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
142 lines (118 loc) · 3.26 KB
/
Loading.js
File metadata and controls
142 lines (118 loc) · 3.26 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import Vue from 'vue'
import QSpinner from '../components/spinner/QSpinner.js'
import { isSSR } from './Platform.js'
import cache from '../utils/cache.js'
import { isObject } from '../utils/is.js'
import { preventScroll } from '../mixins/prevent-scroll.js'
let
vm,
uid = 0,
timeout,
props = {}
const
originalDefaults = {
delay: 0,
message: false,
spinnerSize: 80,
spinnerColor: 'white',
messageColor: 'white',
backgroundColor: 'black',
spinner: QSpinner,
customClass: ''
},
defaults = { ...originalDefaults }
const Loading = {
isActive: false,
show (opts) {
if (isSSR === true) { return }
props = isObject(opts) === true && opts.ignoreDefaults === true
? { ...originalDefaults, ...opts }
: { ...defaults, ...opts }
props.customClass += ` text-${props.backgroundColor}`
this.isActive = true
if (vm !== void 0) {
props.uid = uid
vm.$forceUpdate()
return
}
props.uid = ++uid
clearTimeout(timeout)
timeout = setTimeout(() => {
timeout = void 0
const node = document.createElement('div')
document.body.appendChild(node)
vm = new Vue({
name: 'QLoading',
// hide App from Vue devtools
devtools: { hide: true },
beforeCreate () {
// prevent error in Vue devtools
this._routerRoot === void 0 && (this._routerRoot = {})
},
el: node,
mounted () {
preventScroll(true)
},
render: (h) => {
return h('transition', {
props: {
name: 'q-transition--fade',
appear: true
},
on: cache(this, 'tr', {
'after-leave': () => {
// might be called to finalize
// previous leave, even if it was cancelled
if (this.isActive !== true && vm !== void 0) {
preventScroll(false)
vm.$destroy()
vm.$el.remove()
vm = void 0
}
}
})
}, [
this.isActive === true ? h('div', {
staticClass: 'q-loading fullscreen column flex-center z-max',
key: props.uid,
class: props.customClass.trim()
}, [
h(props.spinner, {
props: {
color: props.spinnerColor,
size: props.spinnerSize
}
}),
(props.message && h('div', {
class: `text-${props.messageColor}`,
domProps: {
[props.sanitize === true ? 'textContent' : 'innerHTML']: props.message
}
})) || void 0
]) : null
])
}
})
}, props.delay)
},
hide () {
if (this.isActive === true) {
if (timeout !== void 0) {
clearTimeout(timeout)
timeout = void 0
}
this.isActive = false
}
},
setDefaults (opts) {
isObject(opts) === true && Object.assign(defaults, opts)
},
install ({ $q, cfg: { loading } }) {
this.setDefaults(loading)
$q.loading = this
}
}
if (isSSR === false) {
Vue.util.defineReactive(Loading, 'isActive', Loading.isActive)
}
export default Loading