(function () {
'use strict';
function ensureLightbox() {
let box = document.getElementById('cep-image-lightbox');
if (box) return box;
box = document.createElement('div');
box.id = 'cep-image-lightbox';
box.className = 'cep-image-lightbox';
box.setAttribute('aria-hidden', 'true');
box.innerHTML =
'' +
'
';
document.body.appendChild(box);
return box;
}
function closeLightbox() {
const box = document.getElementById('cep-image-lightbox');
if (!box) return;
box.classList.remove('is-open');
box.setAttribute('aria-hidden', 'true');
document.body.classList.remove('cep-lightbox-open');
}
function openLightbox(src, alt) {
if (!src) return;
const box = ensureLightbox();
const img = box.querySelector('.cep-image-lightbox-img');
if (!img) return;
img.src = src;
img.alt = alt || 'Image agrandie';
box.classList.add('is-open');
box.setAttribute('aria-hidden', 'false');
document.body.classList.add('cep-lightbox-open');
const close = box.querySelector('.cep-image-lightbox-close');
if (close) close.focus();
}
document.addEventListener('click', function (event) {
const trigger = event.target.closest('[data-image-zoom]');
if (trigger) {
const src = trigger.getAttribute('data-full-image') || trigger.getAttribute('href') || trigger.getAttribute('src') || '';
const img = trigger.matches('img') ? trigger : trigger.querySelector('img');
const alt = img ? (img.getAttribute('alt') || '') : (trigger.getAttribute('aria-label') || '');
if (src) {
event.preventDefault();
openLightbox(src, alt);
}
return;
}
const close = event.target.closest('.cep-image-lightbox-close');
if (close) {
event.preventDefault();
closeLightbox();
return;
}
const box = event.target.closest('#cep-image-lightbox');
if (box && event.target === box) {
closeLightbox();
}
});
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape') closeLightbox();
});
})();