/
index.js
64 lines (49 loc) · 1.33 KB
/
index.js
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
import './index.css';
let currentFile;
const createElement = function() {
let element = document.createElement('div');
element.className = 'throbbler';
element.id = 'js-throbbler';
return element;
};
export default class Throbbler {
constructor() {
this.visible = false;
this.element = createElement();
this.currentFile = this.getFilePath();
this.element.style.background = this.getCssBackground();
this.hide();
}
show() {
this.regenerateFile();
this.element.style.display = null;
this.element.style.background = this.getCssBackground();
this.visible = true;
}
hide() {
this.element.style.display = 'none';
this.visible = false;
}
getRandomDigit() {
return ~~(Math.random() * 10);
}
getFilePath (digit) {
if (!parseInt(digit)) {
digit = this.getRandomDigit();
}
return './components/throbbler/img/loaders/' + digit + '.svg';
};
getCssBackground() {
return 'url(' + this.currentFile + ') no-repeat center center';
};
getCurrentFile () {
return this.currentFile;
};
regenerateFile() {
this.currentFile = this.getFilePath();
return currentFile;
};
isVisible() {
return this.visible;
}
}