Made the dialog close when clicking off of it.

This commit is contained in:
Saud Fatayerji 2023-05-04 19:46:00 +03:00
parent b2a29e2b13
commit b100435d9c

View file

@ -115,6 +115,7 @@ document.addEventListener("DOMContentLoaded", function () {
document.body.appendChild(script); document.body.appendChild(script);
} }
let gameScriptLoaded = false; let gameScriptLoaded = false;
const gameDialog = document.getElementById('game-container-wrapper')
$('#show-game-btn').on('click', function() { $('#show-game-btn').on('click', function() {
console.log('Show game button clicked'); console.log('Show game button clicked');
if (!gameScriptLoaded) { if (!gameScriptLoaded) {
@ -127,8 +128,19 @@ document.addEventListener("DOMContentLoaded", function () {
} else { } else {
window.resetGame(); window.resetGame();
} }
document.getElementById('game-container-wrapper').showModal(); gameDialog.showModal();
}); });
gameDialog.addEventListener("click", e => {
const dialogDimensions = gameDialog.getBoundingClientRect()
if (
e.clientX < dialogDimensions.left ||
e.clientX > dialogDimensions.right ||
e.clientY < dialogDimensions.top ||
e.clientY > dialogDimensions.bottom
) {
gameDialog.close()
}
})
}) })
</script> </script>
<div id="game-container"> <div id="game-container">