Close fullscreen modal on back
This commit is contained in:
parent
406d1f5886
commit
e1e5999617
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue