From 87e0621ec4e53f7ab5107448d4fc0a968489fa72 Mon Sep 17 00:00:00 2001 From: Damir Modyarov Date: Mon, 29 Apr 2024 22:26:39 +0300 Subject: [PATCH] front: hook popups to browser's history api closes #410 --- src/front/cobalt.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/front/cobalt.js b/src/front/cobalt.js index 0fd638f2..6e82d4c5 100644 --- a/src/front/cobalt.js +++ b/src/front/cobalt.js @@ -245,6 +245,7 @@ const hideAllPopups = () => { const popup = (type, action, text) => { if (action === 1) { hideAllPopups(); // hide the previous popup before showing a new one + history.pushState(type, ""); store.isPopupOpen = true; switch (type) { case "about": @@ -306,6 +307,7 @@ const popup = (type, action, text) => { } } else { store.isPopupOpen = false; + history.back(); if (type === "picker") { eid("picker-download").href = '/'; eid("picker-download").classList.remove("visible"); @@ -651,6 +653,11 @@ document.onkeydown = (e) => { if (e.key === "M") popup('settings', 1); } else { - if (e.key === "Escape") hideAllPopups(); + if (e.key === "Escape") history.back(); } } +window.addEventListener("popstate", (e) => { + if (store.isPopupOpen) { + hideAllPopups(); + } +})