Permalink
Browse files

Fixes #392 - aborting sequential uploads.

JSLint compliance updates.
  • Loading branch information...
blueimp committed Jun 13, 2011
1 parent 6da69a0 commit 7f891216ab3e984a26c6110e8626f77e3c7e6941
Showing with 50 additions and 28 deletions.
  1. +3 −2 example/application.js
  2. +2 −2 jquery.fileupload-ui.js
  3. +23 −14 jquery.fileupload.js
  4. +22 −10 tests/tests.js
View
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin JS Example 5.0.1
+ * jQuery File Upload Plugin JS Example 5.0.2
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -9,10 +9,11 @@
* http://creativecommons.org/licenses/MIT/
*/
-/*jslint nomen: false */
+/*jslint nomen: true */
/*global $ */
$(function () {
+ 'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload();
View
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload User Interface Plugin 5.0.12
+ * jQuery File Upload User Interface Plugin 5.0.13
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -9,7 +9,7 @@
* http://creativecommons.org/licenses/MIT/
*/
-/*jslint nomen: false, unparam: true, regexp: false */
+/*jslint nomen: true, unparam: true, regexp: true */
/*global window, document, URL, webkitURL, FileReader, jQuery */
(function ($) {
View
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin 5.0.1
+ * jQuery File Upload Plugin 5.0.2
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -9,7 +9,7 @@
* http://creativecommons.org/licenses/MIT/
*/
-/*jslint nomen: false, unparam: true, regexp: false */
+/*jslint nomen: true, unparam: true, regexp: true */
/*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */
(function ($) {
@@ -232,7 +232,7 @@
options.data = options.blob;
}
}
- if (options.multipart) {
+ if (options.multipart && typeof FormData !== 'undefined') {
if (options.formData instanceof FormData) {
formData = options.formData;
} else {
@@ -318,14 +318,14 @@
// Creates and returns a Promise object enhanced with
// the jqXHR methods abort, success, error and complete:
- _getXHRPromise: function (resolveOrReject, context) {
+ _getXHRPromise: function (resolveOrReject, context, args) {
var dfd = $.Deferred(),
promise = dfd.promise();
context = context || this.options.context || promise;
if (resolveOrReject === true) {
- dfd.resolveWith(context);
+ dfd.resolveWith(context, args);
} else if (resolveOrReject === false) {
- dfd.rejectWith(context);
+ dfd.rejectWith(context, args);
}
promise.abort = dfd.promise;
return this._enhancePromise(promise);
@@ -452,11 +452,12 @@
}
},
- _onAlways: function (result, textStatus, jqXHR, options) {
+ _onAlways: function (result, textStatus, jqXHR, errorThrown, options) {
this._active -= 1;
options.result = result;
options.textStatus = textStatus;
options.jqXHR = jqXHR;
+ options.errorThrown = errorThrown;
this._trigger('always', null, options);
if (this._active === 0) {
// The stop callback is triggered when all uploads have
@@ -472,17 +473,22 @@
jqXHR,
pipe,
options = that._getAJAXSettings(data),
- send = function () {
- jqXHR = ((that._trigger('send', e, options) !== false && (
- that._chunkedUpload(options) ||
- $.ajax(options)
- )) || that._getXHRPromise(false, options.context)
+ send = function (resolve, args) {
+ jqXHR = jqXHR || (
+ (resolve !== false &&
+ that._trigger('send', e, options) !== false &&
+ (that._chunkedUpload(options) || $.ajax(options))) ||
+ that._getXHRPromise(false, options.context, args)
).done(function (result, textStatus, jqXHR) {
that._onDone(result, textStatus, jqXHR, options);
}).fail(function (jqXHR, textStatus, errorThrown) {
that._onFail(jqXHR, textStatus, errorThrown, options);
- }).always(function (result, textStatus, jqXHR) {
- that._onAlways(result, textStatus, jqXHR, options);
+ }).always(function (a1, a2, a3) {
+ if (!a3 || typeof a3 === 'string') {
+ that._onAlways(undefined, a2, a1, a3, options);
+ } else {
+ that._onAlways(a1, a2, a3, undefined, options);
+ }
});
return jqXHR;
};
@@ -493,6 +499,9 @@
// and jqXHR callbacks mapped to the equivalent Promise methods:
pipe = (this._sequence = this._sequence.pipe(send, send));
pipe.abort = function () {
+ if (!jqXHR) {
+ return send(false, [undefined, 'abort', 'abort']);
+ }
return jqXHR.abort();
};
return this._enhancePromise(pipe);
View
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin Tests 3.0
+ * jQuery File Upload Plugin Tests 3.0.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -9,7 +9,7 @@
* http://creativecommons.org/licenses/MIT/
*/
-/*jslint nomen: false, unparam: true */
+/*jslint nomen: true, unparam: true */
/*global $, QUnit, document, expect, module, test, asyncTest, start, ok, strictEqual, notStrictEqual */
$(function () {
@@ -313,7 +313,6 @@ $(function () {
var param = {files: [{name: 'test'}]},
fu = $('#fileupload').fileupload({
url: '404',
- multipart: false,
fail: function (e, data) {
ok(true, 'Triggers fail callback');
start();
@@ -330,7 +329,6 @@ $(function () {
var param = {files: [{name: 'test'}]},
counter = 0,
fu = $('#fileupload').fileupload({
- multipart: false,
always: function (e, data) {
ok(true, 'Triggers always callback');
if (counter === 1) {
@@ -599,7 +597,7 @@ $(function () {
$('#fileupload').fileupload({
singleFileUploads: true,
add: function (e, data) {
- ok(true, 'Triggers callback number ' + index);
+ ok(true, 'Triggers callback number ' + index.toString());
index += 1;
}
}).fileupload('add', param).fileupload(
@@ -608,26 +606,40 @@ $(function () {
false
).fileupload('add', param);
});
-
+
asyncTest('sequentialUploads', function () {
- expect(3);
+ expect(6);
var param = {files: [
{name: '1'},
{name: '2'},
- {name: '3'}
+ {name: '3'},
+ {name: '4'},
+ {name: '5'},
+ {name: '6'}
]},
+ addIndex = 0,
sendIndex = 0,
loadIndex = 0,
fu = $('#fileupload').fileupload({
sequentialUploads: true,
- multipart: false,
+ add: function (e, data) {
+ addIndex += 1;
+ if (addIndex === 4) {
+ data.submit().abort();
+ } else {
+ data.submit();
+ }
+ },
send: function (e, data) {
sendIndex += 1;
},
- always: function (e, data) {
+ done: function (e, data) {
loadIndex += 1;
strictEqual(sendIndex, loadIndex, 'upload in order');
},
+ fail: function (e, data) {
+ strictEqual(data.errorThrown, 'abort', 'upload aborted');
+ },
stop: function (e) {
start();
}

0 comments on commit 7f89121

Please sign in to comment.