isosilo/static/js/modal.js

72 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2026-04-15 10:31:54 +02:00
// Modal functionality for ISO info popups
document.addEventListener("DOMContentLoaded", function () {
2026-04-15 12:22:43 +02:00
// Get modal elements
const modal = document.getElementById("isoModal");
const modalContent = document.getElementById("modalContent");
const closeBtn = document.querySelector(".close-btn");
const modalOverlay = document.querySelector(".modal-overlay");
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
// Function to open modal with ISO info
function openModal(title, description, imageSrc) {
document.getElementById("modalTitle").textContent = title;
document.getElementById("modalDescription").textContent = description ||
"No description available";
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
const modalImage = document.getElementById("modalImage");
if (imageSrc) {
modalImage.src = imageSrc;
modalImage.style.display = "block";
} else {
modalImage.style.display = "none";
}
modal.classList.add("visible");
document.body.style.overflow = "hidden";
2026-04-15 10:31:54 +02:00
}
2026-04-15 12:22:43 +02:00
// Function to close modal
function closeModal() {
modal.classList.remove("visible");
document.body.style.overflow = "";
}
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
// Event listeners for close button and overlay
if (closeBtn) {
closeBtn.addEventListener("click", closeModal);
}
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
if (modalOverlay) {
modalOverlay.addEventListener("click", function (e) {
if (e.target === modalOverlay) {
closeModal();
}
});
}
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
// Close modal when Escape key is pressed
document.addEventListener("keydown", function (e) {
// Change: Check for the "visible" class instead of style.display
if (e.key === "Escape" && modal.classList.contains("visible")) {
closeModal();
}
2026-04-15 10:31:54 +02:00
});
2026-04-15 12:22:43 +02:00
// Add click handlers to all ISO info buttons
// Change: Use the new ".info-trigger" class you added to the HTML
const infoButtons = document.querySelectorAll(".info-trigger");
infoButtons.forEach((button) => {
button.addEventListener("click", function (e) {
e.preventDefault();
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
const isoName = this.getAttribute("data-iso-name");
const description = this.getAttribute("data-description");
const imageSrc = this.getAttribute("data-image-src");
2026-04-15 10:31:54 +02:00
2026-04-15 12:22:43 +02:00
openModal(isoName, description, imageSrc);
});
2026-04-15 10:31:54 +02:00
});
2026-04-15 12:22:43 +02:00
// Expose functions to global scope for potential future use
window.openISOModal = openModal;
window.closeISOModal = closeModal;
2026-04-15 10:31:54 +02:00
});