2023-05-07 22:39:34 +02:00
|
|
|
TabContainer = {
|
2024-02-16 22:49:06 +01:00
|
|
|
initTabGroups() {
|
|
|
|
const groups = document.querySelectorAll(".tab-group");
|
|
|
|
const unloadedGroups = [...groups].filter((g) => !g.initialised);
|
|
|
|
unloadedGroups.forEach((group) => {
|
|
|
|
const containers = group.querySelectorAll(".tab-container");
|
|
|
|
const tabTitles = [...containers].map((c) => c.getAttribute("title"));
|
2024-02-11 17:47:00 +01:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
const tabList = document.createElement("div");
|
|
|
|
tabList.classList.add("tab-buttons");
|
|
|
|
tabTitles.forEach((title) => {
|
|
|
|
const tabButton = document.createElement("button");
|
|
|
|
tabButton.innerHTML = title;
|
|
|
|
tabButton.onclick = (e) => {
|
|
|
|
this.setActiveTab(e.target);
|
|
|
|
};
|
|
|
|
tabList.appendChild(tabButton);
|
|
|
|
});
|
|
|
|
group.prepend(tabList);
|
2023-05-07 22:39:34 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
this.setActiveTab(tabList.firstChild);
|
2023-05-07 22:39:34 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
group.initialised = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setActiveTab(tabButton) {
|
|
|
|
const group = tabButton.closest(".tab-group");
|
2023-05-07 22:39:34 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
group.querySelectorAll(".active").forEach((el) => el.classList.remove("active"));
|
2023-05-07 22:39:34 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
tabButton.classList.add("active");
|
|
|
|
group.querySelector(`[title="${tabButton.innerHTML}"]`).classList.add("active");
|
|
|
|
},
|
|
|
|
};
|
2023-05-07 22:39:34 +02:00
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2024-02-16 22:49:06 +01:00
|
|
|
TabContainer.initTabGroups();
|
|
|
|
});
|