Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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:

  1. 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.
  2. 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)

gesture.diff (4.4 KB) - added by Bryan Forbes 8 years ago.

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by Bryan Forbes

Attachment: gesture.diff added

comment:1 Changed 8 years ago by Bryan Forbes

Summary: dojo/gesture incorrectly sets event.target[CLA][PATCH] dojo/gesture incorrectly sets event.target

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.

comment:2 Changed 8 years ago by evan

Resolution: fixed
Status: newclosed

In [26190]:

Fixes #13482 !strict , by making the correct e.target in the fired gesture event, Bryan, thanks for the patch!

comment:3 Changed 8 years ago by evan

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.

Note: See TracTickets for help on using tickets.