-
Notifications
You must be signed in to change notification settings - Fork 1
/
page-visibility.min.js
7 lines (7 loc) · 1.98 KB
/
page-visibility.min.js
1
2
3
4
5
6
7
/*!
* page-visibility.js - Page Visibility API Wrapper and Polyfill
* http://github.com/Fiery-Fenix
* @version 1.1.0
* @license MIT
*/
!function(i,t,e){var n,a=-1;n={STATE_VISIBLE:"visible",STATE_HIDDEN:"hidden",_visibilityState:{current:void 0,prev:void 0},_isNative:!1,_callbacks:{},isHidden:function(){return n._visibilityState.current===n.STATE_HIDDEN},getVisibilityState:function(){return n._visibilityState},subscribe:function(i){if("function"==typeof i){var t=n._uniqId();return n._callbacks[t]=i,t}},unsubscribe:function(i){n._callbacks[i]&&!n._isDestructing&&delete n._callbacks[i]},isNativelySupported:function(){return n._isNative},_uniqId:function(){return"pageVisibility_"+String(++a)},_onChange:function(i){var a={focus:n.STATE_VISIBLE,focusin:n.STATE_VISIBLE,pageshow:n.STATE_VISIBLE,blur:n.STATE_HIDDEN,focusout:n.STATE_HIDDEN,pagehide:n.STATE_HIDDEN};n._isDestructing||(i=i||t.event,n._visibilityState.prev=n._visibilityState.current,n.isNativelySupported()?n._visibilityState.current=e.webkitVisibilityState||e.visibilityState:i.type in a?n._visibilityState.current=a[i.type]:n._visibilityState.current=n.STATE_VISIBLE,n._notifySubscribers(i))},_notifySubscribers:function(i){for(var t in n._callbacks)n._callbacks.hasOwnProperty(t)&&n._callbacks[t]&&n._callbacks[t].call(e,i,n._visibilityState)},_init:function(){var i,a=navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i);n._inited||(n._isNative=("hidden"in e||"webkitHidden"in e)&&!a,i=function(){n._onChange.apply(n,arguments)},a?(t.addEventListener("pageshow",i,!0),t.addEventListener("pagehide",i,!0)):n._isNative?(n._visibilityState.current=e.webkitVisibilityState||e.visibilityState,e.addEventListener(("webkitHidden"in e?"webkit":"")+"visibilitychange",i)):"onfocusin"in e?(e.attachEvent("onfocusin",i),e.attachEvent("onfocusout",i)):(t.addEventListener("focus",i,!0),t.addEventListener("blur",i,!0)),n._inited=!0)}},n._init(),"undefined"!=typeof module&&module.exports?module.exports=n:i.pageVisibility=n}(this,window,document);