Template
Fix(paquets): popup central pour l'aperçu des images + cache des assets versionné
- La visionneuse devient un vrai popup centré : fond assombri et flouté, carte animée à l'apparition, croix de fermeture, flèches précédent / suivant, compteur « 2 / 5 » et navigation au clavier (Échap, flèches gauche/droite). Clic sur le fond = fermeture, clic sur l'image = rien (fini les fermetures intempestives). - Un seul gestionnaire d'événements délégué remplace les multiples listeners : plus de doubles déclenchements ni d'états incohérents. - styles.css, paquets.css, nav.js et les scripts de page sont servis avec ?v=<date du fichier> : chaque mise à jour est immédiatement prise en compte par les navigateurs au lieu de rester bloquée 7 jours par le cache du .htaccess (cause des rendus mélangés observés).
This commit is contained in:
1 parent
f8066c89fc
commit
3b3127bb34
4 files changed
+205
-72
No files matched your search
+109
-55
@@ -1,68 +1,122 @@
|
||||
(() => {
|
||||
/* ── « Voir plus » de l'historique (pages liste des paquets) ── */
|
||||
document.querySelectorAll("[data-toggle-timeline]").forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const timeline = btn.closest(".paquet-changelog")?.querySelector("[data-expandable]");
|
||||
if (!timeline) return;
|
||||
const expanded = btn.dataset.expanded === "true";
|
||||
timeline.classList.toggle("is-expanded", !expanded);
|
||||
btn.dataset.expanded = expanded ? "false" : "true";
|
||||
btn.textContent = expanded
|
||||
? btn.dataset.label || "Voir plus"
|
||||
: "Voir moins";
|
||||
/* Une seule exécution, même si le script est chargé deux fois. */
|
||||
if (window.__fwsPackagesUi) return;
|
||||
window.__fwsPackagesUi = true;
|
||||
|
||||
/* ── « Voir plus » de l'historique (liste des paquets) ── */
|
||||
document.addEventListener("click", (ev) => {
|
||||
const btn = ev.target.closest("[data-toggle-timeline]");
|
||||
if (!btn) return;
|
||||
const timeline = btn.closest(".paquet-changelog")?.querySelector("[data-expandable]");
|
||||
if (!timeline) return;
|
||||
const expanded = btn.dataset.expanded === "true";
|
||||
timeline.classList.toggle("is-expanded", !expanded);
|
||||
btn.dataset.expanded = expanded ? "false" : "true";
|
||||
btn.textContent = expanded ? (btn.dataset.label || "Voir plus") : "Voir moins";
|
||||
});
|
||||
|
||||
/* ── Popup central « aperçu de l'image » (page détail) ── */
|
||||
const zoomables = Array.from(document.querySelectorAll("img[data-zoom]"));
|
||||
if (zoomables.length === 0) return;
|
||||
|
||||
let overlay = null;
|
||||
let imgEl = null;
|
||||
let capEl = null;
|
||||
let countEl = null;
|
||||
let current = 0;
|
||||
|
||||
function buildOverlay() {
|
||||
if (overlay) return;
|
||||
overlay = document.createElement("div");
|
||||
overlay.className = "pkg-lightbox";
|
||||
overlay.setAttribute("role", "dialog");
|
||||
overlay.setAttribute("aria-modal", "true");
|
||||
overlay.setAttribute("aria-label", "Aperçu de l'image");
|
||||
overlay.innerHTML =
|
||||
'<button type="button" class="pkg-lightbox-close" data-lightbox-close aria-label="Fermer">×</button>' +
|
||||
'<button type="button" class="pkg-lightbox-nav pkg-lightbox-prev" data-lightbox-prev aria-label="Image précédente">‹</button>' +
|
||||
'<figure class="pkg-lightbox-figure">' +
|
||||
'<img class="pkg-lightbox-img" alt="">' +
|
||||
'<figcaption class="pkg-lightbox-figcap">' +
|
||||
'<span class="pkg-lightbox-caption"></span>' +
|
||||
'<span class="pkg-lightbox-count"></span>' +
|
||||
"</figcaption>" +
|
||||
"</figure>" +
|
||||
'<button type="button" class="pkg-lightbox-nav pkg-lightbox-next" data-lightbox-next aria-label="Image suivante">›</button>';
|
||||
document.body.appendChild(overlay);
|
||||
|
||||
imgEl = overlay.querySelector(".pkg-lightbox-img");
|
||||
capEl = overlay.querySelector(".pkg-lightbox-caption");
|
||||
countEl = overlay.querySelector(".pkg-lightbox-count");
|
||||
|
||||
/* Navigation clavier pendant que le popup est ouvert. */
|
||||
document.addEventListener("keydown", (ev) => {
|
||||
if (!overlay.classList.contains("is-open")) return;
|
||||
if (ev.key === "Escape") {
|
||||
ev.preventDefault();
|
||||
closeOverlay();
|
||||
} else if (ev.key === "ArrowLeft" && zoomables.length > 1) {
|
||||
showImage(current - 1);
|
||||
} else if (ev.key === "ArrowRight" && zoomables.length > 1) {
|
||||
showImage(current + 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Visionneuse : clic sur une image du paquet → plein écran ── */
|
||||
const zoomImgs = document.querySelectorAll("img[data-zoom]");
|
||||
if (zoomImgs.length === 0) return;
|
||||
|
||||
const overlay = document.createElement("div");
|
||||
overlay.className = "pkg-lightbox";
|
||||
overlay.innerHTML =
|
||||
'<button type="button" class="pkg-lightbox-close" aria-label="Fermer">×</button>' +
|
||||
'<figure class="pkg-lightbox-figure">' +
|
||||
'<img class="pkg-lightbox-img" src="" alt="">' +
|
||||
'<figcaption class="pkg-lightbox-caption"></figcaption>' +
|
||||
"</figure>";
|
||||
|
||||
const imgEl = overlay.querySelector(".pkg-lightbox-img");
|
||||
const capEl = overlay.querySelector(".pkg-lightbox-caption");
|
||||
|
||||
let lastFocus = null;
|
||||
|
||||
function open(src, alt, caption) {
|
||||
lastFocus = document.activeElement;
|
||||
imgEl.src = src;
|
||||
imgEl.alt = alt || "";
|
||||
capEl.textContent = caption || "";
|
||||
function showImage(index) {
|
||||
current = (index + zoomables.length) % zoomables.length;
|
||||
const src = zoomables[current];
|
||||
imgEl.src = src.currentSrc || src.src;
|
||||
imgEl.alt = src.alt || "";
|
||||
const caption = src.dataset.caption || "";
|
||||
capEl.textContent = caption;
|
||||
capEl.style.display = caption ? "" : "none";
|
||||
countEl.textContent = (current + 1) + " / " + zoomables.length;
|
||||
countEl.style.display = zoomables.length > 1 ? "" : "none";
|
||||
|
||||
/* Relance l'animation d'apparition à chaque changement d'image. */
|
||||
const figure = overlay.querySelector(".pkg-lightbox-figure");
|
||||
figure.classList.remove("is-animating");
|
||||
void figure.offsetWidth; /* reflow : réinitialise l'animation CSS */
|
||||
figure.classList.add("is-animating");
|
||||
}
|
||||
|
||||
function openOverlay(index) {
|
||||
buildOverlay();
|
||||
showImage(index);
|
||||
overlay.classList.add("is-open");
|
||||
document.documentElement.style.overflow = "hidden";
|
||||
overlay.querySelector(".pkg-lightbox-close").focus();
|
||||
document.documentElement.classList.add("pkg-no-scroll");
|
||||
}
|
||||
|
||||
function close() {
|
||||
function closeOverlay() {
|
||||
if (!overlay) return;
|
||||
overlay.classList.remove("is-open");
|
||||
document.documentElement.style.overflow = "";
|
||||
imgEl.src = "";
|
||||
if (lastFocus && typeof lastFocus.focus === "function") lastFocus.focus();
|
||||
document.documentElement.classList.remove("pkg-no-scroll");
|
||||
}
|
||||
|
||||
zoomImgs.forEach((img) => {
|
||||
img.classList.add("zoomable");
|
||||
img.addEventListener("click", () => open(img.src, img.alt, img.dataset.caption));
|
||||
/* Un titre alternatif si aucune légende n'est renseignée. */
|
||||
if (!img.dataset.caption && img.alt) img.dataset.caption = img.alt;
|
||||
});
|
||||
/* Un seul gestionnaire délégué : clic sur une image → ouverture ;
|
||||
clic sur croix / flèches / fond → action correspondante. */
|
||||
document.addEventListener("click", (ev) => {
|
||||
const zoom = ev.target.closest("img[data-zoom]");
|
||||
if (zoom) {
|
||||
const idx = zoomables.indexOf(zoom);
|
||||
if (idx >= 0) {
|
||||
ev.preventDefault();
|
||||
openOverlay(idx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
overlay.addEventListener("click", (ev) => {
|
||||
if (ev.target === overlay || ev.target.closest(".pkg-lightbox-figure") === null) close();
|
||||
});
|
||||
overlay.querySelector(".pkg-lightbox-close").addEventListener("click", close);
|
||||
document.addEventListener("keydown", (ev) => {
|
||||
if (ev.key === "Escape" && overlay.classList.contains("is-open")) close();
|
||||
});
|
||||
if (!overlay || !overlay.classList.contains("is-open")) return;
|
||||
|
||||
document.body.appendChild(overlay);
|
||||
if (ev.target.closest("[data-lightbox-close]")) {
|
||||
closeOverlay();
|
||||
} else if (ev.target.closest("[data-lightbox-prev]")) {
|
||||
showImage(current - 1);
|
||||
} else if (ev.target.closest("[data-lightbox-next]")) {
|
||||
showImage(current + 1);
|
||||
} else if (ev.target === overlay) {
|
||||
closeOverlay(); /* clic sur le fond uniquement, pas sur l'image */
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user