Created
August 29, 2015 02:05
-
-
Save lazd/7d023fb808f1e9adf504 to your computer and use it in GitHub Desktop.
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
| function delegate(el, type, selector, callback) { | |
| el = typeof el === 'string' ? document.querySelector(el) : el; | |
| if (!el) return; | |
| el.addEventListener(type, function(event) { | |
| var node = event.target; | |
| while (node && node !== el) { | |
| if (node.matches(selector)) | |
| callback.call(node, event); | |
| node = node.parentNode; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment