Skip to content

Instantly share code, notes, and snippets.

@itsadok
Forked from yuvaltobias/behaviors.js
Created July 12, 2011 07:37
Show Gist options
  • Save itsadok/1077563 to your computer and use it in GitHub Desktop.
Save itsadok/1077563 to your computer and use it in GitHub Desktop.
Behavior-registration for UJS with jQuery
// 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 + ']').each(function() {
$(this).bind(trigger, handler);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment