Skip to content

Commit 8609fa5

Browse files
committed
Expose the state of the jqXHR object as state() method on the data argument.
1 parent e1e7a1f commit 8609fa5

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

js/jquery.fileupload.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin 5.23
2+
* jQuery File Upload Plugin 5.24
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -485,6 +485,21 @@
485485
return options;
486486
},
487487

488+
// jQuery 1.6 doesn't provide .state(),
489+
// while jQuery 1.8+ removed .isRejected() and .isResolved():
490+
_getDeferredState: function (deferred) {
491+
if (deferred.state) {
492+
return deferred.state();
493+
}
494+
if (deferred.isResolved()) {
495+
return 'resolved';
496+
}
497+
if (deferred.isRejected()) {
498+
return 'rejected';
499+
}
500+
return 'pending';
501+
},
502+
488503
// Maps jqXHR callbacks to the equivalent
489504
// methods of the given Promise object:
490505
_enhancePromise: function (promise) {
@@ -715,15 +730,9 @@
715730
options.limitConcurrentUploads > that._sending) {
716731
// Start the next queued upload,
717732
// that has not been aborted:
718-
var nextSlot = that._slots.shift(),
719-
isPending;
733+
var nextSlot = that._slots.shift();
720734
while (nextSlot) {
721-
// jQuery 1.6 doesn't provide .state(),
722-
// while jQuery 1.8+ removed .isRejected():
723-
isPending = nextSlot.state ?
724-
nextSlot.state() === 'pending' :
725-
!nextSlot.isRejected();
726-
if (isPending) {
735+
if (that._getDeferredState(nextSlot) === 'pending') {
727736
nextSlot.resolve();
728737
break;
729738
}
@@ -806,6 +815,11 @@
806815
return this.jqXHR.abort();
807816
}
808817
};
818+
newData.state = function () {
819+
if (this.jqXHR) {
820+
return that._getDeferredState(this.jqXHR);
821+
}
822+
};
809823
result = that._trigger('add', e, newData);
810824
return result;
811825
});

0 commit comments

Comments
 (0)