update menu

This commit is contained in:
Zhora Shalyapin 2025-03-20 12:09:33 +00:00
parent 64f55efca8
commit 0f8af9b014

99
main.js
View File

@ -18,8 +18,14 @@
const links = {
"Волонтеры": "suv_comp",
"Контрольные пункты": "cp_mgmt",
"Добавить новый КП": "cp_mgmt/?action=edit",
"+ КП": "cp_mgmt/?action=edit",
"Маршруты": "route_mgmt",
"Тесты": "route_mgmt?test=1",
"+ Тест": "suv_comp?action=test_online",
"Склеить": "suv_comp?action=test_merge",
"Прохождение": "callcenter?action=online_log",
"КП в трассах": "route_mgmt?action=cp_list",
// "Связанные КП": "#",
}
const catLinks = {
@ -979,29 +985,16 @@
}
}
function addStickyMenu() {
let competition = getCompetition()
if (!competition) return
let menuContainer = document.createElement("nav")
menuContainer.classList.add("sticky-menu")
function createMenuFromLinks(links, blanks = []) {
let menu = document.createElement("menu")
menuContainer.appendChild(menu)
let catId = urlParams().get("cat_id")
if (catId !== null) {
for (const [label, href] of Object.entries(catLinks)) {
links[label] = href(catId)
}
}
for (const [label, href] of Object.entries(links)) {
let menuItem = document.createElement("li")
let link = document.createElement("a")
link.href = `/${competition}/${href}`
link.href = href
link.innerText = label
if (label === "Легенда") {
if (blanks.includes(label)) {
link.setAttribute("target", "_blank")
}
@ -1009,7 +1002,57 @@
menu.appendChild(menuItem)
}
return menu
}
function addStickyMenu() {
let competition = getCompetition()
if (!competition) return
let menuContainer = document.createElement("nav")
menuContainer.classList.add("sticky-menu")
let mainLinksFormatted = {}
for (const [label, href] of Object.entries(links)) {
mainLinksFormatted[label] = `/${competition}/${href}`
}
menuContainer.append(createMenuFromLinks(mainLinksFormatted, ["Легенда"]))
let catId = urlParams().get("cat_id")
if (catId !== null) {
let catLinksFormatted = {}
for (const [label, href] of Object.entries(catLinks)) {
catLinksFormatted[label] = href(catId)
}
menuContainer.append(createMenuFromLinks(catLinksFormatted))
}
document.querySelector("#header").after(menuContainer)
addStylesToHead(`
.sticky-menu {
position: sticky;
top: 0;
z-index: 9999;
menu {
display: flex;
gap: .3rem;
background: white;
font-size: 1.2rem;
padding-left: 10px;
li {
list-style-type: none;
&:not(:last-child)::after {
content: " | "
}
}
}
}
`)
}
function addClearBoth() {
@ -1996,28 +2039,6 @@
function addCommonStyles() {
addStylesToHead(`
.sticky-menu {
position: sticky;
top: 0;
z-index: 9999;
menu {
display: flex;
gap: .3rem;
background: white;
font-size: 1.2rem;
padding-left: 10px;
li {
list-style-type: none;
&:not(:last-child)::after {
content: " | "
}
}
}
}
#content h1 {
margin-bottom: 0;
}