Skip to content

Commit

Permalink
Fix: update jquery fileupload
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Aug 6, 2012
1 parent 99e234d commit afeabd4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 17 deletions.
@@ -1,5 +1,5 @@
/*
* jQuery File Upload User Interface Plugin 6.9.1
* jQuery File Upload User Interface Plugin 6.9.4
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -89,7 +89,7 @@
files = data.files;
$(this).fileupload('process', data).done(function () {
that._adjustMaxNumberOfFiles(-files.length);
data.isAdjusted = true;
data.maxNumberOfFilesAdjusted = true;
data.files.valid = data.isValidated = that._validate(files);
data.context = that._renderUpload(files).data('data', data);
options.filesContainer[
Expand All @@ -112,8 +112,9 @@
send: function (e, data) {
var that = $(this).data('fileupload');
if (!data.isValidated) {
if (!data.isAdjusted) {
if (!data.maxNumberOfFilesAdjusted) {
that._adjustMaxNumberOfFiles(-data.files.length);
data.maxNumberOfFilesAdjusted = true;
}
if (!that._validate(data.files)) {
return false;
Expand Down Expand Up @@ -151,7 +152,6 @@
function () {
var node = $(this);
template = that._renderDownload([file])
.css('height', node.height())
.replaceAll(node);
that._forceReflow(template);
that._transition(template).done(
Expand All @@ -164,6 +164,17 @@
);
});
} else {
if ($.isArray(data.result)) {
$.each(data.result, function (index, file) {
if (data.maxNumberOfFilesAdjusted && file.error) {
that._adjustMaxNumberOfFiles(1);
} else if (!data.maxNumberOfFilesAdjusted &&
!file.error) {
that._adjustMaxNumberOfFiles(-1);
}
});
data.maxNumberOfFilesAdjusted = true;
}
template = that._renderDownload(data.result)
.appendTo(that.options.filesContainer);
that._forceReflow(template);
Expand All @@ -179,7 +190,9 @@
fail: function (e, data) {
var that = $(this).data('fileupload'),
template;
that._adjustMaxNumberOfFiles(data.files.length);
if (data.maxNumberOfFilesAdjusted) {
that._adjustMaxNumberOfFiles(data.files.length);
}
if (data.context) {
data.context.each(function (index) {
if (data.errorThrown !== 'abort') {
Expand Down Expand Up @@ -210,7 +223,6 @@
}
});
} else if (data.errorThrown !== 'abort') {
that._adjustMaxNumberOfFiles(-data.files.length);
data.context = that._renderUpload(data.files)
.appendTo(that.options.filesContainer)
.data('data', data);
Expand Down Expand Up @@ -664,10 +676,32 @@
}
},

_stringToRegExp: function (str) {
var parts = str.split('/'),
modifiers = parts.pop();
parts.shift();
return new RegExp(parts.join('/'), modifiers);
},

_initRegExpOptions: function () {
var options = this.options;
if ($.type(options.acceptFileTypes) === 'string') {
options.acceptFileTypes = this._stringToRegExp(
options.acceptFileTypes
);
}
if ($.type(options.previewSourceFileTypes) === 'string') {
options.previewSourceFileTypes = this._stringToRegExp(
options.previewSourceFileTypes
);
}
},

_initSpecialOptions: function () {
parentWidget.prototype._initSpecialOptions.call(this);
this._initFilesContainer();
this._initTemplates();
this._initRegExpOptions();
},

_create: function () {
Expand Down
45 changes: 34 additions & 11 deletions htdocs/includes/jquery/plugins/fileupload/js/jquery.fileupload.js
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin 5.11.2
* jQuery File Upload Plugin 5.13
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -530,6 +530,10 @@
ub + i * mcs,
ub + (i + 1) * mcs
);
// Expose the chunk index:
o.chunkIndex = i;
// Expose the number of chunks:
o.chunksNumber = n;
// Store the current chunk size, as the blob itself
// will be dereferenced after data processing:
o.chunkSize = o.blob.size;
Expand Down Expand Up @@ -776,19 +780,30 @@
}
},

_getFileInputFiles: function (fileInput) {
fileInput = $(fileInput);
var files = $.each($.makeArray(fileInput.prop('files')), this._normalizeFile),
value;
if (!files.length) {
value = fileInput.prop('value');
if (!value) {
return [];
}
// If the files property is not available, the browser does not
// support the File API and we add a pseudo File object with
// the input value as name with path information removed:
files = [{name: value.replace(/^.*\\/, '')}];
}
return files;
},

_onChange: function (e) {
var that = e.data.fileupload,
data = {
files: $.each($.makeArray(e.target.files), that._normalizeFile),
fileInput: $(e.target),
form: $(e.target.form)
};
if (!data.files.length) {
// If the files property is not available, the browser does not
// support the File API and we add a pseudo File object with
// the input value as name with path information removed:
data.files = [{name: e.target.value.replace(/^.*\\/, '')}];
}
data.files = that._getFileInputFiles(data.fileInput);
if (that.options.replaceFileInput) {
that._replaceFileInput(data.fileInput);
}
Expand Down Expand Up @@ -838,7 +853,7 @@
return false;
}
if (dataTransfer) {
dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy';
dataTransfer.dropEffect = 'copy';
}
e.preventDefault();
},
Expand Down Expand Up @@ -925,7 +940,11 @@
if (!data || this.options.disabled) {
return;
}
data.files = $.each($.makeArray(data.files), this._normalizeFile);
if (data.fileInput && !data.files) {
data.files = this._getFileInputFiles(data.fileInput);
} else {
data.files = $.each($.makeArray(data.files), this._normalizeFile);
}
this._onAdd(null, data);
},

Expand All @@ -936,7 +955,11 @@
// The method returns a Promise object for the file upload call.
send: function (data) {
if (data && !this.options.disabled) {
data.files = $.each($.makeArray(data.files), this._normalizeFile);
if (data.fileInput && !data.files) {
data.files = this._getFileInputFiles(data.fileInput);
} else {
data.files = $.each($.makeArray(data.files), this._normalizeFile);
}
if (data.files.length) {
return this._onSend(null, data);
}
Expand Down

0 comments on commit afeabd4

Please sign in to comment.