forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (86 loc) · 1.98 KB
/
index.js
File metadata and controls
102 lines (86 loc) · 1.98 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { Vue } from '../../deps'
import Events from '../../features/events'
import { QSpinner } from '../spinner'
let
vm,
appIsInProgress = false,
timeout,
props = {}
const staticClass = 'q-loading animate-fade fullscreen column flex-center z-max'
function isActive () {
return appIsInProgress
}
function show ({
delay = 500,
message = false,
spinnerSize = 80,
spinnerColor = 'white',
messageColor = 'white',
spinner = QSpinner,
customClass = false
} = {}) {
props.spinner = spinner
props.message = message
props.spinnerSize = spinnerSize
props.spinnerColor = spinnerColor
props.messageColor = messageColor
if (customClass && typeof customClass === 'string') {
props.customClass = ` ${customClass.trim()}`
}
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({
name: 'q-loading',
el: node,
functional: true,
render (h) {
const child = [
h(props.spinner, {props: {
color: props.spinnerColor,
size: props.spinnerSize
}})
]
if (message) {
child.push(h('div', {
staticClass: `text-${props.messageColor}`,
domProps: {
innerHTML: props.message
}
}))
}
return h('div', {staticClass: staticClass + props.customClass}, child)
}
})
}, 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
}