-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoastm.js
More file actions
64 lines (58 loc) · 1.78 KB
/
Copy pathtoastm.js
File metadata and controls
64 lines (58 loc) · 1.78 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
var head = document.getElementsByTagName("head")[0];
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = "./node_modules/style.css";
head.appendChild(link);
let toastm = document.createElement("div");
let body = document.body;
toastm.className = "toastm";
function addPosition(position) {
if (position == "left") {
toastm.style.left = "12px";
} else if (position == "right") {
toastm.style.right = "12px";
} else if (position == "center") {
toastm.style.top = "0";
toastm.style.right = "0";
toastm.style.left = "0";
} else {
// default
toastm.style.top = "0";
toastm.style.right = "0";
toastm.style.left = "0";
}
}
export function addToastm(options) {
addPosition(options.position);
let color = options.color;
toastm.textContent = options.text;
if (color == "primary") {
toastm.className = "toastm " + color;
console.log(toastm.className);
} else if (color == "secondary") {
toastm.className = "toastm " + color;
} else if (color == "dark") {
toastm.className = "toastm " + color;
} else if (color == "danger") {
toastm.className = "toastm " + color;
} else if (color == "warning") {
toastm.style.color = "rgb(54,69,69)";
toastm.className = "toastm " + color;
} else if (color == "special") {
toastm.className = "toastm " + color;
} else if (color == "success") {
toastm.className = "toastm " + color;
}
body.appendChild(toastm);
setTimeout(() => {
toastm.style.visibility = "visible";
toastm.style.opacity = "1";
toastm.style.top = "20px";
}, options.seconds * 1000 || 1000);
setInterval(() => {
toastm.style.visibility = "hidden";
toastm.style.opacity = "0";
toastm.style.top = "0px";
}, (options.seconds + 3) * 1000 || 4000);
}