|
18 | 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
19 | 19 | // SOFTWARE. |
20 | 20 | (function initUploader() { |
21 | | - var uploadInProgress = false; |
22 | 21 | var notifyUploadSocketError = false; |
23 | 22 | uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, { |
24 | 23 | 'query': 'token=' + Pterodactyl.server.daemonSecret, |
25 | 24 | }); |
26 | 25 |
|
27 | | - window.onbeforeunload = function () { |
28 | | - if (uploadInProgress) { |
29 | | - return "An upload is in progress. Navigating away will abort this upload, are you sure you want to continue?"; |
30 | | - } |
31 | | - } |
32 | | - |
33 | 26 | uploadSocket.io.on('connect_error', function (err) { |
34 | 27 | if(typeof notifyUploadSocketError !== 'object') { |
35 | 28 | notifyUploadSocketError = $.notify({ |
|
42 | 35 | }); |
43 | 36 |
|
44 | 37 | uploadSocket.on('error', err => { |
45 | | - siofu.destroy(); |
| 38 | + Siofu.destroy(); |
46 | 39 | console.error(err); |
47 | 40 | }); |
48 | 41 |
|
|
53 | 46 | } |
54 | 47 | }); |
55 | 48 |
|
56 | | - var siofu = new SocketIOFileUpload(uploadSocket); |
57 | | - siofu.listenOnDrop(document.getElementById("load_files")); |
| 49 | + window.Siofu = new SocketIOFileUpload(uploadSocket); |
| 50 | + Siofu.listenOnDrop(document.getElementById("load_files")); |
| 51 | + |
| 52 | + if (document.getElementById("files_touch_target")) { |
| 53 | + Siofu.listenOnInput(document.getElementById("files_touch_target")); |
| 54 | + } |
58 | 55 |
|
59 | 56 | window.addEventListener('dragover', function (event) { |
60 | 57 | event.preventDefault(); |
|
83 | 80 | } |
84 | 81 | }); |
85 | 82 |
|
86 | | - siofu.addEventListener('start', function (event) { |
87 | | - uploadInProgress = true; |
| 83 | + Siofu.addEventListener('start', function (event) { |
| 84 | + window.onbeforeunload = function () { |
| 85 | + return 'A file upload in in progress, are you sure you want to continue?'; |
| 86 | + }; |
88 | 87 | event.file.meta.path = $('#headerTableRow').attr('data-currentdir'); |
89 | 88 | event.file.meta.identifier = Math.random().toString(36).slice(2); |
90 | 89 |
|
|
102 | 101 | '); |
103 | 102 | }); |
104 | 103 |
|
105 | | - siofu.addEventListener('progress', function(event) { |
| 104 | + Siofu.addEventListener('progress', function(event) { |
| 105 | + window.onbeforeunload = function () { |
| 106 | + return 'A file upload in in progress, are you sure you want to continue?'; |
| 107 | + }; |
106 | 108 | var percent = event.bytesLoaded / event.file.size * 100; |
107 | 109 | if (percent >= 100) { |
108 | 110 | $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-success').parent().removeClass('active'); |
|
112 | 114 | }); |
113 | 115 |
|
114 | 116 | // Do something when a file is uploaded: |
115 | | - siofu.addEventListener('complete', function(event) { |
116 | | - uploadInProgress = false; |
| 117 | + Siofu.addEventListener('complete', function(event) { |
| 118 | + window.onbeforeunload = function () {}; |
117 | 119 | if (!event.success) { |
118 | 120 | $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger'); |
119 | 121 | $.notify({ |
|
125 | 127 | } |
126 | 128 | }); |
127 | 129 |
|
128 | | - siofu.addEventListener('error', function(event) { |
129 | | - uploadInProgress = false; |
| 130 | + Siofu.addEventListener('error', function(event) { |
| 131 | + window.onbeforeunload = function () {}; |
130 | 132 | console.error(event); |
131 | 133 | $('.prog-bar-' + event.file.meta.identifier).css('width', '100%').removeClass('progress-bar-info').addClass('progress-bar-danger'); |
132 | 134 | $.notify({ |
|
0 commit comments