From 848b532b3c7fba0c653f7653906b89eb7056b554 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 27 Aug 2024 14:55:04 +0100 Subject: [PATCH] ts/modal: dont close when not open! closing an already closed modal messed it up. Function returns if the modal has "block" or "animate-fade-in". --- ts/modules/modal.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ts/modules/modal.ts b/ts/modules/modal.ts index e8079dd..77cbb4e 100644 --- a/ts/modules/modal.ts +++ b/ts/modules/modal.ts @@ -20,7 +20,9 @@ export class Modal implements Modal { }); } } - close = (event?: Event) => { + close = (event?: Event, noDispatch?: boolean) => { + // If we don't check we can mess up a closed modal. + if (!this.modal.classList.contains("block") && !this.modal.classList.contains("animate-fade-in")) return; if (event) { event.preventDefault(); } @@ -30,8 +32,8 @@ export class Modal implements Modal { const listenerFunc = () => { modal.classList.remove('block'); modal.classList.remove('animate-fade-out'); - modal.removeEventListener(window.animationEvent, listenerFunc); - document.dispatchEvent(this.closeEvent); + modal.removeEventListener(window.animationEvent, listenerFunc) + if (!noDispatch) document.dispatchEvent(this.closeEvent); }; this.modal.addEventListener(window.animationEvent, listenerFunc, false); }