|
1 | 1 | /*
|
2 |
| - * jQuery File Upload User Interface Plugin 8.2.1 |
| 2 | + * jQuery File Upload User Interface Plugin 9.5.2 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
9 | 9 | * http://www.opensource.org/licenses/MIT
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/*jslint nomen: true, unparam: true, regexp: true */ |
13 |
| -/*global define, window, URL, webkitURL, FileReader */ |
| 12 | +/* jshint nomen:false */ |
| 13 | +/* global define, window */ |
14 | 14 |
|
15 | 15 | (function (factory) {
|
16 | 16 | 'use strict';
|
|
19 | 19 | define([
|
20 | 20 | 'jquery',
|
21 | 21 | 'tmpl',
|
22 |
| - './jquery.fileupload-resize', |
| 22 | + './jquery.fileupload-image', |
| 23 | + './jquery.fileupload-audio', |
| 24 | + './jquery.fileupload-video', |
23 | 25 | './jquery.fileupload-validate'
|
24 | 26 | ], factory);
|
25 | 27 | } else {
|
|
29 | 31 | window.tmpl
|
30 | 32 | );
|
31 | 33 | }
|
32 |
| -}(function ($, tmpl, loadImage) { |
| 34 | +}(function ($, tmpl) { |
33 | 35 | 'use strict';
|
34 | 36 |
|
35 | 37 | $.blueimp.fileupload.prototype._specialOptions.push(
|
|
64 | 66 | // Function returning the current number of files,
|
65 | 67 | // used by the maxNumberOfFiles validation:
|
66 | 68 | getNumberOfFiles: function () {
|
67 |
| - return this.filesContainer.children().length; |
| 69 | + return this.filesContainer.children() |
| 70 | + .not('.processing').length; |
68 | 71 | },
|
69 | 72 |
|
70 | 73 | // Callback to retrieve the list of files from the server response:
|
|
79 | 82 | // widget (via file input selection, drag & drop or add API call).
|
80 | 83 | // See the basic file upload widget for more information:
|
81 | 84 | add: function (e, data) {
|
| 85 | + if (e.isDefaultPrevented()) { |
| 86 | + return false; |
| 87 | + } |
82 | 88 | var $this = $(this),
|
83 | 89 | that = $this.data('blueimp-fileupload') ||
|
84 | 90 | $this.data('fileupload'),
|
85 |
| - options = that.options, |
86 |
| - files = data.files; |
| 91 | + options = that.options; |
| 92 | + data.context = that._renderUpload(data.files) |
| 93 | + .data('data', data) |
| 94 | + .addClass('processing'); |
| 95 | + options.filesContainer[ |
| 96 | + options.prependFiles ? 'prepend' : 'append' |
| 97 | + ](data.context); |
| 98 | + that._forceReflow(data.context); |
| 99 | + that._transition(data.context); |
87 | 100 | data.process(function () {
|
88 | 101 | return $this.fileupload('process', data);
|
89 | 102 | }).always(function () {
|
90 |
| - data.context = that._renderUpload(files).data('data', data); |
| 103 | + data.context.each(function (index) { |
| 104 | + $(this).find('.size').text( |
| 105 | + that._formatFileSize(data.files[index].size) |
| 106 | + ); |
| 107 | + }).removeClass('processing'); |
91 | 108 | that._renderPreviews(data);
|
92 |
| - options.filesContainer[ |
93 |
| - options.prependFiles ? 'prepend' : 'append' |
94 |
| - ](data.context); |
95 |
| - that._forceReflow(data.context); |
96 |
| - that._transition(data.context).done( |
97 |
| - function () { |
98 |
| - if ((that._trigger('added', e, data) !== false) && |
99 |
| - (options.autoUpload || data.autoUpload) && |
100 |
| - data.autoUpload !== false && !data.files.error) { |
101 |
| - data.submit(); |
| 109 | + }).done(function () { |
| 110 | + data.context.find('.start').prop('disabled', false); |
| 111 | + if ((that._trigger('added', e, data) !== false) && |
| 112 | + (options.autoUpload || data.autoUpload) && |
| 113 | + data.autoUpload !== false) { |
| 114 | + data.submit(); |
| 115 | + } |
| 116 | + }).fail(function () { |
| 117 | + if (data.files.error) { |
| 118 | + data.context.each(function (index) { |
| 119 | + var error = data.files[index].error; |
| 120 | + if (error) { |
| 121 | + $(this).find('.error').text(error); |
102 | 122 | }
|
103 |
| - } |
104 |
| - ); |
| 123 | + }); |
| 124 | + } |
105 | 125 | });
|
106 | 126 | },
|
107 | 127 | // Callback for the start of each file upload request:
|
108 | 128 | send: function (e, data) {
|
| 129 | + if (e.isDefaultPrevented()) { |
| 130 | + return false; |
| 131 | + } |
109 | 132 | var that = $(this).data('blueimp-fileupload') ||
|
110 | 133 | $(this).data('fileupload');
|
111 | 134 | if (data.context && data.dataType &&
|
|
118 | 141 | !$.support.transition && 'progress-animated'
|
119 | 142 | )
|
120 | 143 | .attr('aria-valuenow', 100)
|
121 |
| - .find('.bar').css( |
| 144 | + .children().first().css( |
122 | 145 | 'width',
|
123 | 146 | '100%'
|
124 | 147 | );
|
|
127 | 150 | },
|
128 | 151 | // Callback for successful uploads:
|
129 | 152 | done: function (e, data) {
|
| 153 | + if (e.isDefaultPrevented()) { |
| 154 | + return false; |
| 155 | + } |
130 | 156 | var that = $(this).data('blueimp-fileupload') ||
|
131 | 157 | $(this).data('fileupload'),
|
132 | 158 | getFilesFromResponse = data.getFilesFromResponse ||
|
|
137 | 163 | if (data.context) {
|
138 | 164 | data.context.each(function (index) {
|
139 | 165 | var file = files[index] ||
|
140 |
| - {error: 'Empty file upload result'}, |
141 |
| - deferred = that._addFinishedDeferreds(); |
| 166 | + {error: 'Empty file upload result'}; |
| 167 | + deferred = that._addFinishedDeferreds(); |
142 | 168 | that._transition($(this)).done(
|
143 | 169 | function () {
|
144 | 170 | var node = $(this);
|
|
157 | 183 | );
|
158 | 184 | });
|
159 | 185 | } else {
|
160 |
| - template = that._renderDownload(files) |
161 |
| - .appendTo(that.options.filesContainer); |
| 186 | + template = that._renderDownload(files)[ |
| 187 | + that.options.prependFiles ? 'prependTo' : 'appendTo' |
| 188 | + ](that.options.filesContainer); |
162 | 189 | that._forceReflow(template);
|
163 | 190 | deferred = that._addFinishedDeferreds();
|
164 | 191 | that._transition(template).done(
|
|
173 | 200 | },
|
174 | 201 | // Callback for failed (abort or error) uploads:
|
175 | 202 | fail: function (e, data) {
|
| 203 | + if (e.isDefaultPrevented()) { |
| 204 | + return false; |
| 205 | + } |
176 | 206 | var that = $(this).data('blueimp-fileupload') ||
|
177 | 207 | $(this).data('fileupload'),
|
178 | 208 | template,
|
|
213 | 243 | }
|
214 | 244 | });
|
215 | 245 | } else if (data.errorThrown !== 'abort') {
|
216 |
| - data.context = that._renderUpload(data.files) |
217 |
| - .appendTo(that.options.filesContainer) |
| 246 | + data.context = that._renderUpload(data.files)[ |
| 247 | + that.options.prependFiles ? 'prependTo' : 'appendTo' |
| 248 | + ](that.options.filesContainer) |
218 | 249 | .data('data', data);
|
219 | 250 | that._forceReflow(data.context);
|
220 | 251 | deferred = that._addFinishedDeferreds();
|
|
234 | 265 | },
|
235 | 266 | // Callback for upload progress events:
|
236 | 267 | progress: function (e, data) {
|
| 268 | + if (e.isDefaultPrevented()) { |
| 269 | + return false; |
| 270 | + } |
| 271 | + var progress = Math.floor(data.loaded / data.total * 100); |
237 | 272 | if (data.context) {
|
238 |
| - var progress = Math.floor(data.loaded / data.total * 100); |
239 |
| - data.context.find('.progress') |
240 |
| - .attr('aria-valuenow', progress) |
241 |
| - .find('.bar').css( |
242 |
| - 'width', |
243 |
| - progress + '%' |
244 |
| - ); |
| 273 | + data.context.each(function () { |
| 274 | + $(this).find('.progress') |
| 275 | + .attr('aria-valuenow', progress) |
| 276 | + .children().first().css( |
| 277 | + 'width', |
| 278 | + progress + '%' |
| 279 | + ); |
| 280 | + }); |
245 | 281 | }
|
246 | 282 | },
|
247 | 283 | // Callback for global upload progress events:
|
248 | 284 | progressall: function (e, data) {
|
| 285 | + if (e.isDefaultPrevented()) { |
| 286 | + return false; |
| 287 | + } |
249 | 288 | var $this = $(this),
|
250 | 289 | progress = Math.floor(data.loaded / data.total * 100),
|
251 | 290 | globalProgressNode = $this.find('.fileupload-progress'),
|
|
260 | 299 | globalProgressNode
|
261 | 300 | .find('.progress')
|
262 | 301 | .attr('aria-valuenow', progress)
|
263 |
| - .find('.bar').css( |
| 302 | + .children().first().css( |
264 | 303 | 'width',
|
265 | 304 | progress + '%'
|
266 | 305 | );
|
267 | 306 | },
|
268 | 307 | // Callback for uploads start, equivalent to the global ajaxStart event:
|
269 | 308 | start: function (e) {
|
| 309 | + if (e.isDefaultPrevented()) { |
| 310 | + return false; |
| 311 | + } |
270 | 312 | var that = $(this).data('blueimp-fileupload') ||
|
271 | 313 | $(this).data('fileupload');
|
272 | 314 | that._resetFinishedDeferreds();
|
|
278 | 320 | },
|
279 | 321 | // Callback for uploads stop, equivalent to the global ajaxStop event:
|
280 | 322 | stop: function (e) {
|
| 323 | + if (e.isDefaultPrevented()) { |
| 324 | + return false; |
| 325 | + } |
281 | 326 | var that = $(this).data('blueimp-fileupload') ||
|
282 | 327 | $(this).data('fileupload'),
|
283 | 328 | deferred = that._addFinishedDeferreds();
|
|
289 | 334 | function () {
|
290 | 335 | $(this).find('.progress')
|
291 | 336 | .attr('aria-valuenow', '0')
|
292 |
| - .find('.bar').css('width', '0%'); |
| 337 | + .children().first().css('width', '0%'); |
293 | 338 | $(this).find('.progress-extended').html(' ');
|
294 | 339 | deferred.resolve();
|
295 | 340 | }
|
296 | 341 | );
|
297 | 342 | },
|
298 |
| - processstart: function () { |
| 343 | + processstart: function (e) { |
| 344 | + if (e.isDefaultPrevented()) { |
| 345 | + return false; |
| 346 | + } |
299 | 347 | $(this).addClass('fileupload-processing');
|
300 | 348 | },
|
301 |
| - processstop: function () { |
| 349 | + processstop: function (e) { |
| 350 | + if (e.isDefaultPrevented()) { |
| 351 | + return false; |
| 352 | + } |
302 | 353 | $(this).removeClass('fileupload-processing');
|
303 | 354 | },
|
304 | 355 | // Callback for file deletion:
|
305 | 356 | destroy: function (e, data) {
|
| 357 | + if (e.isDefaultPrevented()) { |
| 358 | + return false; |
| 359 | + } |
306 | 360 | var that = $(this).data('blueimp-fileupload') ||
|
307 |
| - $(this).data('fileupload'); |
308 |
| - if (data.url) { |
309 |
| - $.ajax(data).done(function () { |
| 361 | + $(this).data('fileupload'), |
| 362 | + removeNode = function () { |
310 | 363 | that._transition(data.context).done(
|
311 | 364 | function () {
|
312 | 365 | $(this).remove();
|
313 | 366 | that._trigger('destroyed', e, data);
|
314 | 367 | }
|
315 | 368 | );
|
| 369 | + }; |
| 370 | + if (data.url) { |
| 371 | + data.dataType = data.dataType || that.options.dataType; |
| 372 | + $.ajax(data).done(removeNode).fail(function () { |
| 373 | + that._trigger('destroyfailed', e, data); |
316 | 374 | });
|
| 375 | + } else { |
| 376 | + removeNode(); |
317 | 377 | }
|
318 | 378 | }
|
319 | 379 | },
|
|
446 | 506 | var button = $(e.currentTarget),
|
447 | 507 | template = button.closest('.template-upload'),
|
448 | 508 | data = template.data('data');
|
449 |
| - if (data && data.submit && !data.jqXHR && data.submit()) { |
450 |
| - button.prop('disabled', true); |
| 509 | + button.prop('disabled', true); |
| 510 | + if (data && data.submit) { |
| 511 | + data.submit(); |
451 | 512 | }
|
452 | 513 | },
|
453 | 514 |
|
454 | 515 | _cancelHandler: function (e) {
|
455 | 516 | e.preventDefault();
|
456 |
| - var template = $(e.currentTarget).closest('.template-upload'), |
| 517 | + var template = $(e.currentTarget) |
| 518 | + .closest('.template-upload,.template-download'), |
457 | 519 | data = template.data('data') || {};
|
458 |
| - if (!data.jqXHR) { |
| 520 | + data.context = data.context || template; |
| 521 | + if (data.abort) { |
| 522 | + data.abort(); |
| 523 | + } else { |
459 | 524 | data.errorThrown = 'abort';
|
460 | 525 | this._trigger('fail', e, data);
|
461 |
| - } else { |
462 |
| - data.jqXHR.abort(); |
463 | 526 | }
|
464 | 527 | },
|
465 | 528 |
|
|
606 | 669 | _create: function () {
|
607 | 670 | this._super();
|
608 | 671 | this._resetFinishedDeferreds();
|
| 672 | + if (!$.support.fileInput) { |
| 673 | + this._disableFileInputButton(); |
| 674 | + } |
609 | 675 | },
|
610 | 676 |
|
611 | 677 | enable: function () {
|
|
0 commit comments