Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Use "this" instead of a closure variable as data parameter inside of …
Browse files Browse the repository at this point in the history
…the data.submit() method - Fixes #847.

Store the jqXHR object returned by data.submit() as property of the data object.
  • Loading branch information
blueimp committed Dec 6, 2011
1 parent 92dcc73 commit c99611a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
11 changes: 4 additions & 7 deletions jquery.fileupload-ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload User Interface Plugin 5.1
* jQuery File Upload User Interface Plugin 5.1.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -71,7 +71,7 @@
}).data('data', data);
if ((that.options.autoUpload || data.autoUpload) &&
data.isValidated) {
data.jqXHR = data.submit();
data.submit();
}
},
// Callback for the start of each file upload request:
Expand Down Expand Up @@ -466,11 +466,8 @@
e.preventDefault();
var tmpl = $(this).closest('.template-upload'),
data = tmpl.data('data');
if (data && data.submit && !data.jqXHR) {
data.jqXHR = data.submit();
if (data.jqXHR) {
$(this).fadeOut();
}
if (data && data.submit && !data.jqXHR && data.submit()) {
$(this).fadeOut();
}
},

Expand Down
18 changes: 12 additions & 6 deletions jquery.fileupload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin 5.5.1
* jQuery File Upload Plugin 5.5.2
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -397,15 +397,19 @@
}
if (ub >= fs) {
file.error = 'uploadedBytes';
return this._getXHRPromise(false);
return this._getXHRPromise(
false,
options.context,
[null, 'error', file.error]
);
}
// n is the number of blobs to upload,
// calculated via filesize, uploaded bytes and max chunk size:
n = Math.ceil((fs - ub) / mcs);
// The chunk upload method accepting the chunk number as parameter:
upload = function (i) {
if (!i) {
return that._getXHRPromise(true);
return that._getXHRPromise(true, options.context);
}
// Upload the blobs in sequential order:
return upload(i -= 1).pipe(function () {
Expand Down Expand Up @@ -596,14 +600,16 @@
for (i = 0; i < data.files.length; i += limit) {
fileSet.push(data.files.slice(i, i + limit));
}
}
}
data.originalFiles = data.files;
$.each(fileSet || data.files, function (index, element) {
var files = fileSet ? element : [element],
newData = $.extend({}, data, {files: files});
newData.submit = function () {
return (that._trigger('submit', e, newData) !== false) &&
that._onSend(e, newData);
newData.jqXHR = this.jqXHR =
(that._trigger('submit', e, this) !== false) &&
that._onSend(e, this);
return this.jqXHR;
};
return (result = that._trigger('add', e, newData));
});
Expand Down

0 comments on commit c99611a

Please sign in to comment.