Last active
August 29, 2015 14:01
-
-
Save potch/ebcf5916887963125175 to your computer and use it in GitHub Desktop.
This file contains 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
function delegate(selector, handler) { | |
return function(e) { | |
var context = this; | |
var target = e.target; | |
var delegateEl = e.currentTarget; | |
var matches = delegateEl.querySelectorAll(selector); | |
for (var el = target; el.parentNode && el !== delegateEl; el = el.parentNode) { | |
for (var i = 0; i < matches.length; i++) { | |
if (matches[i] === el) { | |
handler.call(context, e); | |
return; | |
} | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment