Skip to content

Instantly share code, notes, and snippets.

@jamis
Created March 2, 2010 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save jamis/318967 to your computer and use it in GitHub Desktop.
Save jamis/318967 to your computer and use it in GitHub Desktop.
Behavior-registration for UJS
// 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.
var Behaviors = {
add: function(trigger, behavior, handler) {
document.observe(trigger, function(event) {
var element = event.findElement("*[data-behaviors~=" + behavior + "]");
if (element) handler(element, event);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment