-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
88 lines (68 loc) · 2.6 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
let addButton = document.querySelector("#add-button")
let clearButton = document.querySelector("#clear-button");
let toasts = document.querySelector("#toasts")
addButton.addEventListener('click', (event) => {
let cancelable = document.querySelector("#cancelable")
let successBtn = document.querySelector("#success")
let errorBtn = document.querySelector("#error")
if (successBtn.checked) {
let duration = document.querySelector("#duration").value;
const success = document.createElement("div");
const successDesc = document.createElement("p");
const successBtn = document.createElement("button");
success.classList.add('success-toast', 'toast');
successDesc.classList.add('message');
successBtn.classList.add('cancel-button');
toasts.appendChild(success);
success.appendChild(successDesc);
if(cancelable.checked){
success.appendChild(successBtn);
}
successBtn.innerHTML = 'X';
var text = document.getElementById("message-content").value;
if (text == '') {
successDesc.innerHTML = 'Succes';
} else {
successDesc.innerHTML = text
}
var _tick = setInterval(function () {
success.remove()
}, duration = duration < 500 ? 500 : duration)
successBtn.addEventListener('click', (event => {
success.remove()
}))
}
if (errorBtn.checked) {
let duration = document.querySelector("#duration").value;
const error = document.createElement("div");
const errorDesc = document.createElement("p");
const errorBtn = document.createElement("button");
error.classList.add('error-toast', 'toast');
errorDesc.classList.add('message');
errorBtn.classList.add('cancel-button');
toasts.appendChild(error);
error.appendChild(errorDesc);
if(cancelable.checked){
error.appendChild(errorBtn);
}
errorBtn.innerHTML = 'X'
var text = document.getElementById("message-content").value;
if (text == '') {
errorDesc.innerHTML = 'Error';
} else {
errorDesc.innerHTML = text
}
var _tick = setInterval(function () {
error.remove()
}, duration = duration < 500 ? 500 : duration)
errorBtn.addEventListener('click', (event => {
error.remove()
}))
}
})
clearButton.addEventListener('click', (event) => {
let divs = document.querySelectorAll('#toasts div')
divs.forEach(div => {
div.remove()
})
})