Last active
August 29, 2015 14:07
-
-
Save kozo002/3bde4463c54ebe92b1bc to your computer and use it in GitHub Desktop.
Backbone.js like event mapping
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
jQuery.eventMapping = (object) -> | |
jQuery.each object.events, (event_and_selector, handler_name) -> | |
[event, selector_with_elem_name] = event_and_selector.split(' ') | |
[selector, elem_name] = selector_with_elem_name.split('|') | |
object.$el.on(event, selector, jQuery.proxy(object[handler_name], object)) | |
if elem_name? then object[elem_name] = object.$el.find(selector) |
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
jQuery.eventMapping = function(object) { | |
return jQuery.each(object.events, function(event_and_selector, handler_name) { | |
var elem_name, event, selector, selector_with_elem_name, _ref, _ref1; | |
_ref = event_and_selector.split(' '), event = _ref[0], selector_with_elem_name = _ref[1]; | |
_ref1 = selector_with_elem_name.split('|'), selector = _ref1[0], elem_name = _ref1[1]; | |
object.$el.on(event, selector, jQuery.proxy(object[handler_name], object)); | |
if (elem_name != null) return object[elem_name] = object.$el.find(selector); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment