Last active
December 27, 2015 17:19
-
-
Save nilliams/7361860 to your computer and use it in GitHub Desktop.
A relatively sane onClick helper (Webkit only), for e.g. Node-Webkit work. Add additional prefixed versions of `matchesSelector` for further browser compat.
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 onClick(selector, fn) { | |
document.addEventListener('click', function(e) { | |
if ( _matchesSelector(e.target, selector) ) fn(e); | |
}, false); | |
} | |
function _matchesSelector(el, selector) { | |
var doc = document.documentElement; | |
var fn = doc.matchesSelector || doc.webkitMatchesSelector; | |
return fn.call( el, selector ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment