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
+204
-71
No files matched your search
@@ -21,6 +21,18 @@ function e(?string $s): string
|
|||||||
return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8');
|
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é
|
/* 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
|
ci-dessous via fws_site_db()) avec des gardes function_exists : elles
|
||||||
sont donc disponibles quel que soit l'ordre d'inclusion. */
|
sont donc disponibles quel que soit l'ordre d'inclusion. */
|
||||||
|
|||||||
+108
-54
@@ -1,68 +1,122 @@
|
|||||||
(() => {
|
(() => {
|
||||||
/* ── « Voir plus » de l'historique (pages liste des paquets) ── */
|
/* Une seule exécution, même si le script est chargé deux fois. */
|
||||||
document.querySelectorAll("[data-toggle-timeline]").forEach((btn) => {
|
if (window.__fwsPackagesUi) return;
|
||||||
btn.addEventListener("click", () => {
|
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]");
|
const timeline = btn.closest(".paquet-changelog")?.querySelector("[data-expandable]");
|
||||||
if (!timeline) return;
|
if (!timeline) return;
|
||||||
const expanded = btn.dataset.expanded === "true";
|
const expanded = btn.dataset.expanded === "true";
|
||||||
timeline.classList.toggle("is-expanded", !expanded);
|
timeline.classList.toggle("is-expanded", !expanded);
|
||||||
btn.dataset.expanded = expanded ? "false" : "true";
|
btn.dataset.expanded = expanded ? "false" : "true";
|
||||||
btn.textContent = expanded
|
btn.textContent = expanded ? (btn.dataset.label || "Voir plus") : "Voir moins";
|
||||||
? btn.dataset.label || "Voir plus"
|
|
||||||
: "Voir moins";
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* ── Visionneuse : clic sur une image du paquet → plein écran ── */
|
/* ── Popup central « aperçu de l'image » (page détail) ── */
|
||||||
const zoomImgs = document.querySelectorAll("img[data-zoom]");
|
const zoomables = Array.from(document.querySelectorAll("img[data-zoom]"));
|
||||||
if (zoomImgs.length === 0) return;
|
if (zoomables.length === 0) return;
|
||||||
|
|
||||||
const overlay = document.createElement("div");
|
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.className = "pkg-lightbox";
|
||||||
|
overlay.setAttribute("role", "dialog");
|
||||||
|
overlay.setAttribute("aria-modal", "true");
|
||||||
|
overlay.setAttribute("aria-label", "Aperçu de l'image");
|
||||||
overlay.innerHTML =
|
overlay.innerHTML =
|
||||||
'<button type="button" class="pkg-lightbox-close" aria-label="Fermer">×</button>' +
|
'<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">' +
|
'<figure class="pkg-lightbox-figure">' +
|
||||||
'<img class="pkg-lightbox-img" src="" alt="">' +
|
'<img class="pkg-lightbox-img" alt="">' +
|
||||||
'<figcaption class="pkg-lightbox-caption"></figcaption>' +
|
'<figcaption class="pkg-lightbox-figcap">' +
|
||||||
"</figure>";
|
'<span class="pkg-lightbox-caption"></span>' +
|
||||||
|
'<span class="pkg-lightbox-count"></span>' +
|
||||||
const imgEl = overlay.querySelector(".pkg-lightbox-img");
|
"</figcaption>" +
|
||||||
const capEl = overlay.querySelector(".pkg-lightbox-caption");
|
"</figure>" +
|
||||||
|
'<button type="button" class="pkg-lightbox-nav pkg-lightbox-next" data-lightbox-next aria-label="Image suivante">›</button>';
|
||||||
let lastFocus = null;
|
|
||||||
|
|
||||||
function open(src, alt, caption) {
|
|
||||||
lastFocus = document.activeElement;
|
|
||||||
imgEl.src = src;
|
|
||||||
imgEl.alt = alt || "";
|
|
||||||
capEl.textContent = caption || "";
|
|
||||||
capEl.style.display = caption ? "" : "none";
|
|
||||||
overlay.classList.add("is-open");
|
|
||||||
document.documentElement.style.overflow = "hidden";
|
|
||||||
overlay.querySelector(".pkg-lightbox-close").focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
overlay.classList.remove("is-open");
|
|
||||||
document.documentElement.style.overflow = "";
|
|
||||||
imgEl.src = "";
|
|
||||||
if (lastFocus && typeof lastFocus.focus === "function") lastFocus.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.body.appendChild(overlay);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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.classList.add("pkg-no-scroll");
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeOverlay() {
|
||||||
|
if (!overlay) return;
|
||||||
|
overlay.classList.remove("is-open");
|
||||||
|
document.documentElement.classList.remove("pkg-no-scroll");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!overlay || !overlay.classList.contains("is-open")) return;
|
||||||
|
|
||||||
|
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;
|
font-size: 0.72rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Visionneuse plein écran */
|
/* ── Popup central « aperçu de l'image » ── */
|
||||||
|
|
||||||
|
html.pkg-no-scroll {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.pkg-lightbox {
|
.pkg-lightbox {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@@ -410,7 +415,9 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 2rem;
|
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 {
|
.pkg-lightbox.is-open {
|
||||||
@@ -420,35 +427,59 @@
|
|||||||
.pkg-lightbox-figure {
|
.pkg-lightbox-figure {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.6rem;
|
gap: 0.55rem;
|
||||||
max-width: min(1100px, 92vw);
|
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 {
|
.pkg-lightbox-img {
|
||||||
|
display: block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 82vh;
|
max-height: 78vh;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
border-radius: 0.6rem;
|
border-radius: 0.8rem;
|
||||||
border: 1px solid var(--border);
|
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 {
|
.pkg-lightbox-caption {
|
||||||
color: #cbd5e1;
|
color: #e2e8f0;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
text-align: center;
|
}
|
||||||
|
|
||||||
|
.pkg-lightbox-count {
|
||||||
|
color: #94a3b8;
|
||||||
|
font-size: 0.78rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pkg-lightbox-close {
|
.pkg-lightbox-close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 1rem;
|
top: 1rem;
|
||||||
right: 1.2rem;
|
right: 1.2rem;
|
||||||
width: 2.4rem;
|
width: 2.5rem;
|
||||||
height: 2.4rem;
|
height: 2.5rem;
|
||||||
border: 1px solid rgba(148, 163, 184, 0.4);
|
border: 1px solid rgba(148, 163, 184, 0.4);
|
||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
background: rgba(15, 23, 42, 0.7);
|
background: rgba(15, 23, 42, 0.75);
|
||||||
color: #e2e8f0;
|
color: #e2e8f0;
|
||||||
font-size: 1.3rem;
|
font-size: 1.4rem;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@@ -457,6 +488,42 @@
|
|||||||
border-color: #e2e8f0;
|
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 {
|
.paquet-links {
|
||||||
grid-column: 1 / -1;
|
grid-column: 1 / -1;
|
||||||
display: flex;
|
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:image" content="/p/assets/img/logo.png" />
|
||||||
<meta property="og:locale" content="fr_FR" />
|
<meta property="og:locale" content="fr_FR" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="/p/assets/styles/styles.css" />
|
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/styles.css')) ?>" />
|
||||||
<link rel="stylesheet" href="/p/assets/styles/paquets.css" />
|
<link rel="stylesheet" href="<?= e(fws_asset('/p/assets/styles/paquets.css')) ?>" />
|
||||||
<?php foreach ($extraCss as $css): ?>
|
<?php foreach ($extraCss as $css): ?>
|
||||||
<link rel="stylesheet" href="<?= e($css) ?>" />
|
<link rel="stylesheet" href="<?= e(fws_asset($css)) ?>" />
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<link rel="icon" type="image/png" href="/p/assets/img/logo.png" />
|
<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>
|
</footer>
|
||||||
</div>
|
</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): ?>
|
<?php foreach ($extraJs as $js): ?>
|
||||||
<script src="<?= e($js) ?>"></script>
|
<script src="<?= e(fws_asset($js)) ?>"></script>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user