Skip to content

Commit 73e8c6b

Browse files
committed
Use promise.pipe for jQuery version before v1.8.
jQuery versions before 1.8 require promise.pipe if the return value is used, as promise.then in older versions has a different behavior, see: - https://blog.jquery.com/2012/08/09/jquery-1-8-released/ - https://bugs.jquery.com/ticket/11010 - blueimp#3435 Resolves blueimp#3536, Resolves blueimp#3538
1 parent 6b7081c commit 73e8c6b

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

js/jquery.fileupload-process.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
settings
7979
);
8080
};
81-
chain = chain.then(func, settings.always && func);
81+
chain = chain[that._promisePipe](func, settings.always && func);
8282
});
8383
chain
8484
.done(function () {
@@ -146,14 +146,15 @@
146146
};
147147
opts.index = index;
148148
that._processing += 1;
149-
that._processingQueue = that._processingQueue
150-
.then(func, func)
151-
.always(function () {
152-
that._processing -= 1;
153-
if (that._processing === 0) {
154-
that._trigger('processstop');
155-
}
156-
});
149+
that._processingQueue = that._processingQueue[that._promisePipe](
150+
func,
151+
func
152+
).always(function () {
153+
that._processing -= 1;
154+
if (that._processing === 0) {
155+
that._trigger('processstop');
156+
}
157+
});
157158
});
158159
}
159160
return this._processingQueue;

js/jquery.fileupload.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@
301301
timeout: 0
302302
},
303303

304+
// jQuery versions before 1.8 require promise.pipe if the return value is
305+
// used, as promise.then in older versions has a different behavior, see:
306+
// https://blog.jquery.com/2012/08/09/jquery-1-8-released/
307+
// https://bugs.jquery.com/ticket/11010
308+
// https://github.com/blueimp/jQuery-File-Upload/pull/3435
309+
_promisePipe: (function () {
310+
var parts = $.fn.jquery.split('.');
311+
return Number(parts[0]) > 1 || Number(parts[1]) > 7 ? 'then' : 'pipe';
312+
})(),
313+
304314
// A list of options that require reinitializing event listeners and/or
305315
// special initialization code:
306316
_specialOptions: [
@@ -732,16 +742,15 @@
732742
};
733743
data.process = function (resolveFunc, rejectFunc) {
734744
if (resolveFunc || rejectFunc) {
735-
data._processQueue = this._processQueue = (
736-
this._processQueue || getPromise([this])
737-
)
738-
.then(function () {
745+
data._processQueue = this._processQueue = (this._processQueue ||
746+
getPromise([this]))
747+
[that._promisePipe](function () {
739748
if (data.errorThrown) {
740749
return $.Deferred().rejectWith(that, [data]).promise();
741750
}
742751
return getPromise(arguments);
743752
})
744-
.then(resolveFunc, rejectFunc);
753+
[that._promisePipe](resolveFunc, rejectFunc);
745754
}
746755
return this._processQueue || getPromise([this]);
747756
};
@@ -1052,9 +1061,9 @@
10521061
if (this.options.limitConcurrentUploads > 1) {
10531062
slot = $.Deferred();
10541063
this._slots.push(slot);
1055-
pipe = slot.then(send);
1064+
pipe = slot[that._promisePipe](send);
10561065
} else {
1057-
this._sequence = this._sequence.then(send, send);
1066+
this._sequence = this._sequence[that._promisePipe](send, send);
10581067
pipe = this._sequence;
10591068
}
10601069
// Return the piped Promise object, enhanced with an abort method,
@@ -1254,7 +1263,7 @@
12541263
return that._handleFileTreeEntry(entry, path);
12551264
})
12561265
)
1257-
.then(function () {
1266+
[this._promisePipe](function () {
12581267
return Array.prototype.concat.apply([], arguments);
12591268
});
12601269
},
@@ -1322,7 +1331,7 @@
13221331
}
13231332
return $.when
13241333
.apply($, $.map(fileInput, this._getSingleFileInputFiles))
1325-
.then(function () {
1334+
[this._promisePipe](function () {
13261335
return Array.prototype.concat.apply([], arguments);
13271336
});
13281337
},

0 commit comments

Comments
 (0)