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
152 lines (124 loc) · 3.6 KB
/
Copy pathLoading.js
File metadata and controls
152 lines (124 loc) · 3.6 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
143
144
145
146
147
148
149
150
151
152
import { h, createApp, Transition, onMounted } from 'vue'
import QSpinner from '../components/spinner/QSpinner.js'
import defineReactivePlugin from '../utils/private/define-reactive-plugin.js'
import { createGlobalNode, removeGlobalNode } from '../utils/private/global-nodes.js'
import preventScroll from '../utils/prevent-scroll.js'
import { isObject } from '../utils/private/is.js'
let
app,
vm,
uid = 0,
timeout,
props = {}
const originalDefaults = {
delay: 0,
message: false,
html: false,
spinnerSize: 80,
spinnerColor: '',
messageColor: '',
backgroundColor: '',
boxClass: '',
spinner: QSpinner,
customClass: ''
}
const defaults = { ...originalDefaults }
const Plugin = defineReactivePlugin({
isActive: false
}, {
show (opts) {
if (__QUASAR_SSR_SERVER__) { return }
props = isObject(opts) === true && opts.ignoreDefaults === true
? { ...originalDefaults, ...opts }
: { ...defaults, ...opts }
Plugin.isActive = true
if (app !== void 0) {
props.uid = uid
vm.$forceUpdate()
return
}
props.uid = ++uid
clearTimeout(timeout)
timeout = setTimeout(() => {
timeout = void 0
const el = createGlobalNode('q-loading')
app = createApp({
name: 'QLoading',
setup () {
onMounted(() => {
preventScroll(true)
})
function onAfterLeave () {
// might be called to finalize
// previous leave, even if it was cancelled
if (Plugin.isActive !== true && app !== void 0) {
preventScroll(false)
app.unmount(el)
removeGlobalNode(el)
app = void 0
vm = void 0
}
}
function getContent () {
if (Plugin.isActive !== true) {
return null
}
const content = [
h(props.spinner, {
class: 'q-loading__spinner',
color: props.spinnerColor,
size: props.spinnerSize
})
]
props.message && content.push(
h('div', {
class: 'q-loading__message'
+ (props.messageColor ? ` text-${ props.messageColor }` : ''),
[ props.html === true ? 'innerHTML' : 'textContent' ]: props.message
})
)
return h('div', {
class: 'q-loading fullscreen flex flex-center z-max ' + props.customClass.trim(),
key: props.uid
}, [
h('div', {
class: 'q-loading__backdrop'
+ (props.backgroundColor ? ` bg-${ props.backgroundColor }` : '')
}),
h('div', {
class: 'q-loading__box column items-center ' + props.boxClass
}, content)
])
}
return () => h(Transition, {
name: 'q-transition--fade',
appear: true,
onAfterLeave
}, getContent)
}
})
vm = app.mount(el)
}, props.delay)
},
hide () {
if (__QUASAR_SSR_SERVER__ !== true && Plugin.isActive === true) {
if (timeout !== void 0) {
clearTimeout(timeout)
timeout = void 0
}
Plugin.isActive = false
}
},
setDefaults (opts) {
if (__QUASAR_SSR_SERVER__ !== true) {
isObject(opts) === true && Object.assign(defaults, opts)
}
},
install ({ $q }) {
$q.loading = this
if (__QUASAR_SSR_SERVER__ !== true && $q.config.loading !== void 0) {
this.setDefaults($q.config.loading)
}
}
})
export default Plugin