Created
December 7, 2009 11:29
-
-
Save haraldmartin/250775 to your computer and use it in GitHub Desktop.
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
// 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