Fix back button closing modal
This commit is contained in:
parent
8adab752ff
commit
f6cda99b4c
|
|
@ -323,12 +323,13 @@ function normalizeImageUrl(raw) {
|
|||
return value;
|
||||
}
|
||||
|
||||
function closeCenteredOverlay(map) {
|
||||
function closeCenteredOverlay(map, opts = {}) {
|
||||
try {
|
||||
const ov = map?.__swCenteredOverlay;
|
||||
if (!ov) return;
|
||||
if (ov.closing) return;
|
||||
ov.closing = true;
|
||||
const skipHistory = !!opts.skipHistory;
|
||||
|
||||
if (ov.onKey) window.removeEventListener("keydown", ov.onKey);
|
||||
if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth);
|
||||
|
|
@ -352,7 +353,7 @@ function closeCenteredOverlay(map) {
|
|||
|
||||
map.__swCenteredOverlay = null;
|
||||
|
||||
if (ov.historyPushed && !ov.historyClosed) {
|
||||
if (!skipHistory && ov.historyPushed && !ov.historyClosed) {
|
||||
ov.historyClosed = true;
|
||||
try { window.history.back(); } catch {}
|
||||
}
|
||||
|
|
@ -535,7 +536,10 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) {
|
|||
}
|
||||
onPop = () => {
|
||||
const ov = map.__swCenteredOverlay;
|
||||
if (ov && ov.postId === postID) closeCenteredOverlay(map);
|
||||
if (ov && ov.postId === postID) {
|
||||
ov.historyClosed = true;
|
||||
closeCenteredOverlay(map, { skipHistory: true });
|
||||
}
|
||||
};
|
||||
window.addEventListener("popstate", onPop);
|
||||
} catch {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue