Skip to content

Commit f34a201

Browse files
author
rakeshAlgo
committed
tabset functionality fixes for multiple tabset
1 parent edbd627 commit f34a201

File tree

2 files changed

+86
-56
lines changed

2 files changed

+86
-56
lines changed

src/css/doc.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ table.tableblock pre code.language-bash.hljs {
769769

770770
.doc .tabs.ulist {
771771
margin-top: 0;
772+
padding-left: 0;
772773
}
773774

774775
.doc .tabs ul {
@@ -999,6 +1000,10 @@ table.tableblock pre code.language-bash.hljs {
9991000
display: block;
10001001
}
10011002

1003+
.other-tab-box.desktop-hide {
1004+
display: none;
1005+
}
1006+
10021007
/* Media css */
10031008

10041009
@media screen and (max-width: 767px) {
@@ -1029,6 +1034,10 @@ table.tableblock pre code.language-bash.hljs {
10291034
font-size: var(--heading-h4-sm);
10301035
}
10311036

1037+
.other-tab-box.desktop-hide {
1038+
display: block;
1039+
}
1040+
10321041
.doc .admonitionblock td.content {
10331042
padding-left: 1rem;
10341043
}

src/js/05-tabset.js

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,115 @@
11
var hash = window.location.hash
22
var queueData = []
33
var checkActiveClass
4-
var tabOnLargeScreen = 3 // Display tab on desktop
4+
var tabOnLargeScreen = 5 // Display tab on desktop
55
var tabOnSmallScreen = 1 // display tab on mobile view bewlow 768px screen
66
var smallBreak = 768 // Your small screen breakpoint in pixels
77
find('.doc .tabset').forEach(function (tabset) {
88
var active
99
var tabs = tabset.querySelector('.tabs')
1010
if (tabs) {
1111
var first
12-
find('li', tabs).forEach(function (tab, idx) {
13-
var id = (tab.querySelector('a[id]') || tab).id
14-
checkActiveClass = setTimeout(function () {
15-
var activeTabList = tab.classList.contains('is-active')
16-
if (activeTabList) {
17-
document.querySelector('.tabs').insertAdjacentHTML(
18-
'beforeend',
19-
/*eslint max-len: ["error", { "code": 180 }]*/
20-
'<div class="other-tab-box"><a href="#" class="dropddown-btn dropdown-btn-down">More... </a> <ul class="other-tablist" id="otherTabList"></ul></div>'
21-
)
22-
var dropdownBtn = document.querySelector('.dropdown-btn-down')
23-
var dropdownMenu = document.querySelector('.tabs .other-tablist')
24-
dropdownBtn.addEventListener('click', function (e) {
25-
e.preventDefault()
26-
if (dropdownMenu.style.display === 'block' || dropdownMenu.classList.contains('show')) {
27-
dropdownMenu.classList.remove('show')
28-
dropdownMenu.classList.add('hide')
29-
} else {
30-
dropdownMenu.classList.add('show')
31-
dropdownMenu.classList.remove('hide')
12+
find('ul', tabs).forEach(function (ulTabSet, id) {
13+
if (ulTabSet) {
14+
find('li', ulTabSet).forEach(function (tab, idx) {
15+
var id = (tab.querySelector('a[id]') || tab).id
16+
17+
if (window.innerWidth < smallBreak) {
18+
if (idx > tabOnSmallScreen - 1) {
19+
queueData.push(tab)
3220
}
33-
})
34-
}
35-
}, 100)
36-
if (window.innerWidth < smallBreak) {
37-
if (idx > tabOnSmallScreen - 1) {
38-
queueData.push(tab)
39-
}
40-
} else {
41-
if (idx > tabOnLargeScreen - 1) {
42-
queueData.push(tab)
43-
}
44-
}
21+
} else {
22+
if (idx > tabOnLargeScreen - 1) {
23+
queueData.push(tab)
24+
}
25+
}
26+
27+
checkActiveClass = setTimeout(function () {
28+
var activeTabList = tab.classList.contains('is-active')
4529

46-
if (!id) return
47-
var pane = getPane(id, tabset)
48-
if (!idx) first = { tab: tab, pane: pane }
49-
if (!active && hash === '#' + id && (active = true)) {
50-
tab.classList.add('is-active')
51-
if (pane) pane.classList.add('is-active')
52-
} else if (!idx) {
53-
tab.classList.remove('is-active')
54-
if (pane) pane.classList.remove('is-active')
30+
if (activeTabList) {
31+
if (queueData.length > 0) {
32+
if (window.innerWidth > smallBreak && (tab.parentNode.childElementCount > tabOnLargeScreen - 1)) {
33+
tab.parentNode.parentNode.insertAdjacentHTML(
34+
'beforeend',
35+
/*eslint max-len: ["error", { "code": 180 }]*/
36+
'<div class="other-tab-box"><a href="#" class="dropddown-btn dropdown-btn-down">More... </a> <ul class="other-tablist"></ul></div>'
37+
)
38+
} else {
39+
tab.parentNode.parentNode.insertAdjacentHTML(
40+
'beforeend',
41+
/*eslint max-len: ["error", { "code": 180 }]*/
42+
'<div class="other-tab-box desktop-hide"><a href="#" class="dropddown-btn dropdown-btn-down">More... </a> <ul class="other-tablist"></ul></div>'
43+
)
44+
}
45+
var dropdownBtn = tab.parentNode.parentNode.querySelector('.dropdown-btn-down')
46+
var dropdownMenu = tab.parentNode.parentNode.querySelector('.tabs .other-tablist')
47+
dropdownBtn.addEventListener('click', function (e) {
48+
console.log(e, 'enter')
49+
e.preventDefault()
50+
if (dropdownMenu.style.display === 'block' || dropdownMenu.classList.contains('show')) {
51+
dropdownMenu.classList.remove('show')
52+
dropdownMenu.classList.add('hide')
53+
} else {
54+
dropdownMenu.classList.add('show')
55+
dropdownMenu.classList.remove('hide')
56+
}
57+
})
58+
}
59+
}
60+
}, 40)
61+
62+
if (!id) return
63+
var pane = getPane(id, tabset)
64+
if (!idx) first = { tab: tab, pane: pane }
65+
if (!active && hash === '#' + id && (active = true)) {
66+
tab.classList.add('is-active')
67+
if (pane) pane.classList.add('is-active')
68+
} else if (!idx) {
69+
tab.classList.remove('is-active')
70+
if (pane) pane.classList.remove('is-active')
71+
}
72+
tab.addEventListener('click', activateTab.bind({ tabset: tabset, tab: tab, pane: pane }))
73+
})
5574
}
56-
tab.addEventListener('click', activateTab.bind({ tabset: tabset, tab: tab, pane: pane }))
5775
})
76+
5877
if (!active && first) {
5978
first.tab.classList.add('is-active')
6079
if (first.pane) first.pane.classList.add('is-active')
6180
}
6281
}
6382

64-
setTimeout(function () {
65-
var appendMoreTabList = document.getElementById('otherTabList')
66-
67-
queueData.forEach(function (tablist) {
68-
appendMoreTabList.appendChild(tablist)
69-
})
70-
}, 100)
7183
tabset.classList.remove('is-loading')
7284
clearTimeout(checkActiveClass, 20000)
7385
})
7486

87+
setTimeout(function () {
88+
if (queueData.length) {
89+
queueData.forEach(function (tablist) {
90+
tablist.parentNode.nextElementSibling.lastElementChild.appendChild(tablist)
91+
})
92+
}
93+
}, 200)
94+
// to activate tabset
7595
function activateTab (e) {
7696
e.preventDefault()
7797
var tab = this.tab
7898
var pane = this.pane
99+
// Moving element from dropdown into tabset list
79100
var tabMenu = document.querySelector('.tabs ul')
80-
var nodeTab = document.querySelector('.tabs > ul')
81-
var nodeDropdownTabNode = document.querySelector('.other-tablist')
101+
var nodeTab = tab.parentNode.parentNode.parentNode.querySelector('.tabs > ul')
102+
var nodeDropdownTabNode = tab.parentNode
82103
if (tab.parentNode.classList[0] === 'other-tablist') {
83104
nodeDropdownTabNode.appendChild(nodeTab.lastElementChild)
84105
nodeTab.appendChild(tab)
85106
nodeDropdownTabNode.classList.remove('show')
86107
}
87-
var activeTabList = tab.classList.contains('is-active')
88-
if (activeTabList) {
108+
var activeTabListItem = tab.classList.contains('is-active')
109+
if (activeTabListItem) {
89110
tabMenu.classList.remove('show')
90111
}
91-
112+
// for tab active pane
92113
find('.tabs li, .tab-pane', this.tabset).forEach(function (it) {
93114
it === tab || it === pane ? it.classList.add('is-active') : it.classList.remove('is-active')
94115
})
@@ -103,7 +124,7 @@ setTimeout(function () {
103124
e.preventDefault()
104125
})
105126
}
106-
}, 1000)
127+
}, 200)
107128

108129
function getPane (id, tabset) {
109130
return find('.tab-pane', tabset).find(function (it) {

0 commit comments

Comments
 (0)