</div>
<div class="userMenuContentDivider"></div>
{/if}
- <div class="userMenuContent">
+ <div class="userMenuContent userMenuContentScrollable">
{foreach from=$__wcf->getUserMenu()->getUserMenuItems() item=menuItem}
<div class="userMenuItem userMenuItemNarrow" data-category="{$menuItem[category]->menuItem}">
<div class="userMenuItemImage">
import { getUserMenuProviders } from "../../User/Menu/Manager";
import { UserMenuProvider } from "../../User/Menu/Data/Provider";
import DomUtil from "../../../Dom/Util";
+import { getElement as getControlPanelElement } from "../../User/Menu/ControlPanel";
type CallbackOpen = (event: MouseEvent) => void;
type TabPanel = HTMLDivElement;
type TabComponents = [Tab, TabPanel];
+type TabData = {
+ icon: string;
+ label: string;
+ origin: string;
+};
+
export class PageMenuUser implements PageMenuProvider {
private readonly callbackOpen: CallbackOpen;
private readonly container: PageMenuContainer;
}
private attachViewToPanel(tab: HTMLAnchorElement): void {
+ const origin = tab.dataset.origin!;
const tabPanel = this.tabPanels.get(tab)!;
- if (tabPanel.childElementCount === 0) {
- const provider = this.userMenuProviders.get(tab);
- if (provider) {
- const view = provider.getView();
- tabPanel.append(view.getElement());
- void view.open();
- } else {
- throw new Error("TODO: Legacy user panel menus");
+
+ if (origin === "userMenu") {
+ const element = getControlPanelElement();
+ element.hidden = false;
+
+ if (tabPanel.childElementCount === 0) {
+ tabPanel.append(element);
+ }
+ } else {
+ if (tabPanel.childElementCount === 0) {
+ const provider = this.userMenuProviders.get(tab);
+ if (provider) {
+ const view = provider.getView();
+ tabPanel.append(view.getElement());
+ void view.open();
+ } else {
+ throw new Error("TODO: Legacy user panel menus");
+ }
}
}
}
tabList.setAttribute("aria-label", Language.get("TODO"));
tabContainer.append(tabList);
- // TODO: Inject the control panel first.
+ const [tab, tabPanel] = this.buildControlPanelTab();
+ tabList.append(tab);
+ tabContainer.append(tabPanel);
+
+ this.tabs.push(tab);
+ this.tabPanels.set(tab, tabPanel);
getUserMenuProviders().forEach((provider) => {
const [tab, tabPanel] = this.buildTab(provider);
}
private buildTab(provider: UserMenuProvider): TabComponents {
+ const panelButton = provider.getPanelButton();
+ const button = panelButton.querySelector("a")!;
+
+ const data: TabData = {
+ icon: button.querySelector(".icon")!.outerHTML,
+ label: button.dataset.title || button.title,
+ origin: panelButton.id,
+ };
+
+ return this.buildTabComponents(data);
+ }
+
+ private buildControlPanelTab(): TabComponents {
+ const panel = document.getElementById("topMenu")!;
+ const userMenu = document.getElementById("userMenu")!;
+ const userMenuButton = userMenu.querySelector("a")!;
+
+ const data: TabData = {
+ icon: panel.querySelector(".userPanelAvatar .userAvatarImage")!.outerHTML,
+ label: userMenuButton.dataset.title || userMenuButton.title,
+ origin: userMenu.id,
+ };
+
+ return this.buildTabComponents(data);
+ }
+
+ private buildTabComponents(data: TabData): TabComponents {
const tabId = DomUtil.getUniqueId();
const panelId = DomUtil.getUniqueId();
const tab = document.createElement("a");
tab.classList.add("pageMenuUserTab");
- tab.dataset.origin = provider.getPanelButton().id;
+ tab.dataset.origin = data.origin;
tab.id = tabId;
tab.setAttribute("aria-controls", panelId);
tab.setAttribute("aria-selected", "false");
tab.setAttribute("role", "tab");
tab.tabIndex = -1;
- const button = provider.getPanelButton().querySelector("a")!;
- tab.setAttribute("aria-label", button.dataset.title || button.title);
- tab.innerHTML = button.querySelector(".icon")!.outerHTML;
+ tab.setAttribute("aria-label", data.label);
+ tab.innerHTML = data.icon;
tab.addEventListener("click", (event) => {
event.preventDefault();
link.setAttribute("aria-expanded", "false");
}
+export function getElement(): HTMLElement {
+ return element;
+}
+
let isInitialized = false;
export function setup(): void {
if (!isInitialized) {
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Ui/Page/Menu/User
*/
-define(["require", "exports", "tslib", "./Container", "../../../Language", "../../User/Menu/Manager", "../../../Dom/Util"], function (require, exports, tslib_1, Container_1, Language, Manager_1, Util_1) {
+define(["require", "exports", "tslib", "./Container", "../../../Language", "../../User/Menu/Manager", "../../../Dom/Util", "../../User/Menu/ControlPanel"], function (require, exports, tslib_1, Container_1, Language, Manager_1, Util_1, ControlPanel_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasValidUserMenu = exports.PageMenuUser = void 0;
this.attachViewToPanel(tab);
}
attachViewToPanel(tab) {
+ const origin = tab.dataset.origin;
const tabPanel = this.tabPanels.get(tab);
- if (tabPanel.childElementCount === 0) {
- const provider = this.userMenuProviders.get(tab);
- if (provider) {
- const view = provider.getView();
- tabPanel.append(view.getElement());
- void view.open();
+ if (origin === "userMenu") {
+ const element = (0, ControlPanel_1.getElement)();
+ element.hidden = false;
+ if (tabPanel.childElementCount === 0) {
+ tabPanel.append(element);
}
- else {
- throw new Error("TODO: Legacy user panel menus");
+ }
+ else {
+ if (tabPanel.childElementCount === 0) {
+ const provider = this.userMenuProviders.get(tab);
+ if (provider) {
+ const view = provider.getView();
+ tabPanel.append(view.getElement());
+ void view.open();
+ }
+ else {
+ throw new Error("TODO: Legacy user panel menus");
+ }
}
}
}
tabList.setAttribute("role", "tablist");
tabList.setAttribute("aria-label", Language.get("TODO"));
tabContainer.append(tabList);
- // TODO: Inject the control panel first.
+ const [tab, tabPanel] = this.buildControlPanelTab();
+ tabList.append(tab);
+ tabContainer.append(tabPanel);
+ this.tabs.push(tab);
+ this.tabPanels.set(tab, tabPanel);
(0, Manager_1.getUserMenuProviders)().forEach((provider) => {
const [tab, tabPanel] = this.buildTab(provider);
tabList.append(tab);
return tabContainer;
}
buildTab(provider) {
+ const panelButton = provider.getPanelButton();
+ const button = panelButton.querySelector("a");
+ const data = {
+ icon: button.querySelector(".icon").outerHTML,
+ label: button.dataset.title || button.title,
+ origin: panelButton.id,
+ };
+ return this.buildTabComponents(data);
+ }
+ buildControlPanelTab() {
+ const panel = document.getElementById("topMenu");
+ const userMenu = document.getElementById("userMenu");
+ const userMenuButton = userMenu.querySelector("a");
+ const data = {
+ icon: panel.querySelector(".userPanelAvatar .userAvatarImage").outerHTML,
+ label: userMenuButton.dataset.title || userMenuButton.title,
+ origin: userMenu.id,
+ };
+ return this.buildTabComponents(data);
+ }
+ buildTabComponents(data) {
const tabId = Util_1.default.getUniqueId();
const panelId = Util_1.default.getUniqueId();
const tab = document.createElement("a");
tab.classList.add("pageMenuUserTab");
- tab.dataset.origin = provider.getPanelButton().id;
+ tab.dataset.origin = data.origin;
tab.id = tabId;
tab.setAttribute("aria-controls", panelId);
tab.setAttribute("aria-selected", "false");
tab.setAttribute("role", "tab");
tab.tabIndex = -1;
- const button = provider.getPanelButton().querySelector("a");
- tab.setAttribute("aria-label", button.dataset.title || button.title);
- tab.innerHTML = button.querySelector(".icon").outerHTML;
+ tab.setAttribute("aria-label", data.label);
+ tab.innerHTML = data.icon;
tab.addEventListener("click", (event) => {
event.preventDefault();
this.openTab(tab);
define(["require", "exports", "tslib", "../../CloseOverlay", "./Manager", "focus-trap", "../../Alignment", "../../../Dom/Util"], function (require, exports, tslib_1, CloseOverlay_1, Manager_1, focus_trap_1, Alignment, Util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
- exports.setup = void 0;
+ exports.setup = exports.getElement = void 0;
CloseOverlay_1 = (0, tslib_1.__importDefault)(CloseOverlay_1);
Alignment = (0, tslib_1.__importStar)(Alignment);
Util_1 = (0, tslib_1.__importDefault)(Util_1);
button.classList.remove("open");
link.setAttribute("aria-expanded", "false");
}
+ function getElement() {
+ return element;
+ }
+ exports.getElement = getElement;
let isInitialized = false;
function setup() {
if (!isInitialized) {
flex-direction: column;
height: 100%;
- .userMenuContent {
+ .userMenuContentScrollable {
flex: 1 auto;
}
}