mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 23:08:36 +02:00
close dialog boxes on escape
This commit is contained in:
committed by
danielyxie
parent
eecb0c0f01
commit
e5e3fec1a9
@@ -1,3 +1,5 @@
|
|||||||
|
import { KEY } from "./helpers/keyCodes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and display a pop-up dialog box.
|
* Create and display a pop-up dialog box.
|
||||||
* This dialog box does not allow for any interaction and should close when clicking
|
* This dialog box does not allow for any interaction and should close when clicking
|
||||||
@@ -9,28 +11,31 @@ let dialogBoxes = [];
|
|||||||
$(document).click(function(event) {
|
$(document).click(function(event) {
|
||||||
if (dialogBoxOpened && dialogBoxes.length >= 1) {
|
if (dialogBoxOpened && dialogBoxes.length >= 1) {
|
||||||
if (!$(event.target).closest(dialogBoxes[0]).length){
|
if (!$(event.target).closest(dialogBoxes[0]).length){
|
||||||
dialogBoxes[0].remove();
|
closeTopmostDialogBox();
|
||||||
dialogBoxes.splice(0, 1);
|
|
||||||
if (dialogBoxes.length == 0) {
|
|
||||||
dialogBoxOpened = false;
|
|
||||||
} else {
|
|
||||||
dialogBoxes[0].style.visibility = "visible";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function closeTopmostDialogBox() {
|
||||||
|
if (!dialogBoxOpened || dialogBoxes.length === 0) return;
|
||||||
|
dialogBoxes[0].remove();
|
||||||
|
dialogBoxes.shift();
|
||||||
|
if (dialogBoxes.length == 0) {
|
||||||
|
dialogBoxOpened = false;
|
||||||
|
} else {
|
||||||
|
dialogBoxes[0].style.visibility = "visible";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dialog box close buttons
|
// Dialog box close buttons
|
||||||
$(document).on('click', '.dialog-box-close-button', function( event ) {
|
$(document).on('click', '.dialog-box-close-button', function( event ) {
|
||||||
if (dialogBoxOpened && dialogBoxes.length >= 1) {
|
closeTopmostDialogBox();
|
||||||
dialogBoxes[0].remove();
|
});
|
||||||
dialogBoxes.splice(0, 1);
|
|
||||||
if (dialogBoxes.length == 0) {
|
document.addEventListener("keydown", function (event) {
|
||||||
dialogBoxOpened = false;
|
if (event.keyCode == KEY.ESC && dialogBoxOpened) {
|
||||||
} else {
|
closeTopmostDialogBox();
|
||||||
dialogBoxes[0].style.visibility = "visible";
|
event.preventDefault();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user