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