e4a76e96af
* CSS corrections * HTML corrections * JS corrections * JAVA corrections * remove tab * CSS corrections 2 * JS corrections 2 * back to the roots * max-linie 127 * add slash hr|br * return bootstrap-icons.css * return bootstrap-icons.min.css * return bootstrap.min.css * Update bootstrap-icons.css * Update bootstrap-icons.min.css * Update bootstrap-icons.min.css * Update bootstrap.min.css * CSS corrections * HTML corrections * JS corrections * JAVA corrections * remove tab * CSS corrections 2 * JS corrections 2 * back to the roots * max-linie 127 * add slash hr|br * return bootstrap-icons.css * Update bootstrap-icons.css * Bootstrap CSS * Update prism.css
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
TabContainer = {
|
|
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"));
|
|
|
|
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);
|
|
|
|
this.setActiveTab(tabList.firstChild);
|
|
|
|
group.initialised = true;
|
|
});
|
|
},
|
|
setActiveTab(tabButton) {
|
|
const group = tabButton.closest(".tab-group");
|
|
|
|
group.querySelectorAll(".active").forEach((el) => el.classList.remove("active"));
|
|
|
|
tabButton.classList.add("active");
|
|
group.querySelector(`[title="${tabButton.innerHTML}"]`).classList.add("active");
|
|
},
|
|
};
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
TabContainer.initTabGroups();
|
|
});
|