From dfef13aa7b168fe84ea414ce5a12fb54d2779a4c Mon Sep 17 00:00:00 2001 From: homeslicesolutions Date: Thu, 11 Sep 2014 03:21:24 -0700 Subject: [PATCH] Refactored some code and updated read me --- README.md | 7 ++++++- backbone-model-file-upload.js | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 564596f..66fc391 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ model.save([file attribute], [file object], [options]); #### model.set( [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. ``). +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. ``). + +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. @@ -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 diff --git a/backbone-model-file-upload.js b/backbone-model-file-upload.js index b8b6c0d..2f51835 100644 --- a/backbone-model-file-upload.js +++ b/backbone-model-file-upload.js @@ -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; } }