Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload User Interface Plugin 6.9.3
* 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 @@ -163,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 @@ -178,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 @@ -209,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
182 changes: 141 additions & 41 deletions vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin 5.13
* jQuery File Upload Plugin 5.16.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -447,6 +447,9 @@
if (options.type !== 'POST' && options.type !== 'PUT') {
options.type = 'POST';
}
if (!options.formAcceptCharset) {
options.formAcceptCharset = options.form.attr('accept-charset');
}
},

_getAJAXSettings: function (data) {
Expand Down Expand Up @@ -663,9 +666,15 @@
options.limitConcurrentUploads > that._sending) {
// Start the next queued upload,
// that has not been aborted:
var nextSlot = that._slots.shift();
var nextSlot = that._slots.shift(),
isPending;
while (nextSlot) {
if (!nextSlot.isRejected()) {
// jQuery 1.6 doesn't provide .state(),
// while jQuery 1.8+ removed .isRejected():
isPending = nextSlot.state ?
nextSlot.state() === 'pending' :
!nextSlot.isRejected();
if (isPending) {
nextSlot.resolve();
break;
}
Expand Down Expand Up @@ -693,7 +702,7 @@
var args = [undefined, 'abort', 'abort'];
if (!jqXHR) {
if (slot) {
slot.rejectWith(args);
slot.rejectWith(pipe, args);
}
return send(false, args);
}
Expand Down Expand Up @@ -748,14 +757,6 @@
return result;
},

// File Normalization for Gecko 1.9.1 (Firefox 3.5) support:
_normalizeFile: function (index, file) {
if (file.name === undefined && file.size === undefined) {
file.name = file.fileName;
file.size = file.fileSize;
}
},

_replaceFileInput: function (input) {
var inputClone = input.clone(true);
$('<form></form>').append(inputClone)[0].reset();
Expand All @@ -780,21 +781,90 @@
}
},

_handleFileTreeEntry: function (entry, path) {
var that = this,
dfd = $.Deferred(),
errorHandler = function () {
dfd.reject();
},
dirReader;
path = path || '';
if (entry.isFile) {
entry.file(function (file) {
file.relativePath = path;
dfd.resolve(file);
}, errorHandler);
} else if (entry.isDirectory) {
dirReader = entry.createReader();
dirReader.readEntries(function (entries) {
that._handleFileTreeEntries(
entries,
path + entry.name + '/'
).done(function (files) {
dfd.resolve(files);
}).fail(errorHandler);
}, errorHandler);
} else {
errorHandler();
}
return dfd.promise();
},

_handleFileTreeEntries: function (entries, path) {
var that = this;
return $.when.apply(
$,
$.map(entries, function (entry) {
return that._handleFileTreeEntry(entry, path);
})
).pipe(function () {
return Array.prototype.concat.apply(
[],
arguments
);
});
},

_getDroppedFiles: function (dataTransfer) {
dataTransfer = dataTransfer || {};
var items = dataTransfer.items;
if (items && items.length && (items[0].webkitGetAsEntry ||
items[0].getAsEntry)) {
return this._handleFileTreeEntries(
$.map(items, function (item) {
if (item.webkitGetAsEntry) {
return item.webkitGetAsEntry();
}
return item.getAsEntry();
})
);
}
return $.Deferred().resolve(
$.makeArray(dataTransfer.files)
).promise();
},

_getFileInputFiles: function (fileInput) {
fileInput = $(fileInput);
var files = $.each($.makeArray(fileInput.prop('files')), this._normalizeFile),
var entries = fileInput.prop('webkitEntries') ||
fileInput.prop('entries'),
files,
value;
if (entries) {
return this._handleFileTreeEntries(entries);
}
files = $.makeArray(fileInput.prop('files'));
if (!files.length) {
value = fileInput.prop('value');
if (!value) {
return [];
return $.Deferred().reject([]).promise();
}
// 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;
return $.Deferred().resolve(files).promise();
},

_onChange: function (e) {
Expand All @@ -803,14 +873,15 @@
fileInput: $(e.target),
form: $(e.target.form)
};
data.files = that._getFileInputFiles(data.fileInput);
if (that.options.replaceFileInput) {
that._replaceFileInput(data.fileInput);
}
if (that._trigger('change', e, data) === false ||
that._onAdd(e, data) === false) {
return false;
}
that._getFileInputFiles(data.fileInput).always(function (files) {
data.files = files;
if (that.options.replaceFileInput) {
that._replaceFileInput(data.fileInput);
}
if (that._trigger('change', e, data) !== false) {
that._onAdd(e, data);
}
});
},

_onPaste: function (e) {
Expand All @@ -831,19 +902,16 @@
},

_onDrop: function (e) {
e.preventDefault();
var that = e.data.fileupload,
dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer,
data = {
files: $.each(
$.makeArray(dataTransfer && dataTransfer.files),
that._normalizeFile
)
};
if (that._trigger('drop', e, data) === false ||
that._onAdd(e, data) === false) {
return false;
}
e.preventDefault();
data = {};
that._getDroppedFiles(dataTransfer).always(function (files) {
data.files = files;
if (that._trigger('drop', e, data) !== false) {
that._onAdd(e, data);
}
});
},

_onDragOver: function (e) {
Expand Down Expand Up @@ -937,29 +1005,61 @@
// must have a files property and can contain additional options:
// .fileupload('add', {files: filesList});
add: function (data) {
var that = this;
if (!data || this.options.disabled) {
return;
}
if (data.fileInput && !data.files) {
data.files = this._getFileInputFiles(data.fileInput);
this._getFileInputFiles(data.fileInput).always(function (files) {
data.files = files;
that._onAdd(null, data);
});
} else {
data.files = $.each($.makeArray(data.files), this._normalizeFile);
data.files = $.makeArray(data.files);
this._onAdd(null, data);
}
this._onAdd(null, data);
},

// This method is exposed to the widget API and allows sending files
// using the fileupload API. The data parameter accepts an object which
// must have a files property and can contain additional options:
// must have a files or fileInput property and can contain additional options:
// .fileupload('send', {files: filesList});
// The method returns a Promise object for the file upload call.
send: function (data) {
if (data && !this.options.disabled) {
if (data.fileInput && !data.files) {
data.files = this._getFileInputFiles(data.fileInput);
} else {
data.files = $.each($.makeArray(data.files), this._normalizeFile);
var that = this,
dfd = $.Deferred(),
promise = dfd.promise(),
jqXHR,
aborted;
promise.abort = function () {
aborted = true;
if (jqXHR) {
return jqXHR.abort();
}
dfd.reject(null, 'abort', 'abort');
return promise;
};
this._getFileInputFiles(data.fileInput).always(
function (files) {
if (aborted) {
return;
}
data.files = files;
jqXHR = that._onSend(null, data).then(
function (result, textStatus, jqXHR) {
dfd.resolve(result, textStatus, jqXHR);
},
function (jqXHR, textStatus, errorThrown) {
dfd.reject(jqXHR, textStatus, errorThrown);
}
);
}
);
return this._enhancePromise(promise);
}
data.files = $.makeArray(data.files);
if (data.files.length) {
return this._onSend(null, data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery Iframe Transport Plugin 1.4
* jQuery Iframe Transport Plugin 1.5
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
Expand Down Expand Up @@ -42,6 +42,7 @@
return {
send: function (_, completeCallback) {
form = $('<form style="display:none;"></form>');
form.attr('accept-charset', options.formAcceptCharset);
// javascript:false as initial iframe src
// prevents warning popups on HTTPS in IE6.
// IE versions below IE8 cannot set the name property of
Expand Down
Loading