Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const tabs = Array.from(document.querySelectorAll("[data-workflow-tab]"));
|
||||
if (!tabs.length) return;
|
||||
|
||||
const panels = new Map(
|
||||
tabs.map((tab) => [tab.dataset.workflowTab, document.getElementById(tab.dataset.workflowTab)])
|
||||
);
|
||||
|
||||
function activate(tab, moveFocus) {
|
||||
tabs.forEach((item) => {
|
||||
const selected = item === tab;
|
||||
item.classList.toggle("is-active", selected);
|
||||
item.setAttribute("aria-selected", String(selected));
|
||||
item.tabIndex = selected ? 0 : -1;
|
||||
const panel = panels.get(item.dataset.workflowTab);
|
||||
if (panel) {
|
||||
panel.hidden = !selected;
|
||||
panel.classList.toggle("is-active", selected);
|
||||
}
|
||||
});
|
||||
if (moveFocus) tab.focus();
|
||||
if (history.replaceState) history.replaceState(null, "", `#${tab.dataset.workflowTab}`);
|
||||
}
|
||||
|
||||
tabs.forEach((tab, index) => {
|
||||
tab.addEventListener("click", () => activate(tab, false));
|
||||
tab.addEventListener("keydown", (event) => {
|
||||
let target = null;
|
||||
if (event.key === "ArrowRight") target = tabs[(index + 1) % tabs.length];
|
||||
if (event.key === "ArrowLeft") target = tabs[(index - 1 + tabs.length) % tabs.length];
|
||||
if (event.key === "Home") target = tabs[0];
|
||||
if (event.key === "End") target = tabs[tabs.length - 1];
|
||||
if (!target) return;
|
||||
event.preventDefault();
|
||||
activate(target, true);
|
||||
});
|
||||
});
|
||||
|
||||
const initial = tabs.find((tab) => `#${tab.dataset.workflowTab}` === window.location.hash);
|
||||
if (initial) activate(initial, false);
|
||||
})();
|
||||
Reference in New Issue
Block a user