|
1 | 1 | /*
|
2 |
| - * jQuery File Upload Plugin 5.0.1 |
| 2 | + * jQuery File Upload Plugin 5.0.3 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
9 | 9 | * http://creativecommons.org/licenses/MIT/
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/*jslint nomen: false, unparam: true, regexp: false */ |
| 12 | +/*jslint nomen: true, unparam: true, regexp: true */ |
13 | 13 | /*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */
|
14 | 14 |
|
15 | 15 | (function ($) {
|
|
232 | 232 | options.data = options.blob;
|
233 | 233 | }
|
234 | 234 | }
|
235 |
| - if (options.multipart) { |
| 235 | + if (options.multipart && typeof FormData !== 'undefined') { |
236 | 236 | if (options.formData instanceof FormData) {
|
237 | 237 | formData = options.formData;
|
238 | 238 | } else {
|
|
318 | 318 |
|
319 | 319 | // Creates and returns a Promise object enhanced with
|
320 | 320 | // the jqXHR methods abort, success, error and complete:
|
321 |
| - _getXHRPromise: function (resolveOrReject, context) { |
| 321 | + _getXHRPromise: function (resolveOrReject, context, args) { |
322 | 322 | var dfd = $.Deferred(),
|
323 | 323 | promise = dfd.promise();
|
324 | 324 | context = context || this.options.context || promise;
|
325 | 325 | if (resolveOrReject === true) {
|
326 |
| - dfd.resolveWith(context); |
| 326 | + dfd.resolveWith(context, args); |
327 | 327 | } else if (resolveOrReject === false) {
|
328 |
| - dfd.rejectWith(context); |
| 328 | + dfd.rejectWith(context, args); |
329 | 329 | }
|
330 | 330 | promise.abort = dfd.promise;
|
331 | 331 | return this._enhancePromise(promise);
|
|
452 | 452 | }
|
453 | 453 | },
|
454 | 454 |
|
455 |
| - _onAlways: function (result, textStatus, jqXHR, options) { |
| 455 | + _onAlways: function (result, textStatus, jqXHR, errorThrown, options) { |
456 | 456 | this._active -= 1;
|
457 | 457 | options.result = result;
|
458 | 458 | options.textStatus = textStatus;
|
459 | 459 | options.jqXHR = jqXHR;
|
| 460 | + options.errorThrown = errorThrown; |
460 | 461 | this._trigger('always', null, options);
|
461 | 462 | if (this._active === 0) {
|
462 | 463 | // The stop callback is triggered when all uploads have
|
|
472 | 473 | jqXHR,
|
473 | 474 | pipe,
|
474 | 475 | options = that._getAJAXSettings(data),
|
475 |
| - send = function () { |
476 |
| - jqXHR = ((that._trigger('send', e, options) !== false && ( |
477 |
| - that._chunkedUpload(options) || |
478 |
| - $.ajax(options) |
479 |
| - )) || that._getXHRPromise(false, options.context) |
| 476 | + send = function (resolve, args) { |
| 477 | + jqXHR = jqXHR || ( |
| 478 | + (resolve !== false && |
| 479 | + that._trigger('send', e, options) !== false && |
| 480 | + (that._chunkedUpload(options) || $.ajax(options))) || |
| 481 | + that._getXHRPromise(false, options.context, args) |
480 | 482 | ).done(function (result, textStatus, jqXHR) {
|
481 | 483 | that._onDone(result, textStatus, jqXHR, options);
|
482 | 484 | }).fail(function (jqXHR, textStatus, errorThrown) {
|
483 | 485 | that._onFail(jqXHR, textStatus, errorThrown, options);
|
484 |
| - }).always(function (result, textStatus, jqXHR) { |
485 |
| - that._onAlways(result, textStatus, jqXHR, options); |
| 486 | + }).always(function (a1, a2, a3) { |
| 487 | + if (a3 && a3.done) { |
| 488 | + that._onAlways(a1, a2, a3, undefined, options); |
| 489 | + } else { |
| 490 | + that._onAlways(undefined, a2, a1, a3, options); |
| 491 | + } |
486 | 492 | });
|
487 | 493 | return jqXHR;
|
488 | 494 | };
|
|
493 | 499 | // and jqXHR callbacks mapped to the equivalent Promise methods:
|
494 | 500 | pipe = (this._sequence = this._sequence.pipe(send, send));
|
495 | 501 | pipe.abort = function () {
|
| 502 | + if (!jqXHR) { |
| 503 | + return send(false, [undefined, 'abort', 'abort']); |
| 504 | + } |
496 | 505 | return jqXHR.abort();
|
497 | 506 | };
|
498 | 507 | return this._enhancePromise(pipe);
|
|
0 commit comments