[Pkg-javascript-commits] [dojo] 71/149: refs #18355, add matchTarget to event forwarded by on()
David Prévot
taffit at moszumanska.debian.org
Sat Feb 27 03:13:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository dojo.
commit 118120722bf6da3ff8a1d9d73eef55c27c6dc428
Author: Benjamin Santalucia <ben at dojotoolkit-fr.org>
Date: Fri Sep 11 08:29:09 2015 -0700
refs #18355, add matchTarget to event forwarded by on()
---
on.js | 2 ++
tests/unit/on.js | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/on.js b/on.js
index c30cf86..c55abac 100644
--- a/on.js
+++ b/on.js
@@ -257,6 +257,8 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff"], fu
var eventTarget = select(event.target);
// if it matches we call the listener
if (eventTarget) {
+ // We save the matching target into the event, so it can be accessed even when hitching (see #18355)
+ event.selectorTarget = eventTarget;
return listener.call(eventTarget, event);
}
});
diff --git a/tests/unit/on.js b/tests/unit/on.js
index 4857cec..5b6a47d 100644
--- a/tests/unit/on.js
+++ b/tests/unit/on.js
@@ -178,6 +178,47 @@ define([
assert.strictEqual(listenerCallCount, 1);
},
+ 'hitch no selector': function () {
+ var div = document.body.appendChild(document.createElement("div"));
+ var span = div.appendChild(document.createElement("span"));
+ var button = span.appendChild(document.createElement("button"));
+ var that = { fake: true };
+ var result = {
+ contextIsOk: false,
+ selectorTargetIsOk: false
+ }
+
+ on(div, "click", lang.hitch(that, function (e) {
+ result.contextIsOk = this === that;
+ result.selectorTargetIsOk = e.selectorTarget === undefined; //selectorTarget is only available with event delegation
+ }));
+
+ on.emit(button, 'click', { cancelable: true, bubbles: true });
+
+ assert.isTrue(result.contextIsOk, "contextIsOk");
+ assert.isTrue(result.selectorTargetIsOk, "selectorTargetIsOk");
+ },
+ 'hitch with selector': function () {
+ var div = document.body.appendChild(document.createElement("div"));
+ var span = div.appendChild(document.createElement("span"));
+ var button = span.appendChild(document.createElement("button"));
+ var that = { fake: true };
+ var result = {
+ contextIsOk: false,
+ selectorTargetIsOk: false
+ }
+
+ on(div, "span:click", lang.hitch(that, function (e) {
+ result.contextIsOk = this === that;
+ result.selectorTargetIsOk = e.selectorTarget === span;
+ }));
+
+ on.emit(button, 'click', { cancelable: true, bubbles: true });
+
+ assert.isTrue(result.contextIsOk, "contextIsOk");
+ assert.isTrue(result.selectorTargetIsOk, "selectorTargetIsOk");
+ },
+
'listener call order': function () {
var order = [],
onMethodName = 'on' + testEventName;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list