quasar-framework
Version:
Simultaneously build desktop/mobile SPA websites & phone/tablet apps with VueJS
43 lines (34 loc) • 989 B
JavaScript
import { isSSR } from './platform'
export default {
appVisible: false,
__installed: false,
install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true
if (isSSR) {
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)
}
}
}