forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.js
More file actions
76 lines (64 loc) · 1.35 KB
/
loading.js
File metadata and controls
76 lines (64 loc) · 1.35 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
67
68
69
70
71
72
73
74
75
76
import { current as theme } from '../../features/theme'
import { Vue } from '../../vue-install'
import Events from '../../features/events'
import Loading from './Loading.vue'
let
vm,
appIsInProgress = false,
timeout,
props = {}
function isActive () {
return appIsInProgress
}
function show ({
delay = 500,
spinner = theme === 'ios' ? 'ios' : 'tail',
message = false,
spinnerSize,
spinnerColor,
messageColor
} = {}) {
props.spinner = spinner
props.message = message
props.spinnerSize = spinnerSize
props.spinnerColor = spinnerColor
props.messageColor = messageColor
if (appIsInProgress) {
vm && vm.$forceUpdate()
return
}
timeout = setTimeout(() => {
timeout = null
const node = document.createElement('div')
document.body.appendChild(node)
document.body.classList.add('with-loading')
vm = new Vue({
el: node,
render: h => h(Loading, {props})
})
}, delay)
appIsInProgress = true
Events.$emit('app:loading', true)
}
function hide () {
if (!appIsInProgress) {
return
}
if (timeout) {
clearTimeout(timeout)
timeout = null
}
else {
vm.$destroy()
document.body.classList.remove('with-loading')
document.body.removeChild(vm.$el)
vm = null
}
appIsInProgress = false
Events.$emit('app:loading', false)
}
export default {
isActive,
show,
hide
}