From 2ed3aced2f0ec24ef5950e085ff1b0b5cbf7d29f Mon Sep 17 00:00:00 2001 From: venkat_karasani Date: Sat, 13 Jul 2024 12:22:27 -0500 Subject: [PATCH] Prevent modal clos on mouse press up if outside the dialog --- src/components/dialogHelper/dialogHelper.js | 44 ++++++++++--------- .../metadataEditor/metadataEditor.js | 5 ++- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/components/dialogHelper/dialogHelper.js b/src/components/dialogHelper/dialogHelper.js index b03ff9052ce..99369a4a303 100644 --- a/src/components/dialogHelper/dialogHelper.js +++ b/src/components/dialogHelper/dialogHelper.js @@ -42,7 +42,7 @@ function tryRemoveElement(elem) { } } -function DialogHashHandler(dlg, hash, resolve) { +function DialogHashHandler(dlg, hash, resolve, dlgOptions) { const self = this; self.originalUrl = window.location.href; const activeElement = document.activeElement; @@ -157,7 +157,7 @@ function DialogHashHandler(dlg, hash, resolve) { dlg.classList.remove('hide'); - addBackdropOverlay(dlg); + addBackdropOverlay(dlg, dlgOptions); dlg.classList.add('opened'); dlg.dispatchEvent(new CustomEvent('open', { @@ -192,7 +192,7 @@ function DialogHashHandler(dlg, hash, resolve) { } } -function addBackdropOverlay(dlg) { +function addBackdropOverlay(dlg, dlgOptions = {}) { const backdrop = document.createElement('div'); backdrop.classList.add('dialogBackdrop'); @@ -204,29 +204,33 @@ function addBackdropOverlay(dlg) { void backdrop.offsetWidth; backdrop.classList.add('dialogBackdropOpened'); - dom.addEventListener((dlg.dialogContainer || backdrop), 'click', e => { - if (e.target === dlg.dialogContainer) { - close(dlg); - } - }, { - passive: true - }); + if (!dlgOptions.preventCloseOnClick) { + dom.addEventListener((dlg.dialogContainer || backdrop), 'click', e => { + if (e.target === dlg.dialogContainer) { + close(dlg); + } + }, { + passive: true + }); + } - dom.addEventListener((dlg.dialogContainer || backdrop), 'contextmenu', e => { - if (e.target === dlg.dialogContainer) { - // Close the application dialog menu - close(dlg); - // Prevent the default browser context menu from appearing - e.preventDefault(); - } - }); + if (!dlgOptions.preventCloseOnRightClick) { + dom.addEventListener((dlg.dialogContainer || backdrop), 'contextmenu', e => { + if (e.target === dlg.dialogContainer) { + // Close the application dialog menu + close(dlg); + // Prevent the default browser context menu from appearing + e.preventDefault(); + } + }); + } } function isHistoryEnabled(dlg) { return dlg.getAttribute('data-history') === 'true'; } -export function open(dlg) { +export function open(dlg, dlgOptions) { if (globalOnOpenCallback) { globalOnOpenCallback(dlg); } @@ -243,7 +247,7 @@ export function open(dlg) { document.body.appendChild(dialogContainer); return new Promise((resolve) => { - new DialogHashHandler(dlg, `dlg${new Date().getTime()}`, resolve); + new DialogHashHandler(dlg, `dlg${new Date().getTime()}`, resolve, dlgOptions); }); } diff --git a/src/components/metadataEditor/metadataEditor.js b/src/components/metadataEditor/metadataEditor.js index 7e32da10871..02723463cff 100644 --- a/src/components/metadataEditor/metadataEditor.js +++ b/src/components/metadataEditor/metadataEditor.js @@ -1058,7 +1058,10 @@ function show(itemId, serverId, resolve) { centerFocus(dlg.querySelector('.formDialogContent'), false, true); } - dialogHelper.open(dlg); + dialogHelper.open(dlg, { + preventCloseOnClick : true, + preventCloseOnRightClick : true + }); dlg.addEventListener('close', function () { if (layoutManager.tv) {