-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (61 loc) · 2.05 KB
/
script.js
File metadata and controls
71 lines (61 loc) · 2.05 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
65
66
67
68
69
70
71
// script.js
let icon = {
success:
'<span class="material-symbols-outlined">task_alt</span>',
danger:
'<span class="material-symbols-outlined">error</span>',
warning:
'<span class="material-symbols-outlined">warning</span>',
info:
'<span class="material-symbols-outlined">info</span>',
};
const showToast = (
message = "Sample Message",
toastType = "info",
duration = 5000) => {
if (
!Object.keys(icon).includes(toastType))
toastType = "info";
let box = document.createElement("div");
box.classList.add(
"toast", `toast-${toastType}`);
box.innerHTML = ` <div class="toast-content-wrapper">
<div class="toast-icon">
${icon[toastType]}
</div>
<div class="toast-message">${message}</div>
<div class="toast-progress"></div>
</div>`;
duration = duration || 5000;
box.querySelector(".toast-progress").style.animationDuration =
`${duration / 1000}s`;
let toastAlready =
document.body.querySelector(".toast");
if (toastAlready) {
toastAlready.remove();
}
document.body.appendChild(box)};
let submit =
document.querySelector(".custom-toast.success-toast");
let information =
document.querySelector(".custom-toast.info-toast");
let failed =
document.querySelector(".custom-toast.danger-toast");
let warn =
document.querySelector(".custom-toast.warning-toast");
submit.addEventListener("click",(e) => {
e.preventDefault();
showToast("Article Submitted Successfully","success",5000);
});
information.addEventListener("click",(e) => {
e.preventDefault();
showToast("Do POTD and Earn Coins","info",5000);
});
failed.addEventListener("click",(e) => {
e.preventDefault();
showToast("Failed unexpected error","danger",5000);
});
warn.addEventListener("click", (e) => {
e.preventDefault();
showToast("!warning! server error","warning",5000);
});