Last active
August 29, 2015 14:17
-
-
Save Alex1990/cc34fbc38bde0a7abf62 to your computer and use it in GitHub Desktop.
A simple event delegation.
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
| /** | |
| * A simple event delegation method. | |
| */ | |
| // closest method: https://gist.github.com/Alex1990/5547956babc593852c3a | |
| function delegate(elem, type, selector, listener, capture) { | |
| listener._delegateWrapper = function(e) { | |
| if (e.delegateTarget = closest(e.target, selector, elem)) { | |
| listener.call(e.delegateTarget, e); | |
| } | |
| } | |
| addEvent(elem, type, listener._delegateWrapper, capture); | |
| } | |
| function undelegate(elem, type, listener, capture) { | |
| removeEvent(elem, type, listener._delegateWrapper, capture); | |
| delete listener._delegateWrapper; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment