Updated file upload array to be more simple. Fixed problem when using older browsers that do not support function.prototype.bind (or phantomJS in this case, for the tests)
This commit is contained in:
parent
bbd293f738
commit
3d9da19009
@ -43,7 +43,8 @@
|
|||||||
save: function(key, val, options) {
|
save: function(key, val, options) {
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
var attrs, attributes = this.attributes;
|
var attrs, attributes = this.attributes,
|
||||||
|
that = this;
|
||||||
|
|
||||||
// Signature parsing - taken directly from original Backbone.Model.save
|
// Signature parsing - taken directly from original Backbone.Model.save
|
||||||
// and it states: 'Handle both "key", value and {key: value} -style arguments.'
|
// and it states: 'Handle both "key", value and {key: value} -style arguments.'
|
||||||
@ -86,12 +87,7 @@
|
|||||||
// Converting Attributes to Form Data
|
// Converting Attributes to Form Data
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
_.each( formAttrs, function( value, key ){
|
_.each( formAttrs, function( value, key ){
|
||||||
if (value instanceof FileList) {
|
if (value instanceof FileList || (key === that.fileAttribute && value instanceof Array)) {
|
||||||
_.each(value, function(file) {
|
|
||||||
formData.append( key, file );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (value instanceof Array && value.length && value[0] instanceof File) {
|
|
||||||
_.each(value, function(file) {
|
_.each(value, function(file) {
|
||||||
formData.append( key, file );
|
formData.append( key, file );
|
||||||
});
|
});
|
||||||
@ -107,11 +103,10 @@
|
|||||||
options.contentType = false;
|
options.contentType = false;
|
||||||
|
|
||||||
// Handle "progress" events
|
// Handle "progress" events
|
||||||
var that = this;
|
|
||||||
if (!options.xhr) {
|
if (!options.xhr) {
|
||||||
options.xhr = function(){
|
options.xhr = function(){
|
||||||
var xhr = Backbone.$.ajaxSettings.xhr();
|
var xhr = Backbone.$.ajaxSettings.xhr();
|
||||||
xhr.upload.addEventListener('progress', that._progressHandler.bind(that), false);
|
xhr.upload.addEventListener('progress', _.bind(that._progressHandler, that), false);
|
||||||
return xhr
|
return xhr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user