diff --git a/README.md b/README.md index 255561b..54dc367 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Usage Example ```javascript $('#dropzone').filedrop({ fallback_id: 'upload_button', // an identifier of a standard file input element, becomes the target of "click" events on the dropzone + fallback_dropzoneClick : true, // if true, clicking dropzone triggers fallback file selection and the fallback element is made invisible. url: 'upload.php', // upload handler, handles each file separately, can also be a function taking the file and returning a url paramname: 'userfile', // POST parameter name used on serverside to reference file, can also be a function taking the filename and returning the paramname withCredentials: true, // make a cross-origin request with cookies @@ -136,3 +137,4 @@ Contributions * [Reactor5](http://github.com/Reactor5/) (Brian Hicks) * [jpb0104](http://github.com/jpb0104) +* [boughtonp](https://github.com/boughtonp) (Peter Boughton) diff --git a/jquery.filedrop.js b/jquery.filedrop.js index 719fdf4..1c05ec9 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -29,6 +29,7 @@ var default_opts = { fallback_id: '', + fallback_dropzoneClick : true, url: '', refresh: 1000, paramname: 'userfile', @@ -70,18 +71,31 @@ files_count = 0, files; - $('#' + opts.fallback_id).css({ - display: 'none', - width: 0, - height: 0 - }); + if ( opts.fallback_dropzoneClick === true ) + { + $('#' + opts.fallback_id).css({ + display: 'none', + width: 0, + height: 0 + }); + } this.on('drop', drop).on('dragstart', opts.dragStart).on('dragenter', dragEnter).on('dragover', dragOver).on('dragleave', dragLeave); $(document).on('drop', docDrop).on('dragenter', docEnter).on('dragover', docOver).on('dragleave', docLeave); - this.on('click', function(e){ - $('#' + opts.fallback_id).trigger(e); - }); + if ( opts.fallback_dropzoneClick === true ) + { + if ( this.find('#' + opts.fallback_id).length > 0 ) + { + throw "Fallback element ["+opts.fallback_id+"] cannot be inside dropzone, unless option fallback_dropzoneClick is false"; + } + else + { + this.on('click', function(e){ + $('#' + opts.fallback_id).trigger(e); + }); + } + } $('#' + opts.fallback_id).change(function(e) { opts.drop(e); @@ -387,7 +401,7 @@ // Allow url to be a method if (jQuery.isFunction(opts.url)) { - xhr.open(opts.requestType, opts.url(), true); + xhr.open(opts.requestType, opts.url(upload), true); } else { xhr.open(opts.requestType, opts.url, true); }