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;
|
const ov = map?.__swCenteredOverlay;
|
||||||
if (!ov) return;
|
if (!ov) return;
|
||||||
if (ov.closing) return;
|
if (ov.closing) return;
|
||||||
|
ov.closing = true;
|
||||||
|
|
||||||
if (ov.onKey) window.removeEventListener("keydown", ov.onKey);
|
if (ov.onKey) window.removeEventListener("keydown", ov.onKey);
|
||||||
if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth);
|
if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth);
|
||||||
|
if (ov.onPop) window.removeEventListener("popstate", ov.onPop);
|
||||||
|
|
||||||
// animate out
|
// animate out
|
||||||
try {
|
try {
|
||||||
|
|
@ -349,6 +351,11 @@ function closeCenteredOverlay(map) {
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
map.__swCenteredOverlay = null;
|
map.__swCenteredOverlay = null;
|
||||||
|
|
||||||
|
if (ov.historyPushed && !ov.historyClosed) {
|
||||||
|
ov.historyClosed = true;
|
||||||
|
try { window.history.back(); } catch {}
|
||||||
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,6 +523,24 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) {
|
||||||
};
|
};
|
||||||
window.addEventListener("keydown", onKey);
|
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
|
// CTA open url
|
||||||
const cta = modalWrap.querySelector(".sw-cta-primary");
|
const cta = modalWrap.querySelector(".sw-cta-primary");
|
||||||
if (cta) {
|
if (cta) {
|
||||||
|
|
@ -677,9 +702,12 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) {
|
||||||
modalWrapRef: modalWrap,
|
modalWrapRef: modalWrap,
|
||||||
backdrop,
|
backdrop,
|
||||||
onKey,
|
onKey,
|
||||||
|
onPop,
|
||||||
onAuth,
|
onAuth,
|
||||||
unmountFull,
|
unmountFull,
|
||||||
unmountMini: null,
|
unmountMini: null,
|
||||||
|
historyPushed,
|
||||||
|
historyClosed: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue