Side panels: pinned (the map moves over) or overlay (hides on mouse out), switched by a pin button in each panel header
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-17 23:18:21 +01:00
1 parent 066e831219
commit c2df1f4d30
3 files changed
+91 -1

No files matched your search

+59
View File
@@ -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 = `<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17v5M9 3h6l-1 6 3 3v2H7v-2l3-3z"/></svg>`;
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