Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function(){
function focusInHandler(e){
Event.findElement(e).fire("focus:in");
}
function focusOutHandler(e){
Event.findElement(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);
}
})();
document.on('focus:in', selector, function(){
// on focus
});
document.on('focus:out', selector, function(){
// on blur
});
@eric1234

This comment has been minimized.

Copy link

@eric1234 eric1234 commented Jun 29, 2010

A life-saver. Thanks!

@victor-homyakov

This comment has been minimized.

Copy link

@victor-homyakov victor-homyakov commented Aug 30, 2010

In this case Event.element(e) === Event.findElement(e) but executes slightly faster (in fact findElement with single argument directly calls Event.element)

@RStankov

This comment has been minimized.

Copy link
Owner Author

@RStankov RStankov commented Aug 30, 2010

yes currently, but Event.element is going to be deprecated and removed in the future. Because and thats the reason for this change.

@victor-homyakov

This comment has been minimized.

Copy link

@victor-homyakov victor-homyakov commented Aug 31, 2010

Deprecated? Maybe. Removed? Deprecated things like Element.ClassNames, Position, $continue, Insertion, Toggle are still not removed. Why such widely used (e.g. in scriptaculous, ajaxtags, livepipe, modalbox, tablekit) method like Event.element will be removed in the (near) future?

@RStankov

This comment has been minimized.

Copy link
Owner Author

@RStankov RStankov commented Aug 31, 2010

I don't know from the docs - http://api.prototypejs.org/dom/event/prototype/element/ and from I have communicated with the Prototype Core it will be removed some day. Prototype as a whole is moving really really slow :( But I prefer my code to use the no deprecated funcs. (as for ClassNames, Position, $continue, Insertation, Toggle I use a custom build and not include those)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.