Files
matrix/cygnus-onprem-app/build/WebContent/js/matrix-shell-v2.js

125 lines
4.5 KiB
JavaScript

(() => {
"use strict";
const menu = document.getElementById("master_0");
const legacyHeader = document.querySelector(".matrix-shell #PageFrame > .title");
const legacyTitle = legacyHeader?.querySelector(":scope > .matrix-title-text, :scope > span#title");
if (legacyTitle && !legacyTitle.classList.contains("matrix-shell__legacy-title")) {
const parts = legacyTitle.textContent
.replace(/\u00a0/g, " ")
.split(/\s{2,}/)
.map((part) => part.replace(/^\|\s*/, "").trim())
.filter(Boolean);
if (parts.length >= 3 && /^(nimble|cygnus)\b/i.test(parts[0])) {
const brand = parts.shift();
const user = parts.pop();
const company = parts.pop();
const pageName = parts.join(" · ");
legacyTitle.textContent = "";
legacyTitle.className = "matrix-shell__legacy-title";
const brandElement = document.createElement("strong");
brandElement.className = "matrix-shell__legacy-brand";
brandElement.textContent = brand;
legacyTitle.appendChild(brandElement);
if (pageName) {
const pageElement = document.createElement("span");
pageElement.className = "matrix-shell__legacy-page";
pageElement.textContent = pageName;
legacyTitle.appendChild(pageElement);
}
const context = document.createElement("span");
context.className = "matrix-shell__legacy-context";
const companyElement = document.createElement("span");
companyElement.className = "matrix-shell__legacy-company";
companyElement.textContent = company;
const userElement = document.createElement("span");
userElement.className = "matrix-shell__legacy-user";
userElement.textContent = user;
context.append(companyElement, userElement);
legacyTitle.appendChild(context);
}
}
window.SubmitForm = (pageUrl, targetWindow, formName) => {
if (!pageUrl || pageUrl === "#") {
return false;
}
const form = document.forms[formName];
if (!form) {
return false;
}
form.action = pageUrl;
form.target = targetWindow;
form.submit();
return true;
};
window.SubmitMenuCommand = (pageUrl, targetWindow, formName, requestValue) => {
const form = document.forms[formName];
const pageValue = form?.elements.namedItem("pageval");
if (pageValue) {
pageValue.value = requestValue ?? "";
}
return window.SubmitForm(pageUrl, targetWindow, formName);
};
if (!menu) {
return;
}
const closeMenus = (except) => {
menu.querySelectorAll(".matrix-menu-open").forEach((item) => {
if (item !== except && (!except || !item.contains(except))) {
item.classList.remove("matrix-menu-open");
item.querySelector(":scope > a")?.setAttribute("aria-expanded", "false");
}
});
};
menu.querySelectorAll("a").forEach((link) => {
link.setAttribute("href", "#");
const item = link.parentElement;
const submenu = item?.querySelector(":scope > ul");
const hasChildren = Boolean(submenu?.querySelector(":scope > li"));
if (hasChildren) {
link.setAttribute("aria-haspopup", "true");
link.setAttribute("aria-expanded", "false");
link.addEventListener("click", (event) => {
event.preventDefault();
const willOpen = !item.classList.contains("matrix-menu-open");
closeMenus(item);
item.classList.toggle("matrix-menu-open", willOpen);
link.setAttribute("aria-expanded", String(willOpen));
});
}
link.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeMenus();
link.focus();
} else if (event.key === "ArrowDown" && hasChildren) {
event.preventDefault();
item.classList.add("matrix-menu-open");
link.setAttribute("aria-expanded", "true");
submenu.querySelector("a")?.focus();
}
});
});
document.addEventListener("click", (event) => {
if (!menu.contains(event.target)) {
closeMenus();
}
});
})();