Side panels: pinned (the map moves over) or overlay (hides on mouse out), switched by a pin button in each panel header
This commit is contained in:
1 parent
066e831219
commit
c2df1f4d30
3 files changed
+91
-1
No files matched your search
@@ -535,6 +535,36 @@ html, body {
|
|||||||
display: none;
|
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 {
|
.basemap-panel__header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
+2
-1
@@ -19,7 +19,7 @@ import { OfflineDataControl } from "/js/offline_data.js";
|
|||||||
import { RoutePanelControl } from "/js/route.js";
|
import { RoutePanelControl } from "/js/route.js";
|
||||||
import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON } from "/js/icons.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 { 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 { isLoggedIn } from "/js/auth.js";
|
||||||
import { DebugControl } from "/js/debug.js";
|
import { DebugControl } from "/js/debug.js";
|
||||||
import { offerSharedFiles } from "/js/share_import.js";
|
import { offerSharedFiles } from "/js/share_import.js";
|
||||||
@@ -593,6 +593,7 @@ gnssControl.mount(sidebar);
|
|||||||
new LiveTrackPanelControl(map).mount(sidebar);
|
new LiveTrackPanelControl(map).mount(sidebar);
|
||||||
|
|
||||||
if (isLoggedIn()) new DebugControl().mount(sidebar);
|
if (isLoggedIn()) new DebugControl().mount(sidebar);
|
||||||
|
setupSidePanelModes();
|
||||||
|
|
||||||
// The sidebar already has a "Base map" icon (opens the same panel) —
|
// 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
|
// this is a second entry point for it, grouped with Home/zoom on the map
|
||||||
|
|||||||
@@ -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
|
// 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
|
// drawn point) tell GpxPanelControl its tree is stale, without either one
|
||||||
// holding a reference to the other. path (the .geojson file just written
|
// holding a reference to the other. path (the .geojson file just written
|
||||||
|
|||||||
Reference in new issue
Block a user