From ae09cdf842d6c079ec7f093e2bfd5538401e62c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20C=2E=20Mu=CC=88ller?= Date: Sat, 26 Jul 2014 13:17:07 -0400 Subject: [PATCH] Add drop zone option, document it and set it to the document as default (backwards compatible) --- README.md | 3 +++ app/assets/javascripts/s3_direct_upload.js.coffee | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 7e6d3de..2af62df 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/app/assets/javascripts/s3_direct_upload.js.coffee b/app/assets/javascripts/s3_direct_upload.js.coffee index 8548306..e0746e0 100644 --- a/app/assets/javascripts/s3_direct_upload.js.coffee +++ b/app/assets/javascripts/s3_direct_upload.js.coffee @@ -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 @@ -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