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
@@ -21,6 +21,18 @@ function e(?string $s): string
|
||||
return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* URL d'un asset local avec version (…?v=<date du fichier>) : chaque mise
|
||||
* à jour d'un CSS/JS est immédiatement re-téléchargée par les navigateurs,
|
||||
* au lieu d'être bloquée par le cache « 7 jours » du .htaccess.
|
||||
*/
|
||||
function fws_asset(string $path): string
|
||||
{
|
||||
$abs = FWS_SITE_ROOT . $path;
|
||||
$mtime = @filemtime($abs);
|
||||
return $mtime ? $path . '?v=' . $mtime : $path;
|
||||
}
|
||||
|
||||
/* fws_utf8_str / fws_utf8_arr sont définies dans api/bugs/db.php (chargé
|
||||
ci-dessous via fws_site_db()) avec des gardes function_exists : elles
|
||||
sont donc disponibles quel que soit l'ordre d'inclusion. */
|
||||
|
||||
+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 */
|
||||
}
|
||||
});
|
||||
})();
|
||||
+79
-12
@@ -401,7 +401,12 @@
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
/* Visionneuse plein écran */
|
||||
/* ── Popup central « aperçu de l'image » ── */
|
||||
|
||||
html.pkg-no-scroll {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pkg-lightbox {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
@@ -410,7 +415,9 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 2rem;
|
||||
background: rgba(2, 6, 23, 0.9);
|
||||
background: rgba(2, 6, 23, 0.55);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.pkg-lightbox.is-open {
|
||||
@@ -420,35 +427,59 @@
|
||||
.pkg-lightbox-figure {
|
||||
margin: 0;
|
||||
display: grid;
|
||||
gap: 0.6rem;
|
||||
max-width: min(1100px, 92vw);
|
||||
gap: 0.55rem;
|
||||
max-width: min(1000px, 90vw);
|
||||
animation: pkg-pop 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
|
||||
}
|
||||
|
||||
.pkg-lightbox-figure.is-animating {
|
||||
animation: pkg-pop 220ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
|
||||
}
|
||||
|
||||
@keyframes pkg-pop {
|
||||
from { opacity: 0; transform: scale(0.92); }
|
||||
to { opacity: 1; transform: scale(1); }
|
||||
}
|
||||
|
||||
.pkg-lightbox-img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
max-height: 82vh;
|
||||
max-height: 78vh;
|
||||
object-fit: contain;
|
||||
border-radius: 0.6rem;
|
||||
border-radius: 0.8rem;
|
||||
border: 1px solid var(--border);
|
||||
box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.pkg-lightbox-figcap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.pkg-lightbox-caption {
|
||||
color: #cbd5e1;
|
||||
color: #e2e8f0;
|
||||
font-size: 0.9rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pkg-lightbox-count {
|
||||
color: #94a3b8;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.pkg-lightbox-close {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1.2rem;
|
||||
width: 2.4rem;
|
||||
height: 2.4rem;
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border: 1px solid rgba(148, 163, 184, 0.4);
|
||||
border-radius: 999px;
|
||||
background: rgba(15, 23, 42, 0.7);
|
||||
background: rgba(15, 23, 42, 0.75);
|
||||
color: #e2e8f0;
|
||||
font-size: 1.3rem;
|
||||
font-size: 1.4rem;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -457,6 +488,42 @@
|
||||
border-color: #e2e8f0;
|
||||
}
|
||||
|
||||
.pkg-lightbox-nav {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 2.8rem;
|
||||
height: 2.8rem;
|
||||
border: 1px solid rgba(148, 163, 184, 0.35);
|
||||
border-radius: 999px;
|
||||
background: rgba(15, 23, 42, 0.75);
|
||||
color: #e2e8f0;
|
||||
font-size: 1.6rem;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pkg-lightbox-prev { left: 1.2rem; }
|
||||
.pkg-lightbox-next { right: 1.2rem; }
|
||||
|
||||
.pkg-lightbox-nav:hover {
|
||||
border-color: #e2e8f0;
|
||||
background: rgba(30, 41, 59, 0.9);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.pkg-lightbox {
|
||||
padding: 1rem;
|
||||
}
|
||||
.pkg-lightbox-nav {
|
||||
top: auto;
|
||||
bottom: 1.2rem;
|
||||
transform: none;
|
||||
}
|
||||
.pkg-lightbox-prev { left: auto; right: 4.2rem; }
|
||||
.pkg-lightbox-next { right: 1.2rem; }
|
||||
}
|
||||
|
||||
.paquet-links {
|
||||
grid-column: 1 / -1;
|
||||
display: flex;
|
||||
|
||||
@@ -129,10 +129,10 @@ function fws_site_active(string $route, string $prefix): string
|
||||
<meta property="og:image" content="/p/assets/img/logo.png" />
|
||||
<meta property="og:locale" content="fr_FR" />
|
||||
|
||||
<link rel="stylesheet" href="/p/assets/styles/styles.css" />
|
||||
<link rel="stylesheet" href="/p/assets/styles/paquets.css" />
|
||||
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/styles.css')) ?>" />
|
||||
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/paquets.css')) ?>" />
|
||||
<?php foreach ($extraCss as $css): ?>
|
||||
<link rel="stylesheet" href="<?= e($css) ?>" />
|
||||
<link rel="stylesheet" href="<?= e(fws_asset($css)) ?>" />
|
||||
<?php endforeach; ?>
|
||||
<link rel="icon" type="image/png" href="/p/assets/img/logo.png" />
|
||||
|
||||
@@ -238,9 +238,9 @@ function fws_site_active(string $route, string $prefix): string
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="/p/assets/main-nav/nav.js"></script>
|
||||
<script src="<?= e(fws_asset('/p/assets/main-nav/nav.js')) ?>"></script>
|
||||
<?php foreach ($extraJs as $js): ?>
|
||||
<script src="<?= e($js) ?>"></script>
|
||||
<script src="<?= e(fws_asset($js)) ?>"></script>
|
||||
<?php endforeach; ?>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in new issue
Block a user