Skip to content

Commit a081364

Browse files
(Fixed) [Feature Request] capability to render tabs from subheading
Fixes jothepro#149
1 parent 28ed396 commit a081364

1 file changed

Lines changed: 57 additions & 52 deletions

File tree

doxygen-awesome-tabs.js

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,61 +29,66 @@ SOFTWARE.
2929

3030
class DoxygenAwesomeTabs {
3131

32-
static init() {
33-
window.addEventListener("load", () => {
34-
document.querySelectorAll(".tabbed:not(:empty)").forEach((tabbed, tabbedIndex) => {
35-
let tabLinkList = []
36-
tabbed.querySelectorAll(":scope > ul > li").forEach((tab, tabIndex) => {
37-
tab.id = "tab_" + tabbedIndex + "_" + tabIndex
38-
let header = tab.querySelector(".tab-title")
39-
let tabLink = document.createElement("button")
40-
tabLink.classList.add("tab-button")
41-
tabLink.appendChild(header)
42-
header.title = header.textContent
43-
tabLink.addEventListener("click", () => {
44-
tabbed.querySelectorAll(":scope > ul > li").forEach((tab) => {
45-
tab.classList.remove("selected")
46-
})
47-
tabLinkList.forEach((tabLink) => {
48-
tabLink.classList.remove("active")
49-
})
50-
tab.classList.add("selected")
51-
tabLink.classList.add("active")
52-
})
53-
tabLinkList.push(tabLink)
54-
if(tabIndex == 0) {
55-
tab.classList.add("selected")
56-
tabLink.classList.add("active")
57-
}
58-
})
59-
let tabsOverview = document.createElement("div")
60-
tabsOverview.classList.add("tabs-overview")
61-
let tabsOverviewContainer = document.createElement("div")
62-
tabsOverviewContainer.classList.add("tabs-overview-container")
63-
tabLinkList.forEach((tabLink) => {
64-
tabsOverview.appendChild(tabLink)
65-
})
66-
tabsOverviewContainer.appendChild(tabsOverview)
67-
tabbed.before(tabsOverviewContainer)
68-
69-
function resize() {
70-
let maxTabHeight = 0
71-
tabbed.querySelectorAll(":scope > ul > li").forEach((tab, tabIndex) => {
72-
let visibility = tab.style.display
73-
tab.style.display = "block"
74-
maxTabHeight = Math.max(tab.offsetHeight, maxTabHeight)
75-
tab.style.display = visibility
76-
})
77-
tabbed.style.height = `${maxTabHeight + 10}px`
32+
static init() {
33+
window.addEventListener("load", () => {
34+
document.querySelectorAll(".tabbed:not(:empty)").forEach((tabbed, tabbedIndex) => {
35+
let tabLinkList = [];
36+
tabbed.querySelectorAll(":scope > .tab-title").forEach((tab, tabIndex) => {
37+
let tabContainer = document.createElement("li");
38+
tabContainer.id = "tab_" + tabbedIndex + "_" + tabIndex;
39+
tab.title = tab.textContent;
40+
41+
let tabLink = document.createElement("button");
42+
tabLink.classList.add("tab-button");
43+
tabLink.appendChild(tab);
44+
45+
tabLink.addEventListener("click", () => {
46+
tabbed.querySelectorAll(":scope > .tab-title").forEach((tab) => {
47+
tab.parentElement.classList.remove("selected");
48+
});
49+
tabLinkList.forEach((tabLink) => {
50+
tabLink.classList.remove("active");
51+
});
52+
tabContainer.classList.add("selected");
53+
tabLink.classList.add("active");
54+
});
55+
56+
tabLinkList.push(tabLink);
57+
if (tabIndex === 0) {
58+
tabContainer.classList.add("selected");
59+
tabLink.classList.add("active");
7860
}
7961

80-
resize()
81-
new ResizeObserver(resize).observe(tabbed)
82-
})
83-
})
84-
85-
}
62+
tabbed.insertBefore(tabContainer, tabbed.querySelector(":scope > ul"));
63+
tabContainer.appendChild(tabLink);
64+
});
65+
66+
let tabsOverview = document.createElement("div");
67+
tabsOverview.classList.add("tabs-overview");
68+
let tabsOverviewContainer = document.createElement("div");
69+
tabsOverviewContainer.classList.add("tabs-overview-container");
70+
tabLinkList.forEach((tabLink) => {
71+
tabsOverview.appendChild(tabLink);
72+
});
73+
tabsOverviewContainer.appendChild(tabsOverview);
74+
tabbed.before(tabsOverviewContainer);
75+
76+
function resize() {
77+
let maxTabHeight = 0;
78+
tabbed.querySelectorAll(":scope > .tab-title").forEach((tab, tabIndex) => {
79+
let visibility = tab.style.display;
80+
tab.style.display = "block";
81+
maxTabHeight = Math.max(tab.offsetHeight, maxTabHeight);
82+
tab.style.display = visibility;
83+
});
84+
tabbed.style.height = `${maxTabHeight + 10}px`;
85+
}
8686

87+
resize();
88+
new ResizeObserver(resize).observe(tabbed);
89+
});
90+
});
91+
}
8792
static resize(tabbed) {
8893

8994
}

0 commit comments

Comments
 (0)