import { PageMenuProvider } from "./Provider";
import { createFocusTrap, FocusTrap } from "focus-trap";
-import { scrollDisable, scrollEnable } from "../../Screen";
+import { pageOverlayClose, pageOverlayOpen, scrollDisable, scrollEnable } from "../../Screen";
export class PageMenuContainer {
private readonly container = document.createElement("div");
this.content.append(this.provider.getContent());
this.provider.getMenuButton().setAttribute("aria-expanded", "true");
+ pageOverlayOpen();
scrollDisable();
this.container.hidden = false;
close(): void {
this.provider.getMenuButton().setAttribute("aria-expanded", "false");
+ pageOverlayClose();
scrollEnable();
this.container.hidden = true;
}
getContent(): DocumentFragment {
- const fragment = document.createDocumentFragment();
+ const container = document.createElement("div");
+ container.classList.add("pageMenuMainContainer");
+
+ container.append(...this.buildMainMenu());
+
+ const footerMenu = this.buildFooterMenu();
+ if (footerMenu) {
+ container.append(footerMenu);
+ }
- fragment.append(...this.buildMainMenu());
+ const fragment = document.createDocumentFragment();
+ fragment.append(container);
return fragment;
}
}
private buildMainMenu(): HTMLElement[] {
- const menu = this.mainMenu.querySelector(".boxMenu")!;
- const menuItems: MenuItem[] = Array.from(menu.children).map((element: HTMLElement) => {
+ const boxMenu = this.mainMenu.querySelector(".boxMenu") as HTMLElement;
+
+ const nav = this.buildMenu(boxMenu);
+ nav.setAttribute("aria-label", window.PAGE_TITLE);
+ nav.setAttribute("role", "navigation");
+
+ return [nav];
+ }
+
+ private buildFooterMenu(): HTMLElement | null {
+ const box = document.querySelector('.box[data-box-identifier="com.woltlab.wcf.FooterMenu"]');
+ if (box === null) {
+ return null;
+ }
+
+ const boxMenu = box.querySelector(".boxMenu") as HTMLElement;
+ const nav = this.buildMenu(boxMenu);
+ nav.classList.add("pageMenuMainNavigationFooter");
+
+ const label = box.querySelector("nav")!.getAttribute("aria-label")!;
+ nav.setAttribute("aria-label", label);
+
+ return nav;
+ }
+
+ private buildMenu(boxMenu: HTMLElement): HTMLElement {
+ const menuItems: MenuItem[] = Array.from(boxMenu.children).map((element: HTMLElement) => {
return normalizeMenuItem(element);
});
const nav = document.createElement("nav");
nav.classList.add("pageMenuMainNavigation");
- nav.setAttribute("aria-label", window.PAGE_TITLE);
- nav.setAttribute("role", "navigation");
nav.append(this.buildMenuItemList(menuItems));
- return [nav];
+ return nav;
}
private buildMenuItemList(menuItems: MenuItem[]): HTMLUListElement {
this.content.innerHTML = "";
this.content.append(this.provider.getContent());
this.provider.getMenuButton().setAttribute("aria-expanded", "true");
+ (0, Screen_1.pageOverlayOpen)();
(0, Screen_1.scrollDisable)();
this.container.hidden = false;
this.getFocusTrap().activate();
}
close() {
this.provider.getMenuButton().setAttribute("aria-expanded", "false");
+ (0, Screen_1.pageOverlayClose)();
(0, Screen_1.scrollEnable)();
this.container.hidden = true;
this.getFocusTrap().deactivate();
});
}
getContent() {
+ const container = document.createElement("div");
+ container.classList.add("pageMenuMainContainer");
+ container.append(...this.buildMainMenu());
+ const footerMenu = this.buildFooterMenu();
+ if (footerMenu) {
+ container.append(footerMenu);
+ }
const fragment = document.createDocumentFragment();
- fragment.append(...this.buildMainMenu());
+ fragment.append(container);
return fragment;
}
getMenuButton() {
return this.mainMenu;
}
buildMainMenu() {
- const menu = this.mainMenu.querySelector(".boxMenu");
- const menuItems = Array.from(menu.children).map((element) => {
+ const boxMenu = this.mainMenu.querySelector(".boxMenu");
+ const nav = this.buildMenu(boxMenu);
+ nav.setAttribute("aria-label", window.PAGE_TITLE);
+ nav.setAttribute("role", "navigation");
+ return [nav];
+ }
+ buildFooterMenu() {
+ const box = document.querySelector('.box[data-box-identifier="com.woltlab.wcf.FooterMenu"]');
+ if (box === null) {
+ return null;
+ }
+ const boxMenu = box.querySelector(".boxMenu");
+ const nav = this.buildMenu(boxMenu);
+ nav.classList.add("pageMenuMainNavigationFooter");
+ const label = box.querySelector("nav").getAttribute("aria-label");
+ nav.setAttribute("aria-label", label);
+ return nav;
+ }
+ buildMenu(boxMenu) {
+ const menuItems = Array.from(boxMenu.children).map((element) => {
return normalizeMenuItem(element);
});
const nav = document.createElement("nav");
nav.classList.add("pageMenuMainNavigation");
- nav.setAttribute("aria-label", window.PAGE_TITLE);
- nav.setAttribute("role", "navigation");
nav.append(this.buildMenuItemList(menuItems));
- return [nav];
+ return nav;
}
buildMenuItemList(menuItems) {
const list = document.createElement("ul");