|
1 | 1 | /* |
2 | | - * jQuery File Upload Plugin 5.24 |
| 2 | + * jQuery File Upload Plugin 5.25 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload |
4 | 4 | * |
5 | 5 | * Copyright 2010, Sebastian Tschan |
|
276 | 276 | loaded = Math.floor( |
277 | 277 | e.loaded / e.total * (data.chunkSize || total) |
278 | 278 | ) + (data.uploadedBytes || 0); |
279 | | - this._loaded += loaded - (data.loaded || data.uploadedBytes || 0); |
280 | | - data.lengthComputable = true; |
| 279 | + this._progress.loaded += loaded - |
| 280 | + (data.loaded || data.uploadedBytes || 0); |
281 | 281 | data.loaded = loaded; |
282 | 282 | data.total = total; |
283 | 283 | data.bitrate = data._bitrateTimer.getBitrate( |
284 | 284 | now, |
285 | 285 | loaded, |
286 | 286 | data.bitrateInterval |
287 | 287 | ); |
| 288 | + this._progress.bitrate = this._bitrateTimer.getBitrate( |
| 289 | + now, |
| 290 | + this._progress.loaded, |
| 291 | + data.bitrateInterval |
| 292 | + ); |
288 | 293 | // Trigger a custom progress event with a total data property set |
289 | 294 | // to the file size(s) of the current upload and a loaded data |
290 | 295 | // property calculated accordingly: |
291 | 296 | this._trigger('progress', e, data); |
292 | 297 | // Trigger a global progress event for all current file uploads, |
293 | 298 | // including ajax calls queued for sequential file uploads: |
294 | | - this._trigger('progressall', e, { |
295 | | - lengthComputable: true, |
296 | | - loaded: this._loaded, |
297 | | - total: this._total, |
298 | | - bitrate: this._bitrateTimer.getBitrate( |
299 | | - now, |
300 | | - this._loaded, |
301 | | - data.bitrateInterval |
302 | | - ) |
303 | | - }); |
| 299 | + this._trigger('progressall', e, this._progress); |
304 | 300 | } |
305 | 301 | }, |
306 | 302 |
|
|
645 | 641 | this._trigger('start'); |
646 | 642 | // Set timer for global bitrate progress calculation: |
647 | 643 | this._bitrateTimer = new this._BitrateTimer(); |
| 644 | + // Reset the global progress values: |
| 645 | + this._progress.loaded = this._progress.total = 0; |
| 646 | + this._progress.bitrate = 0; |
648 | 647 | } |
649 | 648 | this._active += 1; |
650 | 649 | // Initialize the global progress values: |
651 | | - this._loaded += data.uploadedBytes || 0; |
652 | | - this._total += this._getTotal(data.files); |
| 650 | + this._progress.loaded += data.uploadedBytes || 0; |
| 651 | + this._progress.total += this._getTotal(data.files); |
653 | 652 | }, |
654 | 653 |
|
655 | 654 | _onDone: function (result, textStatus, jqXHR, options) { |
|
679 | 678 | if (options.recalculateProgress) { |
680 | 679 | // Remove the failed (error or abort) file upload from |
681 | 680 | // the global progress calculation: |
682 | | - this._loaded -= options.loaded || options.uploadedBytes || 0; |
683 | | - this._total -= options.total || this._getTotal(options.files); |
| 681 | + this._progress.loaded -= options.loaded || |
| 682 | + options.uploadedBytes || 0; |
| 683 | + this._progress.total -= options.total || |
| 684 | + this._getTotal(options.files); |
684 | 685 | } |
685 | 686 | }, |
686 | 687 |
|
|
693 | 694 | // The stop callback is triggered when all uploads have |
694 | 695 | // been completed, equivalent to the global ajaxStop event: |
695 | 696 | this._trigger('stop'); |
696 | | - // Reset the global progress values: |
697 | | - this._loaded = this._total = 0; |
698 | | - this._bitrateTimer = null; |
699 | 697 | } |
700 | 698 | }, |
701 | 699 |
|
|
1093 | 1091 | this._initSpecialOptions(); |
1094 | 1092 | this._slots = []; |
1095 | 1093 | this._sequence = this._getXHRPromise(true); |
1096 | | - this._sending = this._active = this._loaded = this._total = 0; |
| 1094 | + this._sending = this._active = 0; |
| 1095 | + this._progress = { |
| 1096 | + loaded: 0, |
| 1097 | + total: 0, |
| 1098 | + bitrate: 0 |
| 1099 | + }; |
1097 | 1100 | this._initEventHandlers(); |
1098 | 1101 | }, |
1099 | 1102 |
|
| 1103 | + // This method is exposed to the widget API and allows to query |
| 1104 | + // the widget upload progress. |
| 1105 | + // It returns an object with loaded, total and bitrate properties |
| 1106 | + // for the running uploads: |
| 1107 | + progress: function () { |
| 1108 | + return this._progress; |
| 1109 | + }, |
| 1110 | + |
1100 | 1111 | // This method is exposed to the widget API and allows adding files |
1101 | 1112 | // using the fileupload API. The data parameter accepts an object which |
1102 | 1113 | // must have a files property and can contain additional options: |
|
0 commit comments