From e6acffb9ba784fc9eddae1e6ca1f74e59f01d24f Mon Sep 17 00:00:00 2001 From: Fabio Date: Thu, 26 Feb 2026 13:59:36 +0100 Subject: [PATCH] 4th --- public/css/bottomSheet.css | 2 +- public/js/main.js | 73 +++++++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/public/css/bottomSheet.css b/public/css/bottomSheet.css index 0424e26..bcf21cf 100644 --- a/public/css/bottomSheet.css +++ b/public/css/bottomSheet.css @@ -171,7 +171,7 @@ inset: 0; background: rgba(0,0,0,0.0); /* invisibile ma cliccabile */ display: none; - z-index: 9998; /* appena sotto il bottom sheet */ + z-index: 80; /* appena sotto il bottom sheet */ } .sheet-overlay.open { diff --git a/public/js/main.js b/public/js/main.js index d05c856..df3e91d 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -42,7 +42,7 @@ console.log("main.js avviato"); // Aspetta un tick così il layout è aggiornato setTimeout(() => { try { - // Sostituisci con la tua variabile dell'istanza L.map, se diversa + // In mapGlobal.js imposta: window.leafletMapInstance = window.globalMap; window.leafletMapInstance?.invalidateSize(); } catch (e) { console.warn('invalidateSize non eseguito:', e); @@ -64,6 +64,63 @@ console.log("main.js avviato"); }); })(); +// =============================== +// MENU ⋮ (toggle apri/chiudi con lo stesso bottone, senza global conflicts) +// =============================== +(() => { + const optBtn = document.getElementById("optionsBtn"); + const optSheet = document.getElementById("optionsSheet"); + const overlayEl= document.getElementById("sheetOverlay"); + + if (!optBtn || !optSheet) return; + + function openOptionsSheet() { + try { window.closeBottomSheet?.(); } catch {} + optSheet.classList.add("open"); + overlayEl?.classList.add("open"); + // ARIA (facoltativo) + optBtn.setAttribute("aria-expanded", "true"); + optSheet.setAttribute("aria-hidden", "false"); + } + + function closeOptionsSheet() { + optSheet.classList.remove("open"); + overlayEl?.classList.remove("open"); + // ARIA (facoltativo) + optBtn.setAttribute("aria-expanded", "false"); + optSheet.setAttribute("aria-hidden", "true"); + } + + function toggleOptionsSheet(e) { + e?.preventDefault(); + e?.stopPropagation(); + if (optSheet.classList.contains("open")) closeOptionsSheet(); + else openOptionsSheet(); + } + + // Click sul bottone: toggle (fase di cattura per battere eventuali altri handler) + optBtn.addEventListener("click", toggleOptionsSheet, { capture: true }); + + // Chiudi clic overlay + overlayEl?.addEventListener("click", (e) => { + e.stopPropagation(); + closeOptionsSheet(); + }); + + // Chiudi con ESC + document.addEventListener("keydown", (e) => { + if (e.key === "Escape" && optSheet.classList.contains("open")) { + closeOptionsSheet(); + } + }); + + // Evita chiusure involontarie per click interni + optSheet.addEventListener("click", (e) => e.stopPropagation()); + + // Espone una close per usarla altrove (es. dopo la scelta) + window.closeOptionsSheet = closeOptionsSheet; +})(); + // =============================== // LOGIN AUTOMATICO SU INDEX // =============================== @@ -116,16 +173,6 @@ window.currentSort = currentSort; window.currentGroup = currentGroup; window.currentFilter = currentFilter; -// =============================== -// MENU ⋮ -// =============================== -const optionsBtn = document.getElementById("optionsBtn"); -const optionsSheetEl = document.getElementById("optionsSheet"); - -optionsBtn?.addEventListener("click", () => { - optionsSheetEl?.classList.add("open"); -}); - // =============================== // BOTTONI OPZIONI // =============================== @@ -135,7 +182,9 @@ document.querySelectorAll("#optionsSheet .sheet-btn").forEach(btn => { if (btn.dataset.group) window.currentGroup = currentGroup = btn.dataset.group; if (btn.dataset.filter) window.currentFilter = currentFilter = btn.dataset.filter; - optionsSheetEl?.classList.remove("open"); + // Chiudi sheet e overlay dopo la scelta (usa l’API esposta sopra) + window.closeOptionsSheet?.(); + refreshGallery(); }); });