diff --git a/jquery.filedrop.js b/jquery.filedrop.js index 3fdd3f1..344fc0c 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -68,9 +68,7 @@ $.fn.filedrop = function(options) { var opts = $.extend({}, default_opts, options), global_progress = [], - doc_leave_timer, stop_loop = false, - files_count = 0, - files; + doc_leave_timer, stop_loop = false; $('#' + opts.fallback_id).css({ display: 'none', @@ -86,23 +84,41 @@ }); $('#' + opts.fallback_id).change(function(e) { + + if (e.target.files.length == 0) { + return; + } + var files = []; + opts.drop(e); - files = e.target.files; - files_count = files.length; - upload(); + + for(var i=0;i 0) { - process(); + process(files); } }; - var send = function(e) { + var send = function(e,files) { + var files_count = files.length; var fileIndex = (e.srcElement || e.target).index; // Sometimes the index is not attached to the // event object. Find it by size. Hack for sure. if (e.target.index === undefined) { - e.target.index = getIndexBySize(e.total); + e.target.index = getIndexBySize(e.total,files); } var xhr = new XMLHttpRequest(), @@ -460,17 +479,17 @@ // Pass any errors to the error option if (xhr.status < 200 || xhr.status > 299) { - opts.error(xhr.statusText, file, fileIndex, xhr.status); + opts.error(xhr.statusText, file, fileIndex, xhr.status,xhr); } }; }; // Initiate the processing loop - process(); + process(files); } - function getIndexBySize(size) { - for (var i = 0; i < files_count; i++) { + function getIndexBySize(size,files) { + for (var i = 0; i < files.length; i++) { if (files[i].size === size) { return i; }