Close popup when clicking outside

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2026-03-02 09:36:10 +00:00
parent e9c575ab88
commit 6b9c0f7d22

View File

@@ -243,6 +243,23 @@
{{ end }} {{ end }}
</main> </main>
<script> <script>
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
document.querySelectorAll('.modal.show').forEach(modal => {
modal.classList.remove('show');
});
}
});
document.addEventListener('click', function(event) {
const modal = event.target.closest('.modal');
if (!modal && document.querySelectorAll('.modal.show').length > 0 && !event.target.closest('.more-link')) {
document.querySelectorAll('.modal.show').forEach(modal => {
modal.classList.remove('show');
});
}
});
[...document.querySelectorAll('.more-link')].forEach(more => { [...document.querySelectorAll('.more-link')].forEach(more => {
const toggleModal = function(event) { const toggleModal = function(event) {
event.preventDefault(); event.preventDefault();