mirror of
https://github.com/Anvilcraft/jensmemes
synced 2024-11-14 14:01:55 +01:00
37 lines
952 B
JavaScript
37 lines
952 B
JavaScript
|
const openModalButtons = document.querySelectorAll('[data-modal-target]')
|
||
|
const closeModalButtons = document.querySelectorAll('[data-close-button]')
|
||
|
const overlay = document.getElementById('overlay')
|
||
|
|
||
|
openModalButtons.forEach(button => {
|
||
|
button.addEventListener('click', () => {
|
||
|
const modal = document.querySelector(button.dataset.modalTarget)
|
||
|
openModal(modal)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
overlay.addEventListener('click', () => {
|
||
|
const modals = document.querySelectorAll('.modal.active')
|
||
|
modals.forEach(modal => {
|
||
|
closeModal(modal)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
closeModalButtons.forEach(button => {
|
||
|
button.addEventListener('click', () => {
|
||
|
const modal = button.closest('.modal')
|
||
|
closeModal(modal)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
function openModal(modal) {
|
||
|
if (modal == null) return
|
||
|
modal.classList.add('active')
|
||
|
overlay.classList.add('active')
|
||
|
}
|
||
|
|
||
|
function closeModal(modal) {
|
||
|
if (modal == null) return
|
||
|
modal.classList.remove('active')
|
||
|
overlay.classList.remove('active')
|
||
|
}
|