34 lines
815 B
JavaScript

import { getCookie, setCookie } from "./cookie.js"
/*
* Newsletter modal
*/
// Get the modal
const modal = document.querySelector(".modal-menu");
const showBtn = document.querySelector(".show-modal");
// Get the <span> element that closes the modal
const closeBtn = document.querySelector(".close-modal");
const oneDay = 1 * 24 * 60 * 60 * 1000
// When the user clicks on <span> (x), close the modal
closeBtn.addEventListener("click", event => {
modal.style.display = "none";
setCookie('newsletter-modal', 'true', oneDay)
})
showBtn.addEventListener("click", event => {
modal.style.display = "flex";
})
// When the user clicks anywhere outside of the modal, close it
window.addEventListener("click", event => {
if (event.target == modal) {
modal.style.display = "none";
}
});