-
-
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 | |
}); |
yes currently, but Event.element is going to be deprecated and removed in the future. Because and thats the reason for this change.
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?
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)
In this case Event.element(e) === Event.findElement(e) but executes slightly faster (in fact findElement with single argument directly calls Event.element)