Skip to content

Commit 6c00ea5

Browse files
authored
automatically set the height of the tabs across the languages (#1157)
1 parent 3336f6d commit 6c00ea5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
11
<!-- Upstream docsy commit — ecd4be87ea48e8e94684e32c925049e9bdf7f127-->
2+
var tabContents = document.querySelectorAll('.tab-content.persist');
3+
if (tabContents.length > 1) {
4+
const persistTab = document.querySelector('ul.persist').querySelectorAll('.nav-link');
5+
var heightMap = {};
6+
7+
// select each persist tab and store calculated heights
8+
persistTab.forEach((langTab) => {
9+
langTab.click();
10+
tabContents.forEach((tabContent) => {
11+
heightMap[tabContent.id] ||= [];
12+
heightMap[tabContent.id].push(tabContent.clientHeight);
13+
})
14+
// everything ends up active unless classes removed
15+
document.querySelectorAll('.active.show').forEach((activeTab) => {
16+
activeTab.classList.remove('active');
17+
activeTab.classList.remove('show');
18+
})
19+
})
20+
// need to make something active/shown again
21+
persistTab[0].click();
22+
23+
tabContents.forEach((tabContent) => {
24+
tabContent.style.height = Math.max.apply(Math, heightMap[tabContent.id]).toString() + 'px';
25+
})
26+
}
27+
228
if (typeof Storage !== 'undefined') {
329
let activeLanguage = localStorage.getItem('active_language');
430

0 commit comments

Comments
 (0)