Refactored some code and updated read me
This commit is contained in:
parent
b049eede1f
commit
dfef13aa7b
@ -17,7 +17,9 @@ model.save([file attribute], [file object], [options]);
|
|||||||
#### model.set( [file attribute], [file object], [options] )
|
#### model.set( [file attribute], [file object], [options] )
|
||||||
#### model.save( [file attribute], [file object], [options] )
|
#### 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" />`).
|
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.
|
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.
|
||||||
|
|
||||||
@ -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
|
- 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 "blob" support as a FileObj entity
|
||||||
- Added some Jasmine tests
|
- 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
|
// by Joe Vu - joe.vu@homeslicesolutions.com
|
||||||
// For all details and documentation:
|
// For all details and documentation:
|
||||||
// https://github.com/homeslicesolutions/backbone-model-file-upload
|
// https://github.com/homeslicesolutions/backbone-model-file-upload
|
||||||
// Contributors:
|
// Contributors:
|
||||||
// lutherism - Alex Jansen - alex.openrobot.net
|
// lutherism - Alex Jansen - alex.openrobot.net
|
||||||
// bildja - Dima Bildin - github.com/bildja
|
// bildja - Dima Bildin - github.com/bildja
|
||||||
|
// Minjung - Alejandro - github.com/Minjung
|
||||||
|
|
||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
// AMD. Register as an anonymous module.
|
// AMD. Register as an anonymous module.
|
||||||
define(['underscore', 'backbone'], factory);
|
define(['underscore', 'backbone'], factory);
|
||||||
} else {
|
} else {
|
||||||
// Browser globals
|
// Browser globals
|
||||||
factory(_, Backbone);
|
factory(_, Backbone);
|
||||||
}
|
}
|
||||||
}(this, function(_, Backbone){
|
}(this, function(_, Backbone){
|
||||||
|
|
||||||
// Clone the original Backbone.Model.prototype
|
// Clone the original Backbone.Model.prototype
|
||||||
@ -87,12 +88,9 @@
|
|||||||
options.contentType = false;
|
options.contentType = false;
|
||||||
|
|
||||||
// Apply custom XHR for processing status & listen to "progress"
|
// Apply custom XHR for processing status & listen to "progress"
|
||||||
var that = this;
|
|
||||||
options.xhr = function() {
|
options.xhr = function() {
|
||||||
var xhr = $.ajaxSettings.xhr();
|
var xhr = $.ajaxSettings.xhr();
|
||||||
xhr.upload.addEventListener('progress', function(){
|
xhr.upload.addEventListener('progress', this._progressHandler.bind(this), false);
|
||||||
that._progressHandler.apply(that, arguments);
|
|
||||||
}, false);
|
|
||||||
return xhr;
|
return xhr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user