Created
May 7, 2013 07:30
-
-
Save LeoDT/5530844 to your computer and use it in GitHub Desktop.
backbone like event map
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
$.fn.event_map = function(map){ | |
var el = this; | |
$.each(map, function(k, v){ | |
var event = k.slice(0, k.indexOf(" ")), | |
selector = k.slice(k.indexOf(" ") + 1, k.length); | |
if(event && typeof v === "function"){ | |
if(k.indexOf(" ") != -1){ | |
el.on(event, selector, v); | |
} | |
else{ | |
el.on(k, v); | |
} | |
} | |
else{ | |
throw "need a event and function"; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment