Skip to content

Instantly share code, notes, and snippets.

@haraldmartin
Created December 7, 2009 11:29
Show Gist options
  • Save haraldmartin/250775 to your computer and use it in GitHub Desktop.
Save haraldmartin/250775 to your computer and use it in GitHub Desktop.
// provide a shorter version to listen for events (like jQuery) but with a $-prefix
// so it won't conflict with the builtin click() submit() etc.
// $(element).$click(function() { ... });
(function() {
// Alias events to work directly as methods on elments
var methods = {};
$w("blur focus load resize scroll unload click dblclick ready" +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error").each(function(eventName) {
methods['$' + eventName] = function(element, handler) {
return Event.observe(element, eventName, handler);
}
});
Element.addMethods(methods);
// alias $(document).ready for dom:loaded: $(document).ready(function() { ... });
Object.extend(document, {
ready: Event.observe.curry(document, 'dom:loaded')
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment