Created
July 29, 2011 18:46
-
-
Save danwrong/1114468 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(rules) { | |
return function(e) { | |
var target = $(e.target), parent = null; | |
for (var selector in rules) { | |
if (target.is(selector) || ((parent = target.parents(selector)) && parent.length > 0)) { | |
return rules[selector].apply(this, [parent || target].concat($.makeArray(arguments))); | |
} | |
parent = null; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment