-
-
Save yuvaltobias/1076236 to your computer and use it in GitHub Desktop.
Behavior-registration for UJS with jQuery
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
// An Unobtrusive Javascript (UJS) driver based on explicit behavior definitions. Just | |
// put a "data-behaviors" attribute on your view elements, and then assign callbacks | |
// for those named behaviors via $.Behaviors.add. | |
$.Behaviors = { | |
add: function(trigger, behavior, handler) { | |
$('[data-behaviors~=' + behavior + ']').live(trigger, handler); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We're doing it live()
It doesn't make much sense to call it a behavior, and expect to call $.Behaviors.add(...) each time an element is added dynamically.