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".
This commit is contained in:
+5
-3
@@ -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) {
|
if (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -30,8 +32,8 @@ export class Modal implements Modal {
|
|||||||
const listenerFunc = () => {
|
const listenerFunc = () => {
|
||||||
modal.classList.remove('block');
|
modal.classList.remove('block');
|
||||||
modal.classList.remove('animate-fade-out');
|
modal.classList.remove('animate-fade-out');
|
||||||
modal.removeEventListener(window.animationEvent, listenerFunc);
|
modal.removeEventListener(window.animationEvent, listenerFunc)
|
||||||
document.dispatchEvent(this.closeEvent);
|
if (!noDispatch) document.dispatchEvent(this.closeEvent);
|
||||||
};
|
};
|
||||||
this.modal.addEventListener(window.animationEvent, listenerFunc, false);
|
this.modal.addEventListener(window.animationEvent, listenerFunc, false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user