feat: align Bell prototype with go-admin-ui (#31)

This commit is contained in:
QiuSW
2026-08-12 10:56:07 +08:00
parent 1da77fe0b1
commit 0bdd88ba9c
8 changed files with 350 additions and 245 deletions
+41
View File
@@ -0,0 +1,41 @@
(function () {
"use strict";
const shell = document.querySelector("[data-go-admin-shell]");
const collapse = document.querySelector("[data-collapse-sidebar]");
function syncTags(viewName) {
document.querySelectorAll(".tags-view-item").forEach((tag) => {
const active = tag.dataset.viewTarget === viewName;
tag.classList.toggle("active", active);
if (active) tag.setAttribute("aria-current", "page");
else tag.removeAttribute("aria-current");
});
}
document.querySelectorAll("[data-view-target]").forEach((trigger) => {
trigger.addEventListener("click", () => syncTags(trigger.dataset.viewTarget));
});
if (collapse && shell) {
collapse.addEventListener("click", () => {
const compact = shell.classList.toggle("compact");
collapse.setAttribute("aria-expanded", String(!compact));
collapse.setAttribute("aria-label", compact ? "展开主导航" : "折叠主导航");
});
}
document.querySelectorAll("[data-go-admin-query]").forEach((form) => {
const input = document.querySelector(form.dataset.queryInput || "");
form.addEventListener("submit", (event) => {
event.preventDefault();
input?.dispatchEvent(new Event("input", { bubbles: true }));
});
form.addEventListener("reset", () => {
window.setTimeout(() => input?.dispatchEvent(new Event("input", { bubbles: true })), 0);
});
});
const initialView = document.querySelector("[data-view-target].active")?.dataset.viewTarget;
if (initialView) syncTags(initialView);
})();