From e1e59996173e8d31ff8df7836107e8a9062c4059 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 25 Dec 2025 21:28:27 -0500 Subject: [PATCH] Close fullscreen modal on back --- src/components/Map/markerManager.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/Map/markerManager.js b/src/components/Map/markerManager.js index 74aa23e..ff3f530 100644 --- a/src/components/Map/markerManager.js +++ b/src/components/Map/markerManager.js @@ -328,9 +328,11 @@ function closeCenteredOverlay(map) { const ov = map?.__swCenteredOverlay; if (!ov) return; if (ov.closing) return; + ov.closing = true; if (ov.onKey) window.removeEventListener("keydown", ov.onKey); if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth); + if (ov.onPop) window.removeEventListener("popstate", ov.onPop); // animate out try { @@ -349,6 +351,11 @@ function closeCenteredOverlay(map) { } catch {} map.__swCenteredOverlay = null; + + if (ov.historyPushed && !ov.historyClosed) { + ov.historyClosed = true; + try { window.history.back(); } catch {} + } } catch {} } @@ -516,6 +523,24 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) { }; window.addEventListener("keydown", onKey); + let onPop = null; + let historyPushed = false; + if (fullScreen && postID) { + try { + const url = `/?post_id=${postID}`; + const state = window.history.state || {}; + if (!state || state.swModal !== true || state.postId !== postID) { + window.history.pushState({ ...state, swModal: true, postId: postID }, "", url); + historyPushed = true; + } + onPop = () => { + const ov = map.__swCenteredOverlay; + if (ov && ov.postId === postID) closeCenteredOverlay(map); + }; + window.addEventListener("popstate", onPop); + } catch {} + } + // CTA open url const cta = modalWrap.querySelector(".sw-cta-primary"); if (cta) { @@ -677,9 +702,12 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) { modalWrapRef: modalWrap, backdrop, onKey, + onPop, onAuth, unmountFull, unmountMini: null, + historyPushed, + historyClosed: false, }; }