private readonly callbackOpen: CallbackOpen;
private readonly container: PageMenuContainer;
private readonly mainMenu: HTMLElement;
+ private readonly menuItemBadges = new Map<string, HTMLElement>();
private readonly menuItemProvider: PageMenuMainProvider;
private readonly observer: MutationObserver;
counter.setAttribute("aria-hidden", "true");
counter.textContent = menuItem.counter.toString();
+ if (menuItem.identifier !== false) {
+ this.menuItemBadges.set(menuItem.identifier, counter);
+ }
+
link.append(counter);
}
} else {
this.mainMenu.classList.remove("pageMenuMobileButtonHasContent");
}
+
+ const menuItems = this.menuItemProvider.getMenuItems(this.mainMenu);
+ menuItems.forEach((menuItem) => this.refreshUnreadBage(menuItem));
+ }
+
+ private refreshUnreadBage(menuItem: MenuItem): void {
+ if (menuItem.identifier !== false) {
+ const counter = this.menuItemBadges.get(menuItem.identifier);
+ if (counter) {
+ if (menuItem.counter === 0) {
+ counter.remove();
+ this.menuItemBadges.delete(menuItem.identifier);
+ } else {
+ const value = parseInt(counter.textContent!, 10);
+ if (value !== menuItem.counter) {
+ counter.textContent = menuItem.counter.toString();
+ }
+ }
+ }
+ }
+
+ menuItem.children.forEach((child) => this.refreshUnreadBage(child));
}
private updateOverflowIndicator(container: HTMLElement): void {
Util_1 = tslib_1.__importDefault(Util_1);
class PageMenuMain {
constructor(menuItemProvider) {
+ this.menuItemBadges = new Map();
this.mainMenu = document.querySelector(".mainMenu");
this.menuItemProvider = menuItemProvider;
this.container = new Container_1.default(this);
counter.classList.add("pageMenuMainItemCounter", "badge", "badgeUpdate");
counter.setAttribute("aria-hidden", "true");
counter.textContent = menuItem.counter.toString();
+ if (menuItem.identifier !== false) {
+ this.menuItemBadges.set(menuItem.identifier, counter);
+ }
link.append(counter);
}
listItem.append(link);
else {
this.mainMenu.classList.remove("pageMenuMobileButtonHasContent");
}
+ const menuItems = this.menuItemProvider.getMenuItems(this.mainMenu);
+ menuItems.forEach((menuItem) => this.refreshUnreadBage(menuItem));
+ }
+ refreshUnreadBage(menuItem) {
+ if (menuItem.identifier !== false) {
+ const counter = this.menuItemBadges.get(menuItem.identifier);
+ if (counter) {
+ if (menuItem.counter === 0) {
+ counter.remove();
+ this.menuItemBadges.delete(menuItem.identifier);
+ }
+ else {
+ const value = parseInt(counter.textContent, 10);
+ if (value !== menuItem.counter) {
+ counter.textContent = menuItem.counter.toString();
+ }
+ }
+ }
+ }
+ menuItem.children.forEach((child) => this.refreshUnreadBage(child));
}
updateOverflowIndicator(container) {
const hasOverflow = container.clientHeight < container.scrollHeight;