Files
wrapped/app/static/js/admin-nav.js
T
Sergey Antropoff eef8c4ec57
devops-tools/wrapped/wrapped-build/pipeline/head This commit looks good
devops-tools/wrapped/wrapped-deploy/pipeline/head This commit looks good
Исправлены create UI, PWA-иконки, tooltip A2HS и breakpoint админ-меню 1015px.
2026-07-29 21:03:51 +03:00

53 lines
1.5 KiB
JavaScript

(() => {
const top = document.getElementById("admin-top");
const toggle = document.getElementById("admin-nav-toggle");
const nav = document.getElementById("admin-nav");
if (!top || !toggle || !nav) return;
const mq = window.matchMedia("(max-width: 1015px)");
const syncLabel = () => {
const open = top.classList.contains("is-nav-open");
const key = open ? "admin.nav.closeMenu" : "admin.nav.openMenu";
const label = window.WrappedI18n?.t(key) || (open ? "Close menu" : "Menu");
toggle.setAttribute("aria-label", label);
toggle.setAttribute("title", label);
};
const setOpen = (open) => {
top.classList.toggle("is-nav-open", open);
toggle.setAttribute("aria-expanded", open ? "true" : "false");
const icon = toggle.querySelector("i");
if (icon) {
icon.className = open ? "fa-solid fa-xmark" : "fa-solid fa-bars";
}
syncLabel();
};
toggle.addEventListener("click", () => {
setOpen(!top.classList.contains("is-nav-open"));
});
nav.addEventListener("click", (e) => {
if (!mq.matches) return;
if (e.target.closest("a.admin-nav-link")) setOpen(false);
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && top.classList.contains("is-nav-open")) {
setOpen(false);
toggle.focus();
}
});
mq.addEventListener("change", () => {
if (!mq.matches) setOpen(false);
else syncLabel();
});
if (window.WrappedI18n?.onChange) {
window.WrappedI18n.onChange(syncLabel);
}
syncLabel();
})();