JuiceUI/Libraries/js/themekit/modal.js
2020-03-02 23:22:36 -05:00

37 lines
1.3 KiB
JavaScript

$(document).ready(() => {
// Close when clicking on *not* the modal-contents
window.onclick = (event) => {
if (event.target.classList.contains("modal")) {
$(event.target).hide("fade", {
direction: "out",
}, 300);
document.body.classList.remove("no-scroll");
}
};
document.querySelectorAll(".modal .close").forEach((closeBtn) => {
closeBtn.addEventListener('click', (evt) => {
$(closeBtn.parentElement.parentElement).hide("fade", {
direction: "out",
}, 300);
document.body.classList.remove("no-scroll");
});
});
document.querySelectorAll("[for-modal]").forEach((modalTrigerEl) => {
modalTrigerEl.addEventListener('click', (evt) => {
// document.getElementById(modalTrigerEl.getAttribute("for-modal")).style.display = "flex";
$(`#${modalTrigerEl.getAttribute("for-modal")}`).show("fade", {
direction: "in",
}, 300);
document.body.classList.add("no-scroll");
});
});
});
$(document).ready(() => {
document.querySelectorAll("[for-modal]").forEach((modalTrigerEl) => {
$(`#${modalTrigerEl.getAttribute("for-modal")}`).hide();
});
});