#13482 closed defect (fixed)
[CLA][PATCH] dojo/gesture incorrectly sets event.target
Reported by: | Bryan Forbes | Owned by: | evan |
---|---|---|---|
Priority: | high | Milestone: | 1.7 |
Component: | Events | Version: | 1.7.0b1 |
Keywords: | Cc: | Kris Zyp | |
Blocked By: | Blocking: |
Description
Currently, dojo/gesture sets event.target to the connected to node while bubbling. This is contrary to how the DOM event model works: event.target is the node the event was dispatched on (https://developer.mozilla.org/en/DOM/event.target). Because of this fact, event delegation won't work with dojo/gesture in its current state. Take the following code sample:
<div id="one"> <div id="two"></div> </div> <script> require(["dojo/on", "dojo/dom", "dojo/gesture/tap"], function(on, dom, tap){ on(dom.byId("one"), "click", function(evt){ console.log(evt.target.id); }); on(dom.byId("one"), tap, function(evt){ console.log(evt.target.id); }); }); </script>
If "two" is clicked, you will see "two" output on the console. If "two" is tapped, you will see "one" output on the console. Event delegation relies on the fact that event.target is the node that the event originated from.
There are two courses of action that could be taken:
- Modify "fire" to take an extra argument which would be the originating element. event.target would be set to this element. "_fire" would have to be modified to keep from setting e.target.
- Modify dojo/gesture to use on.emit. Since dojo/on already has a system for firing synthetic events, dojo/gesture should be leveraging on.emit rather than reinventing the wheel. on.emit correctly sets event.target (where needed) or uses element.dispatchEvent.
This is a show stopper since event delegation will not work for gestures at this point.
Attachments (1)
Change History (4)
Changed 10 years ago by
Attachment: | gesture.diff added |
---|
comment:1 Changed 10 years ago by
Summary: | dojo/gesture incorrectly sets event.target → [CLA][PATCH] dojo/gesture incorrectly sets event.target |
---|
comment:3 Changed 9 years ago by
Thanks, Bryan,
Really nice suggestion, I'll have a try. Also will track it with #13675. Due to the possible significant changes, we may not be able to get it in for 1.7, let's discuss once I got a patch for it.
I attached a patch for dojo/gesture to implement setting target correctly, but I'd still like to see it use on.emit. For now, this fixes event delegation.