Refactored some code and updated read me
This commit is contained in:
parent
b049eede1f
commit
dfef13aa7b
@ -19,6 +19,8 @@ model.save([file attribute], [file object], [options]);
|
||||
|
||||
In terms of how to use these methods, they have not changed. The only difference is that it has the capability to take a File object grabbed from the DOM (i.e. `<input type="file" />`).
|
||||
|
||||
File, Blob, and FileList are all valid in the model. Once set it will be uploaded when ready.
|
||||
|
||||
As the file is being uploaded, a trigger `progress` fires as the browser sends chunks of data. The `progress` trigger sends a progress status in percents.
|
||||
|
||||
If you want to force not using FormData, add the option `{ formData: false }` and the whether or not you have a file object in the model, it'll try to send it as part of the JSON object. Opposite is true (for whichever circumstance) is that if you set `{ formData: true }`, it will force the usage of FormData. Not setting it will leave it automatic and it'll try to detect if there is the file in the model.
|
||||
@ -149,3 +151,6 @@ requirejs.config({
|
||||
- Fixed all the wonkiness from 0.3 with the attributes and save. Reverted a lot of code and refactored
|
||||
- Added "blob" support as a FileObj entity
|
||||
- Added some Jasmine tests
|
||||
|
||||
## Version 0.5
|
||||
- Added FileList support
|
||||
|
@ -1,19 +1,20 @@
|
||||
// Backbone.Model File Upload v0.4
|
||||
// Backbone.Model File Upload v0.5
|
||||
// by Joe Vu - joe.vu@homeslicesolutions.com
|
||||
// For all details and documentation:
|
||||
// https://github.com/homeslicesolutions/backbone-model-file-upload
|
||||
// Contributors:
|
||||
// lutherism - Alex Jansen - alex.openrobot.net
|
||||
// bildja - Dima Bildin - github.com/bildja
|
||||
// Minjung - Alejandro - github.com/Minjung
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['underscore', 'backbone'], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(_, Backbone);
|
||||
}
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['underscore', 'backbone'], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(_, Backbone);
|
||||
}
|
||||
}(this, function(_, Backbone){
|
||||
|
||||
// Clone the original Backbone.Model.prototype
|
||||
@ -87,12 +88,9 @@
|
||||
options.contentType = false;
|
||||
|
||||
// Apply custom XHR for processing status & listen to "progress"
|
||||
var that = this;
|
||||
options.xhr = function() {
|
||||
var xhr = $.ajaxSettings.xhr();
|
||||
xhr.upload.addEventListener('progress', function(){
|
||||
that._progressHandler.apply(that, arguments);
|
||||
}, false);
|
||||
xhr.upload.addEventListener('progress', this._progressHandler.bind(this), false);
|
||||
return xhr;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user