|
1 | 1 | /*
|
2 |
| - * jQuery File Upload Plugin 5.25.1 |
| 2 | + * jQuery File Upload Plugin 5.26 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
261 | 261 | return total;
|
262 | 262 | },
|
263 | 263 |
|
| 264 | + _initProgressObject: function (obj) { |
| 265 | + obj._progress = { |
| 266 | + loaded: 0, |
| 267 | + total: 0, |
| 268 | + bitrate: 0 |
| 269 | + }; |
| 270 | + }, |
| 271 | + |
264 | 272 | _onProgress: function (e, data) {
|
265 | 273 | if (e.lengthComputable) {
|
266 | 274 | var now = +(new Date()),
|
267 |
| - total, |
268 | 275 | loaded;
|
269 | 276 | if (data._time && data.progressInterval &&
|
270 | 277 | (now - data._time < data.progressInterval) &&
|
271 | 278 | e.loaded !== e.total) {
|
272 | 279 | return;
|
273 | 280 | }
|
274 | 281 | data._time = now;
|
275 |
| - total = data.total || this._getTotal(data.files); |
276 | 282 | loaded = Math.floor(
|
277 |
| - e.loaded / e.total * (data.chunkSize || total) |
| 283 | + e.loaded / e.total * (data.chunkSize || data._progress.total) |
278 | 284 | ) + (data.uploadedBytes || 0);
|
279 |
| - this._progress.loaded += loaded - |
280 |
| - (data.loaded || data.uploadedBytes || 0); |
281 |
| - data.loaded = loaded; |
282 |
| - data.total = total; |
283 |
| - data.bitrate = data._bitrateTimer.getBitrate( |
| 285 | + // Add the difference from the previously loaded state |
| 286 | + // to the global loaded counter: |
| 287 | + this._progress.loaded += (loaded - data._progress.loaded); |
| 288 | + this._progress.bitrate = this._bitrateTimer.getBitrate( |
284 | 289 | now,
|
285 |
| - loaded, |
| 290 | + this._progress.loaded, |
286 | 291 | data.bitrateInterval
|
287 | 292 | );
|
288 |
| - this._progress.bitrate = this._bitrateTimer.getBitrate( |
| 293 | + data._progress.loaded = data.loaded = loaded; |
| 294 | + data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( |
289 | 295 | now,
|
290 |
| - this._progress.loaded, |
| 296 | + loaded, |
291 | 297 | data.bitrateInterval
|
292 | 298 | );
|
293 | 299 | // Trigger a custom progress event with a total data property set
|
|
542 | 548 | return that._getDeferredState(this.jqXHR);
|
543 | 549 | }
|
544 | 550 | };
|
| 551 | + data.progress = function () { |
| 552 | + return this._progress; |
| 553 | + }; |
545 | 554 | },
|
546 | 555 |
|
547 | 556 | // Parses the Range header from the server response
|
|
588 | 597 | // The chunk upload method:
|
589 | 598 | upload = function () {
|
590 | 599 | // Clone the options object for each chunk upload:
|
591 |
| - var o = $.extend({}, options); |
| 600 | + var o = $.extend({}, options), |
| 601 | + currentLoaded = o._progress.loaded; |
592 | 602 | o.blob = slice.call(
|
593 | 603 | file,
|
594 | 604 | ub,
|
|
610 | 620 | .done(function (result, textStatus, jqXHR) {
|
611 | 621 | ub = that._getUploadedBytes(jqXHR) ||
|
612 | 622 | (ub + o.chunkSize);
|
613 |
| - // Create a progress event if upload is done and no progress |
614 |
| - // event has been invoked for this chunk, or there has been |
615 |
| - // no progress event with loaded equaling total: |
616 |
| - if (!o.loaded || o.loaded < o.total) { |
| 623 | + // Create a progress event if no final progress event |
| 624 | + // with loaded equaling total has been triggered |
| 625 | + // for this chunk: |
| 626 | + if (o._progress.loaded === currentLoaded) { |
617 | 627 | that._onProgress($.Event('progress', {
|
618 | 628 | lengthComputable: true,
|
619 | 629 | loaded: ub - o.uploadedBytes,
|
|
669 | 679 | this._progress.loaded = this._progress.total = 0;
|
670 | 680 | this._progress.bitrate = 0;
|
671 | 681 | }
|
| 682 | + if (!data._progress) { |
| 683 | + data._progress = {}; |
| 684 | + } |
| 685 | + data._progress.loaded = data.loaded = data.uploadedBytes || 0; |
| 686 | + data._progress.total = data.total = this._getTotal(data.files) || 1; |
| 687 | + data._progress.bitrate = data.bitrate = 0; |
672 | 688 | this._active += 1;
|
673 | 689 | // Initialize the global progress values:
|
674 |
| - this._progress.loaded += data.uploadedBytes || 0; |
675 |
| - this._progress.total += this._getTotal(data.files); |
| 690 | + this._progress.loaded += data.loaded; |
| 691 | + this._progress.total += data.total; |
676 | 692 | },
|
677 | 693 |
|
678 | 694 | _onDone: function (result, textStatus, jqXHR, options) {
|
679 |
| - if (!options.uploadedBytes && (!this._isXHRUpload(options) || |
680 |
| - !options.loaded || options.loaded < options.total)) { |
681 |
| - var total = this._getTotal(options.files) || 1; |
682 |
| - // Create a progress event for each iframe load, |
683 |
| - // or if there has been no progress event with |
684 |
| - // loaded equaling total for XHR uploads: |
| 695 | + var total = options._progress.total; |
| 696 | + if (options._progress.loaded < total) { |
| 697 | + // Create a progress event if no final progress event |
| 698 | + // with loaded equaling total has been triggered: |
685 | 699 | this._onProgress($.Event('progress', {
|
686 | 700 | lengthComputable: true,
|
687 | 701 | loaded: total,
|
|
702 | 716 | if (options.recalculateProgress) {
|
703 | 717 | // Remove the failed (error or abort) file upload from
|
704 | 718 | // the global progress calculation:
|
705 |
| - this._progress.loaded -= options.loaded || |
706 |
| - options.uploadedBytes || 0; |
707 |
| - this._progress.total -= options.total || |
708 |
| - this._getTotal(options.files); |
| 719 | + this._progress.loaded -= options._progress.loaded; |
| 720 | + this._progress.total -= options._progress.total; |
709 | 721 | }
|
710 | 722 | },
|
711 | 723 |
|
|
722 | 734 | },
|
723 | 735 |
|
724 | 736 | _onSend: function (e, data) {
|
| 737 | + if (!data.submit) { |
| 738 | + this._addConvenienceMethods(e, data); |
| 739 | + } |
725 | 740 | var that = this,
|
726 | 741 | jqXHR,
|
727 | 742 | aborted,
|
|
826 | 841 | var newData = $.extend({}, data);
|
827 | 842 | newData.files = fileSet ? element : [element];
|
828 | 843 | newData.paramName = paramNameSet[index];
|
| 844 | + that._initProgressObject(newData); |
829 | 845 | that._addConvenienceMethods(e, newData);
|
830 | 846 | result = that._trigger('add', e, newData);
|
831 | 847 | return result;
|
|
1101 | 1117 | this._slots = [];
|
1102 | 1118 | this._sequence = this._getXHRPromise(true);
|
1103 | 1119 | this._sending = this._active = 0;
|
1104 |
| - this._progress = { |
1105 |
| - loaded: 0, |
1106 |
| - total: 0, |
1107 |
| - bitrate: 0 |
1108 |
| - }; |
| 1120 | + this._initProgressObject(this); |
1109 | 1121 | this._initEventHandlers();
|
1110 | 1122 | },
|
1111 | 1123 |
|
|
0 commit comments