Created
January 31, 2014 17:06
-
-
Save 350d/8736390 to your computer and use it in GitHub Desktop.
Window Active Status
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 windowVisibility() { | |
var v = 'visible', hidden = h = 'hidden', map = {focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h}; | |
if (hidden in D) D.addEventListener("visibilitychange", onchange); | |
else if ((hidden = "mozHidden") in D) D.addEventListener("mozvisibilitychange", onchange); | |
else if ((hidden = "webkitHidden") in D) D.addEventListener("webkitvisibilitychange", onchange); | |
else if ((hidden = "msHidden") in D) D.addEventListener("msvisibilitychange", onchange); | |
else if ('onfocusin' in D) D.onfocusin = D.onfocusout = onchange; | |
W.onpageshow = W.onpagehide = W.onfocus = W.onblur = onchange; | |
function onchange(e) { | |
e = e || W.event; | |
W.active = ((e.type in map)?map[e.type]:this[hidden]?h:v) == v; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment