forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppVisibility.js
More file actions
40 lines (32 loc) · 931 Bytes
/
AppVisibility.js
File metadata and controls
40 lines (32 loc) · 931 Bytes
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
import Vue from 'vue'
import { isSSR } from './Platform.js'
export default {
appVisible: false,
install ({ $q }) {
if (isSSR === true) {
this.appVisible = $q.appVisible = true
return
}
let prop, evt
if (typeof document.hidden !== 'undefined') { // Opera 12.10 and Firefox 18 and later support
prop = 'hidden'
evt = 'visibilitychange'
}
else if (typeof document.msHidden !== 'undefined') {
prop = 'msHidden'
evt = 'msvisibilitychange'
}
else if (typeof document.webkitHidden !== 'undefined') {
prop = 'webkitHidden'
evt = 'webkitvisibilitychange'
}
const update = () => {
this.appVisible = $q.appVisible = !document[prop]
}
update()
if (evt && typeof document[prop] !== 'undefined') {
Vue.util.defineReactive($q, 'appVisible', this.appVisible)
document.addEventListener(evt, update, false)
}
}
}