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
102 lines (87 loc) · 2.03 KB
/
loading.js
File metadata and controls
102 lines (87 loc) · 2.03 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 QSpinner from '../components/spinner/QSpinner.js'
import { isSSR } from './platform.js'
let
vm,
timeout,
props = {},
defaults = {
delay: 0,
message: false,
spinnerSize: 80,
spinnerColor: 'white',
messageColor: 'white',
spinner: QSpinner,
customClass: false
}
const staticClass = 'q-loading animate-fade fullscreen column flex-center z-max'
export default {
isActive: false,
show (opts) {
if (isSSR) { return }
props = Object.assign({}, defaults, opts)
if (typeof props.customClass === 'string') {
props.customClass = props.customClass.trim()
}
if (this.isActive) {
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 this.__Vue({
name: 'QLoading',
el: node,
render (h) {
return h('div', {
staticClass,
'class': props.customClass
}, [
h(props.spinner, {
props: {
color: props.spinnerColor,
size: props.spinnerSize
}
}),
props.message
? h('div', {
'class': `text-${props.messageColor}`,
domProps: {
innerHTML: props.message
}
})
: null
])
}
})
}, props.delay)
this.isActive = true
},
hide () {
if (!this.isActive) {
return
}
if (timeout) {
clearTimeout(timeout)
timeout = null
}
else {
vm.$destroy()
document.body.classList.remove('with-loading')
vm.$el.remove()
vm = null
}
this.isActive = false
},
setDefaults (opts) {
Object.assign(defaults, opts)
},
__Vue: null,
install ({ $q, Vue, cfg: { loading } }) {
loading && this.setDefaults(loading)
$q.loading = this
this.__Vue = Vue
}
}