Allow single button dialogs to be dismissed by clicking the background.

This commit is contained in:
flash 2024-04-21 19:36:58 +00:00
parent ddc7830c4c
commit 72340994da

View file

@ -11,9 +11,16 @@ const MamiMessageBoxContainer = function() {
if(typeof dialog !== 'object' || dialog === null)
throw 'dialog must be a non-null object';
const backgroundClick = () => {
dialog.clickButtonIndex(0);
};
try {
if(dialog.buttonCount === 1)
container.addEventListener('click', backgroundClick);
return await dialog.show(container);
} finally {
container.removeEventListener('click', backgroundClick);
dialog.dismiss();
}
},
@ -117,6 +124,14 @@ const MamiMessageBoxDialog = function(info) {
return {
getElement: () => dialog,
get buttonCount() {
return buttons.childElementCount;
},
clickButtonIndex: num => {
buttons.children[num].click();
},
show: container => {
return new Promise((resolve, reject) => {
showResolve = resolve;