-
Notifications
You must be signed in to change notification settings - Fork 1
/
modal.js
57 lines (51 loc) · 2.1 KB
/
modal.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
let modalBoard = document.getElementById("modal-board");
let modalDanger = document.getElementById("modal-danger");
let modalDangerCloseButton = document.getElementById("modal-danger-close");
let modalDangerSuccessButton = document.getElementById("modal-danger-success");
let modalDangerCancelButton = document.getElementById("modal-danger-cancel");
let modalInfo = document.getElementById("modal-info");
let modalInfoCloseButton = document.getElementById("modal-info-close");
function openModal(type) {
modalBoard.style.display = "flex";
if(type==="danger"){
modalDanger.style.display = "block";
return new Promise(
(resolve, reject) => {
modalDangerCancelButton.addEventListener("click", () => {
closeModal(modalDanger);
modalDangerCancelButton.removeEventListener("click",()=>{});
resolve(false);
});
modalDangerCloseButton.addEventListener("click", () => {
closeModal(modalDanger);
modalDangerCloseButton.removeEventListener("click",()=>{});
resolve(false);
});
modalDangerSuccessButton.addEventListener("click", () => {
closeModal(modalDanger);
modalDangerSuccessButton.removeEventListener("click",()=>{});
resolve(true);
});
}
);
}else if(type==="info"){
modalInfo.style.display = "block";
return new Promise(
(resolve, reject) => {
modalInfoCloseButton.addEventListener("click", () => {
closeModal(modalInfo);
modalInfoCloseButton.removeEventListener("click",()=>{});
resolve(false);
});
}
);
}
}
function closeModal(modalElement) {
modalElement.style.display="none";
modalBoard.style.display = "none";
}
let infoButton=document.getElementById("info-button");
infoButton.addEventListener("click",()=>{
openModal("info");
});