2024-06-24 18:36:50 +00:00
|
|
|
function initTabs(container, initialTab = null) {
|
|
|
|
const buttons = Array.from(container.querySelectorAll("[data-tab-button]"));
|
|
|
|
const tabs = Array.from(container.querySelectorAll("[data-tab]"));
|
2021-08-27 17:58:52 +00:00
|
|
|
|
2024-06-24 18:36:50 +00:00
|
|
|
if (!initialTab) {
|
|
|
|
initialTab = tabs[0].getAttribute("data-tab");
|
2021-08-27 17:58:52 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 18:36:50 +00:00
|
|
|
function switchTo(name) {
|
|
|
|
for (const tab of tabs) {
|
|
|
|
tab.hidden = tab.getAttribute("data-tab") !== name;
|
|
|
|
}
|
|
|
|
for (const button of buttons) {
|
|
|
|
button.classList.toggle("tab-button-active", button.getAttribute("data-tab-button") === name);
|
2021-08-27 17:58:52 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-24 18:36:50 +00:00
|
|
|
switchTo(initialTab);
|
2021-08-27 17:58:52 +00:00
|
|
|
|
2024-06-24 18:36:50 +00:00
|
|
|
for (const button of buttons) {
|
|
|
|
button.addEventListener("click", () => {
|
|
|
|
switchTo(button.getAttribute("data-tab-button"));
|
|
|
|
});
|
2021-08-27 17:58:52 +00:00
|
|
|
}
|
2021-11-25 03:59:51 +00:00
|
|
|
}
|