private readonly container: PageMenuContainer;
private readonly mainMenu: HTMLElement;
private readonly menuItemProvider: PageMenuMainProvider;
+ private readonly observer: MutationObserver;
constructor(menuItemProvider: PageMenuMainProvider) {
this.mainMenu = document.querySelector(".mainMenu")!;
this.container.toggle();
};
+
+ this.observer = new MutationObserver((mutations) => {
+ let refreshUnreadIndicator = false;
+
+ mutations.forEach((mutation) => {
+ if (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0 || mutation.type === "characterData") {
+ refreshUnreadIndicator = true;
+ }
+ });
+
+ if (refreshUnreadIndicator) {
+ this.refreshUnreadIndicator();
+ }
+ });
+
+ this.watchForChanges();
}
enable(): void {
}
sleep(): void {
- /* Does nothing */
+ this.watchForChanges();
}
wakeup(): void {
+ this.observer.disconnect();
+
this.refreshUnreadIndicator();
}
+ private watchForChanges(): void {
+ this.observer.observe(this.mainMenu, {
+ childList: true,
+ subtree: true,
+ });
+ }
+
private buildMainMenu(): HTMLElement {
const boxMenu = this.mainMenu.querySelector(".boxMenu") as HTMLElement;
event.stopPropagation();
this.container.toggle();
};
+ this.observer = new MutationObserver((mutations) => {
+ let refreshUnreadIndicator = false;
+ mutations.forEach((mutation) => {
+ if (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0 || mutation.type === "characterData") {
+ refreshUnreadIndicator = true;
+ }
+ });
+ if (refreshUnreadIndicator) {
+ this.refreshUnreadIndicator();
+ }
+ });
+ this.watchForChanges();
}
enable() {
this.mainMenu.setAttribute("aria-expanded", "false");
return this.mainMenu;
}
sleep() {
- /* Does nothing */
+ this.watchForChanges();
}
wakeup() {
+ this.observer.disconnect();
this.refreshUnreadIndicator();
}
+ watchForChanges() {
+ this.observer.observe(this.mainMenu, {
+ childList: true,
+ subtree: true,
+ });
+ }
buildMainMenu() {
const boxMenu = this.mainMenu.querySelector(".boxMenu");
const nav = this.buildMenu(boxMenu);