From c2df1f4d3074f7397602f09e36ef8fe5d38724c4 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Tue, 17 Nov 2026 23:18:21 +0100 Subject: [PATCH] Side panels: pinned (the map moves over) or overlay (hides on mouse out), switched by a pin button in each panel header --- public/css/style.css | 30 ++++++++++++++++++++++ public/js/map.js | 3 ++- public/js/panels.js | 59 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/public/css/style.css b/public/css/style.css index 20edf9c..4e0a219 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -535,6 +535,36 @@ html, body { display: none; } +/* Pinned side panel: the map (and the profile panel under it) moves over + instead of being covered. Switching panels swaps the one in that spot. */ +body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) #map { + margin-left: min(300px, 90vw); +} + +body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .profile-panel { + left: calc(52px + min(300px, 90vw)); +} + +.side-panel-pin { + margin-left: auto; + margin-right: 4px; + padding: 2px; + border: none; + border-radius: 4px; + background: none; + color: #898781; + cursor: pointer; + display: inline-flex; +} + +.side-panel-pin:hover { + background: #f0f0f0; +} + +.side-panel-pin.active { + color: #1a5fb4; +} + .basemap-panel__header { display: flex; align-items: center; diff --git a/public/js/map.js b/public/js/map.js index ec9758c..59e5c7e 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -19,7 +19,7 @@ import { OfflineDataControl } from "/js/offline_data.js"; import { RoutePanelControl } from "/js/route.js"; import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON } from "/js/icons.js"; import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js"; -import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js"; +import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { DebugControl } from "/js/debug.js"; import { offerSharedFiles } from "/js/share_import.js"; @@ -593,6 +593,7 @@ gnssControl.mount(sidebar); new LiveTrackPanelControl(map).mount(sidebar); if (isLoggedIn()) new DebugControl().mount(sidebar); +setupSidePanelModes(); // The sidebar already has a "Base map" icon (opens the same panel) — // this is a second entry point for it, grouped with Home/zoom on the map diff --git a/public/js/panels.js b/public/js/panels.js index ed1609d..e995847 100644 --- a/public/js/panels.js +++ b/public/js/panels.js @@ -16,6 +16,65 @@ export function onlyOneSidePanelOpen(panel, onClosedByOther) { }); } +// Two ways a side panel sits next to the map, switched by the pin button +// every panel's header gets (remembered per browser): +// - pinned (default): stays open and the map shrinks beside it (CSS on +// body.side-pinned, see style.css; MapLibre resizes itself on that); +// - overlay: floats over the map and closes once the mouse has been in it +// and left — not while typing in one of its fields, and never on touch. +const PANELS = ".basemap-panel, .gpx-panel"; +const MODE_KEY = "sidePanelMode"; +const HIDE_DELAY_MS = 400; + +export function setupSidePanelModes() { + let pinned = true; + try { + pinned = localStorage.getItem(MODE_KEY) !== "overlay"; + } catch {} + const apply = () => { + document.body.classList.toggle("side-pinned", pinned); + document.querySelectorAll(".side-panel-pin").forEach((btn) => { + btn.classList.toggle("active", pinned); + btn.title = pinned ? "Pinned beside the map (click: float over it, hide on mouse out)" : "Floats over the map (click: pin beside it)"; + btn.setAttribute("aria-pressed", pinned); + }); + }; + + document.querySelectorAll(PANELS).forEach((panel) => { + const close = panel.querySelector(".basemap-panel__close, .gpx-panel__close"); + const pin = document.createElement("button"); + pin.type = "button"; + pin.className = "side-panel-pin"; + pin.setAttribute("aria-label", "Pin panel"); + pin.innerHTML = ``; + pin.addEventListener("click", () => { + pinned = !pinned; + try { + localStorage.setItem(MODE_KEY, pinned ? "pinned" : "overlay"); + } catch {} + apply(); + }); + close.before(pin); + + let entered = false; + let timer = null; + new MutationObserver(() => (entered = false)).observe(panel, { attributes: true, attributeFilter: ["hidden"] }); + panel.addEventListener("pointerenter", (event) => { + if (event.pointerType !== "mouse") return; + entered = true; + clearTimeout(timer); + }); + panel.addEventListener("pointerleave", (event) => { + if (pinned || !entered || event.pointerType !== "mouse") return; + timer = setTimeout(() => { + const typing = panel.contains(document.activeElement) && document.activeElement.matches("input:not([type=checkbox]):not([type=radio]), textarea, select"); + if (!pinned && !panel.hidden && !typing) close.click(); + }, HIDE_DELAY_MS); + }); + }); + apply(); +} + // Lets a control that writes into the GPX store (e.g. notes.js saving a // drawn point) tell GpxPanelControl its tree is stale, without either one // holding a reference to the other. path (the .geojson file just written