Created
December 24, 2010 18:48
-
-
Save chicagoworks/754445 to your computer and use it in GitHub Desktop.
Override jquery.delegate() to accept an object
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
/** | |
* Override .delegate() | |
* if 'selector' is an object loop over the object and call .live() for each item | |
* otherwise it call .live() just like the original .delegate(). | |
* Roughly similar to the way the map is implemented in .bind(). | |
*/ | |
$.fn.delegate = function(selector, types, data, fn) { | |
if (typeof selector === "object") { | |
for (var sel in selector) { | |
for (var type in selector[sel]) { | |
this.live(type, data, selector[sel][type], sel); | |
} | |
} | |
return this; | |
} else { | |
return this.live(types, data, fn, selector); | |
} | |
}; |
I assume .delegate now calls .on() underneath?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Call delegate with an object map of selectors, events and function