Skip to content

Commit

Permalink
Merge pull request #173 from boughtonp/develop
Browse files Browse the repository at this point in the history
Fixes for #135 and #172, workaround for #169.
  • Loading branch information
weixiyen authored Feb 9, 2017
2 parents 872e1c1 + 7e536a1 commit 972740b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,3 +137,4 @@ Contributions

* [Reactor5](http://github.com/Reactor5/) (Brian Hicks)
* [jpb0104](http://github.com/jpb0104)
* [boughtonp](https://github.com/boughtonp) (Peter Boughton)
32 changes: 23 additions & 9 deletions jquery.filedrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

var default_opts = {
fallback_id: '',
fallback_dropzoneClick : true,
url: '',
refresh: 1000,
paramname: 'userfile',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 972740b

Please sign in to comment.