Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add drop zone option, document it and set it to the document as default ... #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Use the javascript in `s3_direct_upload` as a guide.
* `before_add:` Callback function that executes before a file is added to the queue. It is passed file object and expects `true` or `false` to be returned. This could be useful if you would like to validate the filenames of files to be uploaded for example. If true is returned file will be uploaded as normal, false will cancel the upload.
* `progress_bar_target:` The jQuery selector for the element where you want the progress bars to be appended to. Default is the form element.
* `click_submit_target:` The jQuery selector for the element you wish to add a click handler to do the submitting instead of submiting on file open.
* `drop_zone`: The jQuery selector for the element that will be the drop target. By default,
the whole document is the drop zone.

### Example with all options
```coffeescript
Expand All @@ -159,6 +161,7 @@ jQuery ->
before_add: myCallBackFunction # must return true or false if set
progress_bar_target: $('.js-progress-bars')
click_submit_target: $('.submit-target')
drop_zone: $('#drop-zone')
```
### Example with single file upload bar without script template

Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/s3_direct_upload.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $.fn.S3Uploader = (options) ->
progress_bar_target: null
click_submit_target: null
allow_multiple_files: true
drop_zone: $(document)

$.extend settings, options

Expand Down Expand Up @@ -131,6 +132,8 @@ $.fn.S3Uploader = (options) ->
$uploadForm.find("input[name='key']").val(settings.path + key)
data

dropZone: settings.drop_zone

build_content_object = ($uploadForm, file, result) ->
content = {}
if result # Use the S3 response to set the URL to avoid character encodings bugs
Expand Down