--
This commit is contained in:
parent
52bde7cc5e
commit
e4c9c302a5
257 changed files with 13967 additions and 131850 deletions
38
Libraries/js/modal.js
Normal file
38
Libraries/js/modal.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
window.addEventListener("DOMContentLoaded", (evt) => {
|
||||
window.onclick = (event) => {
|
||||
if (event.target.classList.contains("modal")) {
|
||||
let modal = event.target;
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
}
|
||||
};
|
||||
|
||||
document.querySelectorAll(".modal .close").forEach((closeBtn) => {
|
||||
closeBtn.addEventListener('click', (evt) => {
|
||||
let modal = closeBtn.parentElement.parentElement;
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll("[for-modal]").forEach((modalTrigerEl) => {
|
||||
modalTrigerEl.addEventListener('click', (evt) => {
|
||||
let modal = document.getElementById(modalTrigerEl.getAttribute("for-modal"));
|
||||
modal.classList.add("visible");
|
||||
modal.setAttribute("active", "");
|
||||
document.body.classList.add("modal-no-scroll");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
document.body.addEventListener('keydown', (evt) => {
|
||||
if (evt.key == "Escape") {
|
||||
let modal = document.querySelector(".modal[active]");
|
||||
modal.classList.remove("visible");
|
||||
modal.removeAttribute("active");
|
||||
document.body.classList.remove("modal-no-scroll");
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue