Created
September 18, 2008 16:07
-
-
Save sudara/11441 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
delegate: function(rules) { | |
return function(e) { | |
var target = $(e.target); | |
// first check the target itself | |
for(var selector in rules){ | |
if (target.is(selector)) | |
return rules[selector].apply(this, $.makeArray(arguments)); | |
} | |
// then, jump up to parents | |
for(var selector in rules){ | |
if ((target = target.parents(selector)) && target.length > 0) | |
return rules[selector].apply(this, [target].concat($.makeArray(arguments))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment