Skip to content

Commit 12936e9

Browse files
committed
feat(docs): move theme toggle to navbar
- Theme icon now appears next to GitHub link in top navbar - Uses icons: ◑ (system), ☀ (light), ☾ (dark) - Hover shows current mode in tooltip
1 parent 4dbdee3 commit 12936e9

2 files changed

Lines changed: 70 additions & 38 deletions

File tree

docs/_includes/head_custom.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<style>
2+
.theme-toggle {
3+
cursor: pointer;
4+
padding: 4px 8px;
5+
border: none;
6+
background: transparent;
7+
font-size: 1.2rem;
8+
opacity: 0.7;
9+
transition: opacity 0.2s;
10+
}
11+
.theme-toggle:hover {
12+
opacity: 1;
13+
}
14+
</style>
15+
116
<script>
217
// Apply saved theme on page load (before render to prevent flash)
318
(function() {
@@ -10,4 +25,59 @@
1025
}
1126
document.documentElement.setAttribute('data-theme', theme);
1227
})();
28+
29+
// Add theme toggle to navbar after DOM loads
30+
document.addEventListener('DOMContentLoaded', function() {
31+
var modes = ['system', 'light', 'dark'];
32+
var icons = { system: '\u25D1', light: '\u2600', dark: '\u263E' };
33+
var titles = { system: 'Theme: System', light: 'Theme: Light', dark: 'Theme: Dark' };
34+
35+
function getSystemTheme() {
36+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
37+
}
38+
39+
function applyMode(mode, btn) {
40+
var theme = (mode === 'system') ? getSystemTheme() : mode;
41+
jtd.setTheme(theme);
42+
btn.textContent = icons[mode];
43+
btn.title = titles[mode];
44+
localStorage.setItem('theme-mode', mode);
45+
}
46+
47+
// Create toggle button
48+
var btn = document.createElement('button');
49+
btn.className = 'theme-toggle';
50+
btn.setAttribute('aria-label', 'Toggle theme');
51+
52+
// Initialize
53+
var currentMode = localStorage.getItem('theme-mode') || 'system';
54+
btn.textContent = icons[currentMode];
55+
btn.title = titles[currentMode];
56+
57+
// Insert into aux nav
58+
var auxNav = document.querySelector('.site-nav, .aux-nav');
59+
if (auxNav) {
60+
var auxList = auxNav.querySelector('ul');
61+
if (auxList) {
62+
var li = document.createElement('li');
63+
li.className = 'aux-nav-item';
64+
li.appendChild(btn);
65+
auxList.appendChild(li);
66+
}
67+
}
68+
69+
// Listen for system preference changes
70+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function() {
71+
if (localStorage.getItem('theme-mode') === 'system') {
72+
jtd.setTheme(getSystemTheme());
73+
}
74+
});
75+
76+
// Cycle through modes on click
77+
btn.addEventListener('click', function() {
78+
var current = localStorage.getItem('theme-mode') || 'system';
79+
var nextIndex = (modes.indexOf(current) + 1) % modes.length;
80+
applyMode(modes[nextIndex], btn);
81+
});
82+
});
1383
</script>

docs/_includes/nav_footer_custom.html

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)