mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-11 12:58:04 +02:00
35 lines
962 B
TypeScript
35 lines
962 B
TypeScript
|
const Modal = (): void => {
|
||
|
const modalTriggerElements: NodeListOf<HTMLElement> = document.querySelectorAll(
|
||
|
"[data-modal-target]"
|
||
|
);
|
||
|
|
||
|
for (let i = 0; i < modalTriggerElements.length; i++) {
|
||
|
const modalTrigger = modalTriggerElements[i];
|
||
|
|
||
|
if (modalTrigger.dataset.modalTarget) {
|
||
|
const modal: HTMLElement | null = document.getElementById(
|
||
|
modalTrigger.dataset.modalTarget
|
||
|
);
|
||
|
|
||
|
if (modal) {
|
||
|
modalTrigger.addEventListener("click", () => {
|
||
|
modal.classList.toggle("hidden");
|
||
|
});
|
||
|
|
||
|
const closeButtonsElements: NodeListOf<HTMLElement> = modal.querySelectorAll(
|
||
|
"[data-modal-button]"
|
||
|
);
|
||
|
|
||
|
for (let j = 0; j < closeButtonsElements.length; j++) {
|
||
|
const closeButton = closeButtonsElements[j];
|
||
|
closeButton.addEventListener("click", () => {
|
||
|
modal.classList.toggle("hidden");
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export default Modal;
|