shiloh-echo/js/agenda.js
2026-07-13 22:13:45 -07:00

61 lines
1.7 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function () {
var tabs = Array.prototype.slice.call(
document.querySelectorAll('[role="tab"]')
);
var panels = Array.prototype.slice.call(
document.querySelectorAll('[role="tabpanel"]')
);
if (tabs.length === 0) return;
var STORAGE_KEY = "shiloh-echo-schedule-tab";
function activateTab(tab, isClick) {
tabs.forEach(function (t) {
var sel = t === tab;
t.setAttribute("aria-selected", String(sel));
var panelId = t.getAttribute("aria-controls");
var panel = document.getElementById(panelId);
if (panel) panel.setAttribute("aria-hidden", String(!sel));
});
try {
localStorage.setItem(STORAGE_KEY, tab.id);
} catch (e) {}
tab.focus({ preventScroll: true });
if (isClick) {
var panelId = tab.getAttribute("aria-controls");
var panel = document.getElementById(panelId);
if (panel) {
var rect = panel.getBoundingClientRect();
window.scrollTo({
top: rect.top + window.pageYOffset - 80,
behavior: "smooth",
});
}
}
}
tabs.forEach(function (tab, index) {
tab.addEventListener("click", function () {
activateTab(tab, true);
});
tab.addEventListener("keydown", function (e) {
if (e.key === "ArrowRight") {
tabs[(index + 1) % tabs.length].click();
} else if (e.key === "ArrowLeft") {
tabs[(index - 1 + tabs.length) % tabs.length].click();
}
});
});
var stored = null;
try {
stored = localStorage.getItem(STORAGE_KEY);
} catch (e) {}
var initial =
(stored && document.getElementById(stored)) ||
document.getElementById("tab-friday") ||
tabs[0];
if (initial) activateTab(initial, false);
});