Skip to content

Instantly share code, notes, and snippets.

@sudara
Created September 18, 2008 16:07
Show Gist options
  • Save sudara/11441 to your computer and use it in GitHub Desktop.
Save sudara/11441 to your computer and use it in GitHub Desktop.
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