From f2d172de7d3820b83721bf73aa3bbc83f9f5e07e Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 31 Aug 2021 16:17:20 +0200 Subject: [PATCH] Prevent unloading of browser window when popups (like composer window) are open. --- dev/App/User.js | 3 ++- dev/Knoin/Knoin.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dev/App/User.js b/dev/App/User.js index 8322b0ae4..9cdf59014 100644 --- a/dev/App/User.js +++ b/dev/App/User.js @@ -72,7 +72,7 @@ import { LoginUserScreen } from 'Screen/User/Login'; import { MailBoxUserScreen } from 'Screen/User/MailBox'; import { SettingsUserScreen } from 'Screen/User/Settings'; -import { startScreens, showScreenPopup } from 'Knoin/Knoin'; +import { startScreens, showScreenPopup, arePopupsVisible } from 'Knoin/Knoin'; import { AbstractApp } from 'App/Abstract'; @@ -851,6 +851,7 @@ class AppUser extends AbstractApp { super.bootstart(); addEventListener('resize', () => leftPanelDisabled(ThemeStore.isMobile() || 1000 > innerWidth)); + addEventListener('beforeunload', event => arePopupsVisible() && event.preventDefault() , {capture: true}); NotificationUserStore.populate(); AccountUserStore.populate(); diff --git a/dev/Knoin/Knoin.js b/dev/Knoin/Knoin.js index 36d0c6e81..e8f0ce45d 100644 --- a/dev/Knoin/Knoin.js +++ b/dev/Knoin/Knoin.js @@ -4,6 +4,7 @@ import { doc, $htmlCL } from 'Common/Globals'; import { arrayLength, isFunction } from 'Common/Utils'; let currentScreen = null, + popupsVisible = 0, defaultScreenName = ''; const SCREENS = {}, @@ -60,6 +61,7 @@ const SCREENS = {}, vm.modalVisibility.subscribe(value => { if (value) { + ++popupsVisible; vmDom.style.zIndex = 3000 + popupVisibilityNames().length + 10; vmDom.hidden = false; vm.storeAndSetScope(); @@ -69,6 +71,7 @@ const SCREENS = {}, vmDom.classList.add('show'); // trigger the transitions }); } else { + popupsVisible = Math.max(0, popupsVisible-1); vm.onHide && vm.onHide(); vmDom.classList.remove('show'); vm.restoreScope(); @@ -268,6 +271,8 @@ export const } }, + arePopupsVisible = () => 0 < popupsVisible, + /** * @param {Function} ViewModelClassToShow * @returns {boolean}