Open jamiebuilds opened 8 years ago
That's a good point about the multiple bindings if you can it more than once. Open to suggestions about that.
As per accurate browser support, that is also a good point. http://stackoverflow.com/questions/7337670/how-to-detect-focusin-support seems to indicate that the only way is to make a focusable element and fire focus on that element, which seems really obtrusive and gross. Not sure what to do about that one.
The only accurate way I can find to test for this is to:
var el = document.createElement('input'),
prev = document.activeElement,
supported = false;
function callback() {
supported = true;
}
if (window.addEventListener) {
el.addEventListener('focusin', callback);
} else if (window.attachEvent) {
el.attachEvent('onfocusin', callback);
}
document.body.appendChild(el);
el.focus();
if (prev) {
prev.focus();
} else {
el.blur();
}
document.body.removeChild(el);
In pre-Edge you could check with 'onfocusin' in window
but Edge removed the inference so it's a bit trickier. Related to https://github.com/jquery/jquery/issues/2389#issuecomment-148947869.
@jdalton What does this result in for Edge? (sorry, can't test right now)
var el = document.createElement('input');
'onfocusin' in el; // Safari: true, Chrome: false
false
damnit
This is not enough to detect browser support:
Safari and Chrome both support
focusin
butwindow.onfocusin
will beundefined
.There's also an issue of this polyfill running more than once even after doing it's job. This is an issue if you have multiple copies for some reason or if you call
polyfill()
more than once.