Skip to content

Commit 6515979

Browse files
committed
automatically set the height of the tabs across the languages
1 parent 745ff0f commit 6515979

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

website_and_docs/layouts/shortcodes/tabpane.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<!-- Scratchpad gets populated through call to .Inner -->
3131
{{- .Inner -}}
3232

33-
<ul class="nav nav-tabs" id="tabs-{{- $.Ordinal -}}" role="tablist">
33+
<ul class="nav nav-tabs{{ if $persistLang }} persist{{ end }}" id="tabs-{{- $.Ordinal -}}" role="tablist">
3434
{{- range $index, $element := $.Scratch.Get "tabs" -}}
3535

3636
{{- $lang := $langPane -}}
@@ -75,7 +75,7 @@
7575
{{ $activeSet = false }}
7676

7777
<!-- Inner content -->
78-
<div class="tab-content" id="tabs-{{- $.Ordinal -}}-content">
78+
<div class="tab-content{{ if $persistLang }} persist{{ end }}" id="tabs-{{- $.Ordinal -}}-content">
7979
{{- range $index, $element := $.Scratch.Get "tabs" -}}
8080

8181
{{- $lang := $langPane -}}

website_and_docs/static/js/tabpane-persist.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,35 @@ if (typeof Storage !== 'undefined') {
1010
activeLanguage = params.language;
1111
localStorage.setItem('active_language', activeLanguage);
1212
}
13-
if (activeLanguage) {
13+
var tabContents = document.querySelectorAll('.tab-content.persist');
14+
if (activeLanguage && tabContents.length > 1) {
15+
const persistTab = document.querySelector('ul.persist').querySelectorAll('.nav-link');
16+
var heightMap = {};
17+
18+
// select each persist tab and store calculated heights
19+
persistTab.forEach((langTab) => {
20+
langTab.click();
21+
tabContents.forEach((tabContent) => {
22+
heightMap[tabContent.id] ||= [];
23+
heightMap[tabContent.id].push(tabContent.clientHeight);
24+
})
25+
// everything ends up active unless classes removed
26+
document.querySelectorAll('.active.show').forEach((activeTab) => {
27+
activeTab.classList.remove('active');
28+
activeTab.classList.remove('show');
29+
})
30+
})
31+
// need to make something active/shown again
32+
persistTab[0].click();
33+
34+
tabContents.forEach((tabContent) => {
35+
tabContent.style.height = Math.max.apply( Math, heightMap[tabContent.id]).toString() + 'px';
36+
})
37+
1438
document
1539
.querySelectorAll('.persistLang-' + activeLanguage)
1640
.forEach((element) => {
17-
$('#' + element.id).tab('show');
41+
element.click();
1842
});
1943
}
2044
}

0 commit comments

Comments
 (0)