Forked from nuxodin/focusin focusout support for firefox.js
Last active
August 29, 2015 14:19
-
-
Save celmaun/9b4feaed81882a391d6d to your computer and use it in GitHub Desktop.
This file contains hidden or 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(w, d, undefined){ | |
if( w.onfocusin === undefined){ | |
d.addEventListener('focus', addPolyfill, true); | |
d.addEventListener('blur', addPolyfill, true); | |
d.addEventListener('focusin', removePolyfill, true); | |
d.addEventListener('focusout', removePolyfill, true); | |
} | |
function addPolyfill(e){ | |
var type = e.type === 'focus' ? 'focusin' : 'focusout'; | |
var event = new CustomEvent(type, { bubbles:true, cancelable:false }); | |
event.c1Generated = true; | |
e.target.dispatchEvent( event ); | |
} | |
function removePolyfill(e){ | |
if(e.c1Generated){ | |
d.removeEventListener('focusin', removePolyfill, true); | |
d.removeEventListener('focusout', removePolyfill, true); | |
} else { | |
d.removeEventListener('focus', addPolyfill, true); | |
d.removeEventListener('blur', addPolyfill, true); | |
d.removeEventListener('focusin', removePolyfill, true); | |
d.removeEventListener('focusout', removePolyfill, true); | |
} | |
} | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment