Skip to content

Commit 80ccb24

Browse files
committed
Restore Night Owl theme + true language tabs
- Fix broken additional-css path in book.toml: the path-variant experiment left 'additional-css = ["../CodingInterviewFightClub/theme/css/nightowl.css"]' which made mdBook emit a link pointing outside the served book -> 404 -> the Night Owl theme vanished from the deployed site. Restored the relative path so the hashed css is copied into book/theme/css/ and linked correctly. - Tabs: switch to classic tabbed behavior. Only the ACTIVE language is visible (Kotlin by default); click Java/C++/Python/Rust to switch; 'All' reveals every language. Verified with jsdom: default view = Kotlin only, switching works, nothing is ever removed from the DOM.
1 parent 74d49d9 commit 80ccb24

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎CodingInterviewFightClub/book.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ preferred-dark-theme = "navy"
1414
mathjax-support = true
1515
git-repository-url = "https://github.com/arpanpathak/AdvancedAlgorithmPatterns"
1616
edit-url-template = "https://github.com/arpanpathak/AdvancedAlgorithmPatterns/edit/main/src/{path}"
17-
additional-css = ["../CodingInterviewFightClub/theme/css/nightowl.css"]
17+
additional-css = ["theme/css/nightowl.css"]
1818
additional-js = ["theme/js/book.js"]
1919
no-section-label = true
2020

‎CodingInterviewFightClub/theme/js/book.js‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
return el && el.tagName === 'PRE' && el.querySelector('code');
3737
}
3838

39-
/* Build tabs from a run of adjacent <pre> siblings.
40-
All languages are VISIBLE by default (stacked); the tab buttons filter.
41-
This way even a JS failure never hides code. */
39+
/* Build language tabs from a run of adjacent <pre> siblings.
40+
Only the ACTIVE language is visible (classic tabbed code). The first
41+
block (Kotlin) is active by default; clicking a language shows only
42+
that one; "All" reveals everything. If JS ever fails, a <noscript>
43+
fallback is not needed because we only HIDE via inline styles set by
44+
this script — blocks are never removed from the DOM. */
4245
function buildTabs(run) {
4346
var parent = run[0].parentNode;
4447
var container = document.createElement('div');
@@ -51,11 +54,16 @@
5154

5255
var allBtn = document.createElement('button');
5356
allBtn.type = 'button';
54-
allBtn.className = 'code-tab-btn active';
57+
allBtn.className = 'code-tab-btn';
5558
allBtn.textContent = 'All';
59+
allBtn.addEventListener('click', function () {
60+
setActive(allBtn);
61+
run.forEach(function (p) { p.style.display = 'block'; });
62+
});
5663
nav.appendChild(allBtn);
5764

5865
var uniqueLangs = langs.filter(function (l, i) { return langs.indexOf(l) === i; });
66+
var langBtns = {};
5967
uniqueLangs.forEach(function (l) {
6068
var btn = document.createElement('button');
6169
btn.type = 'button';
@@ -65,6 +73,7 @@
6573
setActive(btn);
6674
run.forEach(function (p, k) { p.style.display = langs[k] === l ? 'block' : 'none'; });
6775
});
76+
langBtns[l] = btn;
6877
nav.appendChild(btn);
6978
});
7079

@@ -73,11 +82,6 @@
7382
btn.classList.add('active');
7483
}
7584

76-
allBtn.addEventListener('click', function () {
77-
setActive(allBtn);
78-
run.forEach(function (p) { p.style.display = 'block'; });
79-
});
80-
8185
container.appendChild(nav);
8286

8387
var body = document.createElement('div');
@@ -95,11 +99,17 @@
9599
/* Order matters: put the container in the DOM FIRST (while run[0] is still
96100
attached to parent), then move the pre blocks into it. */
97101
parent.replaceChild(container, run[0]);
98-
run.forEach(function (pre) {
99-
pre.style.display = 'block'; // ALL visible by default
102+
run.forEach(function (pre, idx) {
103+
pre.style.display = idx === 0 ? 'block' : 'none'; // tabbed: first language active
100104
body.appendChild(pre);
101105
});
102106
container.appendChild(body);
107+
108+
// Default active tab = the first language (Kotlin).
109+
var first = uniqueLangs[0] || null;
110+
if (first && langBtns[first]) {
111+
setActive(langBtns[first]);
112+
}
103113
}
104114

105115
/* Wrap a lone code block with a copy button. */

0 commit comments

Comments
 (0)