Created
August 14, 2012 13:21
-
-
Save adamsilver/3349199 to your computer and use it in GitHub Desktop.
jessie event delegation design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var containerEl = jessie.getElement('container'); | |
jessie.delegateClassNameListener(containerEl, 'click', 'myClass', function(e, secondParam) { | |
// NOTE: | |
// 1) Our handler only fires when the anchor with a class of 'myClass' is clicked | |
// or if the img inside the anchor is clicked etc | |
// 2) In our handler we provide the raw event object as the first param | |
// this could be the anchor or it could be the img so the target in this case is | |
// not consistently going to give us what we want. | |
var target = jessie.getEventTarget(e); | |
// should be the anchor with a class of 'myClass' but we should also provide this | |
// reference as the second parameter | |
this; | |
// this should be the same as 'this' i.e. the anchor with a class of myClass. | |
secondParam; | |
// SO: What should we call this secondParam parameter? currentTarget, target, sourceNode (as is now)? | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="container"> | |
<div> | |
<a class='myClass'><img src='/path/to/img.gif'></a> | |
<a class='myClass'>some text</a> | |
</div> | |
</div> |
eventNode
Either of those two will work. The second argument is redundant in these non-bound listener methods, right? But I think we should still pass it to keep the same signature with the bound versions. Hadn't really considered until just now.
+1 for listenerNode. I'd understand what that was just by glancing at the source.
looking at the native event with Adam, there is a currentTarget. We think this is the best to keep it consistent?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
listenerNode