shiloh-echo/js/agenda.js
Gary 38ecf42a1e improve agenda UI
Add william toll
2026-05-28 11:10:37 -07:00

42 lines
1.2 KiB
JavaScript

$(document).ready(function () {
var $tabs = $('[role="tab"]');
var $panels = $('[role="tabpanel"]');
if ($tabs.length === 0) return;
function activateTab($tab, isClick) {
$tabs.each(function () {
var $t = $(this);
var sel = $t[0] === $tab[0];
$t.attr("aria-selected", String(sel));
var panelId = $t.attr("aria-controls");
$("#" + panelId).attr("aria-hidden", String(!sel));
});
$tab.focus({ preventScroll: true });
if (isClick) {
var panelId = $tab.attr("aria-controls");
var $panel = $("#" + panelId);
$panel[0].scrollIntoView({ block: "center", behavior: "smooth" });
$panel[0].scrollTop = 0;
}
}
$tabs.each(function (index) {
var $t = $(this);
$t.on("click", function () {
activateTab($t, true);
});
$t.on("keydown", function (e) {
if (e.key === "ArrowRight") {
$tabs.eq((index + 1) % $tabs.length).click();
} else if (e.key === "ArrowLeft") {
$tabs.eq((index - 1 + $tabs.length) % $tabs.length).click();
}
});
});
var $initial = $("#tab-friday");
if ($initial.length === 0) $initial = $tabs.eq(0);
if ($initial.length) activateTab($initial, false);
});