From e0736376b72453daba6fbd31367788a3ff835df2 Mon Sep 17 00:00:00 2001 From: Peter Boughton Date: Mon, 8 Jun 2015 12:40:56 +0100 Subject: [PATCH 1/3] Add optional fallback_dropzoneClick to control whether clicking dropzone triggers fallback. Fixes #172. --- README.md | 2 ++ jquery.filedrop.js | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) 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 3fdd3f1..08c9af7 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -31,6 +31,7 @@ var default_opts = { fallback_id: '', + fallback_dropzoneClick : true, url: '', refresh: 1000, paramname: 'userfile', @@ -72,18 +73,24 @@ 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 ) + { + this.on('click', function(e){ + $('#' + opts.fallback_id).trigger(e); + }); + } $('#' + opts.fallback_id).change(function(e) { opts.drop(e); From 5de4e81cb5561612e1441d62622b9726e347cedc Mon Sep 17 00:00:00 2001 From: Peter Boughton Date: Mon, 8 Jun 2015 15:17:19 +0100 Subject: [PATCH 2/3] Throw error if fallback element inside dropzone and fallback_dropzoneClick true. Workaround for infinite loop issue of #169 --- jquery.filedrop.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jquery.filedrop.js b/jquery.filedrop.js index 08c9af7..a87dd56 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -87,9 +87,16 @@ if ( opts.fallback_dropzoneClick === true ) { - this.on('click', function(e){ - $('#' + opts.fallback_id).trigger(e); - }); + 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) { From 7e536a131aff292231b7f3a77ce19392b2f97263 Mon Sep 17 00:00:00 2001 From: Peter Boughton Date: Mon, 8 Jun 2015 15:19:50 +0100 Subject: [PATCH 3/3] Pass upload object to url callback. Enables referencing upload filename, fixes #135. --- jquery.filedrop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.filedrop.js b/jquery.filedrop.js index a87dd56..76cede8 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -402,7 +402,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); }