feat: align Bell prototype with go-admin-ui (#31)
This commit is contained in:
Vendored
+41
@@ -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);
|
||||
})();
|
||||
Reference in New Issue
Block a user