Skip to content

Instantly share code, notes, and snippets.

@hchoroomi
Forked from jamis/behaviors.js
Created March 2, 2010 20:02
Show Gist options
  • Save hchoroomi/319852 to your computer and use it in GitHub Desktop.
Save hchoroomi/319852 to your computer and use it in GitHub Desktop.
// 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