-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (40 loc) · 1.32 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
// import './hotsnackbar.css';
function hsSnackbarWrapper() {
let hsOldId = 0;
let hsIntervalToClear = 0;
let hsTimeOut = 20000;
function hsRemakeSnackbar(randomId, hsOldIdtoHide, textx) {
clearTimeout(hsIntervalToClear);
let timedOutSnackbars = document.getElementsByClassName("hs-snackbar-hide");
while (timedOutSnackbars.length > 0) {
timedOutSnackbars[0].remove();
}
document.getElementById(hsOldIdtoHide).className += " hs-snackbar-hide";
hsOldId = 0;
hsMakeSnackbar(randomId, textx);
}
function hsMakeSnackbar(randomId, textx) {
let hsSnackbarDiv = document.createElement("div");
hsSnackbarDiv.innerHTML = textx;
hsSnackbarDiv.id = randomId;
hsSnackbarDiv.className = "hs-snackbar";
document.getElementsByTagName("body")[0].appendChild(hsSnackbarDiv);
let currenths = hsSnackbarDiv;
currenths.className += " hs-snackbar-show";
hsOldId = randomId;
hsIntervalToClear = setTimeout(function() {
currenths.className += " hs-snackbar-hide";
hsOldId = 0;
}, hsTimeOut);
}
return function hotsnackbar(text) {
let randomId = Math.random();
if (hsOldId) {
hsRemakeSnackbar(randomId, hsOldId, text);
} else {
hsMakeSnackbar(randomId, text);
}
};
}
let hotsnackbar = hsSnackbarWrapper();
module.exports = hotsnackbar;