1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Prevent modal clos on mouse press up if outside the dialog

This commit is contained in:
venkat_karasani 2024-07-13 12:22:27 -05:00 committed by Bill Thornton
parent b9dea3a788
commit 2ed3aced2f
2 changed files with 28 additions and 21 deletions

View file

@ -42,7 +42,7 @@ function tryRemoveElement(elem) {
} }
} }
function DialogHashHandler(dlg, hash, resolve) { function DialogHashHandler(dlg, hash, resolve, dlgOptions) {
const self = this; const self = this;
self.originalUrl = window.location.href; self.originalUrl = window.location.href;
const activeElement = document.activeElement; const activeElement = document.activeElement;
@ -157,7 +157,7 @@ function DialogHashHandler(dlg, hash, resolve) {
dlg.classList.remove('hide'); dlg.classList.remove('hide');
addBackdropOverlay(dlg); addBackdropOverlay(dlg, dlgOptions);
dlg.classList.add('opened'); dlg.classList.add('opened');
dlg.dispatchEvent(new CustomEvent('open', { 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'); const backdrop = document.createElement('div');
backdrop.classList.add('dialogBackdrop'); backdrop.classList.add('dialogBackdrop');
@ -204,6 +204,7 @@ function addBackdropOverlay(dlg) {
void backdrop.offsetWidth; void backdrop.offsetWidth;
backdrop.classList.add('dialogBackdropOpened'); backdrop.classList.add('dialogBackdropOpened');
if (!dlgOptions.preventCloseOnClick) {
dom.addEventListener((dlg.dialogContainer || backdrop), 'click', e => { dom.addEventListener((dlg.dialogContainer || backdrop), 'click', e => {
if (e.target === dlg.dialogContainer) { if (e.target === dlg.dialogContainer) {
close(dlg); close(dlg);
@ -211,7 +212,9 @@ function addBackdropOverlay(dlg) {
}, { }, {
passive: true passive: true
}); });
}
if (!dlgOptions.preventCloseOnRightClick) {
dom.addEventListener((dlg.dialogContainer || backdrop), 'contextmenu', e => { dom.addEventListener((dlg.dialogContainer || backdrop), 'contextmenu', e => {
if (e.target === dlg.dialogContainer) { if (e.target === dlg.dialogContainer) {
// Close the application dialog menu // Close the application dialog menu
@ -221,12 +224,13 @@ function addBackdropOverlay(dlg) {
} }
}); });
} }
}
function isHistoryEnabled(dlg) { function isHistoryEnabled(dlg) {
return dlg.getAttribute('data-history') === 'true'; return dlg.getAttribute('data-history') === 'true';
} }
export function open(dlg) { export function open(dlg, dlgOptions) {
if (globalOnOpenCallback) { if (globalOnOpenCallback) {
globalOnOpenCallback(dlg); globalOnOpenCallback(dlg);
} }
@ -243,7 +247,7 @@ export function open(dlg) {
document.body.appendChild(dialogContainer); document.body.appendChild(dialogContainer);
return new Promise((resolve) => { return new Promise((resolve) => {
new DialogHashHandler(dlg, `dlg${new Date().getTime()}`, resolve); new DialogHashHandler(dlg, `dlg${new Date().getTime()}`, resolve, dlgOptions);
}); });
} }

View file

@ -1058,7 +1058,10 @@ function show(itemId, serverId, resolve) {
centerFocus(dlg.querySelector('.formDialogContent'), false, true); centerFocus(dlg.querySelector('.formDialogContent'), false, true);
} }
dialogHelper.open(dlg); dialogHelper.open(dlg, {
preventCloseOnClick : true,
preventCloseOnRightClick : true
});
dlg.addEventListener('close', function () { dlg.addEventListener('close', function () {
if (layoutManager.tv) { if (layoutManager.tv) {