Skip to content

Commit

Permalink
Merge pull request #5781 from venkat-karasani/prevent-modal-close
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill authored Jul 26, 2024
2 parents b9dea3a + 2ed3ace commit c3a00e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
44 changes: 24 additions & 20 deletions src/components/dialogHelper/dialogHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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');

Expand All @@ -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);
}
Expand All @@ -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);
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/metadataEditor/metadataEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c3a00e2

Please sign in to comment.