Skip to content

Instantly share code, notes, and snippets.

@adamsilver
Created August 14, 2012 13:21
Show Gist options
  • Save adamsilver/3349199 to your computer and use it in GitHub Desktop.
Save adamsilver/3349199 to your computer and use it in GitHub Desktop.
jessie event delegation design
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)?
});
<div id="container">
<div>
<a class='myClass'><img src='/path/to/img.gif'></a>
<a class='myClass'>some text</a>
</div>
</div>
@web-bert
Copy link

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