-
-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathspinner.ts
53 lines (46 loc) · 1.48 KB
/
spinner.ts
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
import h from 'mithril/hyperscript'
let timeoutId: number | undefined
export default {
spin() {
if (timeoutId !== undefined || document.getElementById('globalSpinner')) {
return
}
const spinner = document.createElement('div')
spinner.id = 'globalSpinner'
spinner.className = 'spinner globalSpinner'
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg.setAttribute('viewBox', '0 0 40 40')
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle')
circle.setAttribute('cx', '20')
circle.setAttribute('cy', '20')
circle.setAttribute('r', '18')
circle.setAttribute('fill', 'none')
svg.appendChild(circle)
spinner.appendChild(svg)
timeoutId = setTimeout(() => {
document.body.appendChild(spinner)
}, 200)
},
stop() {
clearTimeout(timeoutId as number)
timeoutId = undefined
const spinners = document.getElementsByClassName('globalSpinner')
if (spinners.length) {
setTimeout(function() {
while (spinners[0]) document.body.removeChild(spinners[0])
}, 500)
}
},
getVdom(classes?: string) {
return h('div.spinner', { className: classes || '' }, [
h('svg', {
viewBox: '0 0 40 40'
}, [
h('circle', { cx: '20', cy: '20', r: '18', fill: 'none' })
])
])
},
getHtml() {
return '<div class="spinner monochrome"><svg viewBox="0 0 40 40"><circle cx=20 cy=20 r=18 fill="none"></circle></svg></div>'
}
}