Skip to content

Instantly share code, notes, and snippets.

@aliang
Forked from RStankov/gist:162593
Created March 23, 2010 07:15
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aliang/340915 to your computer and use it in GitHub Desktop.
bubble and delegate focus, blur, change with prototype
(function(){
function focusInHandler(e){
Event.element(e).fire("focus:in");
}
function focusOutHandler(e){
Event.element(e).fire("focus:out");
}
if (document.addEventListener){
document.addEventListener("focus", focusInHandler, true);
document.addEventListener("blur", focusOutHandler, true);
} else {
document.observe("focusin", focusInHandler);
document.observe("focusout", focusOutHandler);
}
})();
// I don't have document.delegate, but I'd just use the similar
document.observe('focus:in', function(event) {
// this is how you'd handle change validating
// if (event.findElement().readAttribute(...)) ...
});
// also, if you give each element a previous_value property or some such
// you can implement onchange bubbling
/*
document.delegate(selector, 'focus:in', function(){
// on focus
});
document.delegate(selector, 'focus:out', function(){
// on blur
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment