Skip to content

Commit 22be539

Browse files
author
javadoug
committed
issue 1112 - emit click event before delegating to hidden file input click
1 parent 2e0c007 commit 22be539

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/dropzone.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Dropzone extends Emitter
123123
"maxfilesexceeded"
124124
"maxfilesreached"
125125
"queuecomplete"
126+
"click"
126127
]
127128

128129

@@ -362,6 +363,7 @@ class Dropzone extends Emitter
362363
dragover: (e) -> @element.classList.add "dz-drag-hover"
363364
dragleave: (e) -> @element.classList.remove "dz-drag-hover"
364365

366+
click: noop
365367
paste: noop
366368

367369
# Called whenever there are no files left in the dropzone anymore, and the
@@ -714,6 +716,7 @@ class Dropzone extends Emitter
714716
"click": (evt) =>
715717
# Only the actual dropzone or the message element should trigger file selection
716718
if (clickableElement != @element) or (evt.target == @element or Dropzone.elementInside evt.target, @element.querySelector ".dz-message")
719+
@emit "click", evt
717720
@hiddenFileInput.click() # Forward the click
718721
return true
719722

test/test.coffee

+10-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,16 @@ describe "Dropzone", ->
475475
dropzone.clickableElements.should.eql [ document.body, clickableElement ]
476476
it "should throw an exception if the element is invalid", ->
477477
expect(-> dropzone = new Dropzone element, clickable: ".some-invalid-clickable").to.throw "Invalid `clickable` option provided. Please provide a CSS selector, a plain HTML element or a list of those."
478-
478+
it "should emit a 'click' event when element is clicked", ->
479+
dropzone = new Dropzone element, clickable: clickableElement
480+
callbackCount = 0
481+
callback = (evt) ->
482+
callbackCount++
483+
dropzone.on "click", callback
484+
event = document.createEvent "HTMLEvents"
485+
event.initEvent "click", true, true
486+
clickableElement.dispatchEvent event
487+
callbackCount.should.eql 1
479488

480489

481490

0 commit comments

Comments
 (0)