bubble and delegate focus, blur, change with prototype
This file contains 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
(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