@fastkit/visibility
Advanced tools
Comparing version 0.6.10 to 0.6.11
@@ -5,5 +5,32 @@ 'use strict'; | ||
var helpers = require('@fastkit/helpers'); | ||
let _hidden = 'hidden'; | ||
let _visibilityChange = 'visibilitychange'; | ||
if (helpers.IN_WINDOW) { | ||
if (document.hidden !== undefined) { | ||
_hidden = 'hidden'; | ||
_visibilityChange = 'visibilitychange'; | ||
} | ||
else if (document.mozHidden !== undefined) { | ||
_hidden = 'mozHidden'; | ||
_visibilityChange = 'mozvisibilitychange'; | ||
} | ||
else if (document.msHidden !== undefined) { | ||
_hidden = 'msHidden'; | ||
_visibilityChange = 'msvisibilitychange'; | ||
} | ||
else if (document.webkitHidden !== undefined) { | ||
_hidden = 'webkitHidden'; | ||
_visibilityChange = 'webkitvisibilitychange'; | ||
} | ||
} | ||
const HIDDEN = _hidden; | ||
const VISIBILITY_CHANGE = _visibilityChange; | ||
const states = ['visible', 'hidden']; | ||
function getVisibilityState() { | ||
return 'hidden'; | ||
if (!helpers.IN_WINDOW) | ||
return 'hidden'; | ||
return document[HIDDEN] ? 'hidden' : 'visible'; | ||
} | ||
@@ -27,2 +54,7 @@ class VisibilityManager { | ||
constructor() { | ||
if (helpers.IN_WINDOW) { | ||
document.addEventListener(VISIBILITY_CHANGE, (e) => { | ||
this._setState(getVisibilityState(), e); | ||
}, false); | ||
} | ||
} | ||
@@ -29,0 +61,0 @@ _setState(state, event) { |
@@ -5,5 +5,32 @@ 'use strict'; | ||
var helpers = require('@fastkit/helpers'); | ||
let _hidden = 'hidden'; | ||
let _visibilityChange = 'visibilitychange'; | ||
if (helpers.IN_WINDOW) { | ||
if (document.hidden !== undefined) { | ||
_hidden = 'hidden'; | ||
_visibilityChange = 'visibilitychange'; | ||
} | ||
else if (document.mozHidden !== undefined) { | ||
_hidden = 'mozHidden'; | ||
_visibilityChange = 'mozvisibilitychange'; | ||
} | ||
else if (document.msHidden !== undefined) { | ||
_hidden = 'msHidden'; | ||
_visibilityChange = 'msvisibilitychange'; | ||
} | ||
else if (document.webkitHidden !== undefined) { | ||
_hidden = 'webkitHidden'; | ||
_visibilityChange = 'webkitvisibilitychange'; | ||
} | ||
} | ||
const HIDDEN = _hidden; | ||
const VISIBILITY_CHANGE = _visibilityChange; | ||
const states = ['visible', 'hidden']; | ||
function getVisibilityState() { | ||
return 'hidden'; | ||
if (!helpers.IN_WINDOW) | ||
return 'hidden'; | ||
return document[HIDDEN] ? 'hidden' : 'visible'; | ||
} | ||
@@ -27,2 +54,7 @@ class VisibilityManager { | ||
constructor() { | ||
if (helpers.IN_WINDOW) { | ||
document.addEventListener(VISIBILITY_CHANGE, (e) => { | ||
this._setState(getVisibilityState(), e); | ||
}, false); | ||
} | ||
} | ||
@@ -29,0 +61,0 @@ _setState(state, event) { |
@@ -0,4 +1,6 @@ | ||
import { IN_WINDOW } from '@fastkit/helpers'; | ||
let _hidden = 'hidden'; | ||
let _visibilityChange = 'visibilitychange'; | ||
if ((typeof document !== 'undefined')) { | ||
if (IN_WINDOW) { | ||
if (document.hidden !== undefined) { | ||
@@ -26,3 +28,3 @@ _hidden = 'hidden'; | ||
function getVisibilityState() { | ||
if (!(typeof document !== 'undefined')) | ||
if (!IN_WINDOW) | ||
return 'hidden'; | ||
@@ -48,3 +50,3 @@ return document[HIDDEN] ? 'hidden' : 'visible'; | ||
constructor() { | ||
if ((typeof document !== 'undefined')) { | ||
if (IN_WINDOW) { | ||
document.addEventListener(VISIBILITY_CHANGE, (e) => { | ||
@@ -51,0 +53,0 @@ this._setState(getVisibilityState(), e); |
{ | ||
"name": "@fastkit/visibility", | ||
"version": "0.6.10", | ||
"version": "0.6.11", | ||
"description": "@fastkit/visibility", | ||
@@ -5,0 +5,0 @@ "buildOptions": { |
12860
377