From 3aec97ee5ddcc5b1fe7a9285f05c769a47a78523 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Tue, 6 Mar 2018 20:52:51 -0500 Subject: [PATCH] Avoid jquery selector error when fallback_id is unset --- jquery.filedrop.js | 53 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/jquery.filedrop.js b/jquery.filedrop.js index 1c05ec9..7a8a279 100644 --- a/jquery.filedrop.js +++ b/jquery.filedrop.js @@ -71,38 +71,41 @@ files_count = 0, files; - if ( opts.fallback_dropzoneClick === true ) + if ( opts.fallback_id ) { - $('#' + 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); - - if ( opts.fallback_dropzoneClick === true ) - { - if ( this.find('#' + opts.fallback_id).length > 0 ) + if ( opts.fallback_dropzoneClick === true ) { - throw "Fallback element ["+opts.fallback_id+"] cannot be inside dropzone, unless option fallback_dropzoneClick is false"; + $('#' + opts.fallback_id).css({ + display: 'none', + width: 0, + height: 0 + }); } - else + + 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) { + opts.drop(e); + files = e.target.files; + files_count = files.length; + upload(); + }); } - $('#' + opts.fallback_id).change(function(e) { - opts.drop(e); - files = e.target.files; - files_count = files.length; - upload(); - }); + 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); function drop(e) { if( opts.drop.call(this, e) === false ) return false;