-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
26 lines (22 loc) · 834 Bytes
/
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
function setupDialog(showId, closeId, dialogId) {
const showButton = document.getElementById(showId);
const closeButton = document.getElementById(closeId);
const dialog = document.getElementById(dialogId);
function closeModalWithKeys(event) {
if (event.key === 'Enter' || event.key === 'Escape') {
event.preventDefault();
dialog.close();
removeEventListener('keydown', closeModalWithKeys);
}
};
showButton.addEventListener("click", () => {
dialog.showModal();
addEventListener('keydown', closeModalWithKeys);
});
closeButton.addEventListener("click", () => {
dialog.close();
removeEventListener('keydown', closeModalWithKeys);
});
}
setupDialog("showInputFormat", "closeInputFormat", "inputFormat");
setupDialog("showConfigFormat", "closeConfigFormat", "configFormat");