sutom/ts/notificationMessage.ts
2022-01-31 19:29:33 +01:00

35 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default class NotificationMessage {
private static _notificationArea: HTMLElement = document.getElementById("notification") as HTMLElement;
private static _notificationPanelArea: HTMLElement = document.getElementById("panel-fenetre-notification") as HTMLElement;
private static _currentTimeout: NodeJS.Timeout | undefined;
public static ajouterNotification(message: string): void {
this.ajouterNotificationDiv(this._notificationArea, message);
}
public static ajouterNotificationPanel(message: string): void {
this.ajouterNotificationDiv(this._notificationPanelArea, message);
}
private static ajouterNotificationDiv(div: HTMLElement, message: string): void {
if (this._currentTimeout) {
clearTimeout(this._currentTimeout);
this._currentTimeout = undefined;
}
div.innerHTML = message;
div.style.opacity = "1";
this._currentTimeout = setTimeout(
(() => {
div.style.opacity = "0";
this._currentTimeout = setTimeout(
(() => {
div.innerHTML = " ";
this._currentTimeout = undefined;
}).bind(this),
1000
);
}).bind(this),
5000
);
}
}