From 631b4871633d26cedeb205820c037cd12659df51 Mon Sep 17 00:00:00 2001 From: djmaze Date: Fri, 10 Sep 2021 10:25:58 +0200 Subject: [PATCH] Bugfix: close popups on browser back/forward hash change --- dev/Knoin/Knoin.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index 4ecb60555..5842abe71 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -4,7 +4,7 @@ import { doc, $htmlCL } from 'Common/Globals'; import { arrayLength, isFunction } from 'Common/Utils'; let currentScreen = null, - popupsVisible = 0, + visiblePopups = new Set, defaultScreenName = ''; const SCREENS = {}, @@ -61,7 +61,7 @@ const SCREENS = {}, vm.modalVisibility.subscribe(value => { if (value) { - ++popupsVisible; + visiblePopups.add(vm); vmDom.style.zIndex = 3000 + popupVisibilityNames().length + 10; vmDom.hidden = false; vm.storeAndSetScope(); @@ -71,7 +71,7 @@ const SCREENS = {}, vmDom.classList.add('show'); // trigger the transitions }); } else { - popupsVisible = Math.max(0, popupsVisible-1); + visiblePopups.delete(vm); vm.onHide && vm.onHide(); vmDom.classList.remove('show'); vm.restoreScope(); @@ -123,6 +123,11 @@ const SCREENS = {}, screenName = defaultScreenName; } + // Close all popups + for (let vm of visiblePopups) { + vm.closeCommand(); + } + if (screenName) { vmScreen = screen(screenName); if (!vmScreen) { @@ -271,7 +276,7 @@ export const } }, - arePopupsVisible = () => 0 < popupsVisible, + arePopupsVisible = () => 0 < visiblePopups.size, /** * @param {Function} ViewModelClassToShow