Skip to content

Instantly share code, notes, and snippets.

@RStankov
Created August 5, 2009 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RStankov/162593 to your computer and use it in GitHub Desktop.
Save RStankov/162593 to your computer and use it in GitHub Desktop.
(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
Copy link

A life-saver. Thanks!

@victor-homyakov
Copy link

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

@RStankov
Copy link
Author

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
Copy link

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
Copy link
Author

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