From 49acbd10ae1376ca0848d558a346fe80167b870f Mon Sep 17 00:00:00 2001 From: Freeplay Date: Wed, 17 May 2023 12:34:45 -0400 Subject: [PATCH] Close modals on browser back --- packages/client/src/components/MkMediaList.vue | 16 ++++++++++++++++ packages/client/src/components/MkModal.vue | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/MkMediaList.vue b/packages/client/src/components/MkMediaList.vue index 0b4ed9dac..6ee427388 100644 --- a/packages/client/src/components/MkMediaList.vue +++ b/packages/client/src/components/MkMediaList.vue @@ -108,6 +108,7 @@ onMounted(() => { }, imageClickAction: "close", tapAction: "toggle-controls", + preloadFirstSlide: false, pswpModule: PhotoSwipe, }); @@ -162,7 +163,22 @@ onMounted(() => { }); }); + lightbox.on("afterInit", () => { + history.pushState(null, "", location.href); + addEventListener("popstate", close); + }) + lightbox.on("close", () => { + removeEventListener("popstate", close); + history.back(); + }) + lightbox.init(); + + function close() { + removeEventListener("popstate", close); + history.forward(); + lightbox.pswp.close(); + } }); const previewable = (file: misskey.entities.DriveFile): boolean => { diff --git a/packages/client/src/components/MkModal.vue b/packages/client/src/components/MkModal.vue index 0a07f57e0..287fb1d8c 100644 --- a/packages/client/src/components/MkModal.vue +++ b/packages/client/src/components/MkModal.vue @@ -74,7 +74,7 @@