forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-visibility.js
More file actions
66 lines (58 loc) · 1.46 KB
/
app-visibility.js
File metadata and controls
66 lines (58 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Events from './events'
import Utils from '../utils'
let
hidden = 'hidden',
appVisibility = 'visible'
function onchange (evt) {
let
v = 'visible',
h = 'hidden',
state,
evtMap = {
focus: v,
focusin: v,
pageshow: v,
blur: h,
focusout: h,
pagehide: h
}
evt = evt || window.event
if (evt.type in evtMap) {
state = evtMap[evt.type]
}
else {
state = this[hidden] ? h : v
}
appVisibility = state
Events.$emit('app:visibility', state)
}
Utils.dom.ready(() => {
// Standards:
if (hidden in document) {
document.addEventListener('visibilitychange', onchange)
}
else if ((hidden = 'mozHidden') in document) {
document.addEventListener('mozvisibilitychange', onchange)
}
else if ((hidden = 'webkitHidden') in document) {
document.addEventListener('webkitvisibilitychange', onchange)
}
else if ((hidden = 'msHidden') in document) {
document.addEventListener('msvisibilitychange', onchange)
}
// IE 9 and lower:
else if ('onfocusin' in document) {
document.onfocusin = document.onfocusout = onchange
}
// All others:
else {
window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange
}
// set the initial state (but only if browser supports the Page Visibility API)
if (document[hidden] !== undefined) {
onchange({type: document[hidden] ? 'blur' : 'focus'})
}
})
export default {
isVisible: () => appVisibility === 'visible'
}