generated from hugomods/template-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
spinner.ts
39 lines (31 loc) · 1006 Bytes
/
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
export default class Spinner {
constructor(private ele: string | HTMLElement) {
}
getElement(): HTMLElement {
if (!(this.ele instanceof HTMLElement)) {
this.ele = document.querySelector(this.ele) as HTMLElement
}
return this.ele
}
private searchIcon: HTMLElement
getSearchIcon(): HTMLElement {
if (!this.searchIcon) {
this.searchIcon = this.getElement().previousElementSibling as HTMLElement
}
return this.searchIcon
}
hide() {
// delay the action to make the spinner more obvious.
setTimeout(() => {
this.getSearchIcon().classList.remove('disabled')
this.getElement().classList.add('disabled')
}, 200)
}
show() {
this.getSearchIcon().classList.add('disabled')
// delay for making sure the search icon was hidden.
setTimeout(() => {
this.getElement().classList.remove('disabled')
}, 1)
}
}