|
1 | 1 | <link rel="icon" href="{{ '/assets/images/favicon.svg' | relative_url }}" type="image/svg+xml"> |
2 | 2 |
|
| 3 | +<!-- Determine theme before loading stylesheets --> |
| 4 | +<script> |
| 5 | + var jtdTheme = localStorage.getItem('jtd-theme') || 'light'; |
| 6 | + document.documentElement.setAttribute('data-theme', jtdTheme); |
| 7 | +</script> |
| 8 | + |
| 9 | +<!-- Theme stylesheets - disabled state set dynamically --> |
| 10 | +<link rel="stylesheet" href="{{ '/assets/css/just-the-docs-light.css' | relative_url }}" id="jtd-light"> |
| 11 | +<link rel="stylesheet" href="{{ '/assets/css/just-the-docs-dark.css' | relative_url }}" id="jtd-dark"> |
| 12 | +<script> |
| 13 | + (function() { |
| 14 | + var isDark = jtdTheme === 'dark'; |
| 15 | + document.getElementById('jtd-light').disabled = isDark; |
| 16 | + document.getElementById('jtd-dark').disabled = !isDark; |
| 17 | + })(); |
| 18 | + |
| 19 | + function toggleTheme() { |
| 20 | + var current = document.documentElement.getAttribute('data-theme') || 'light'; |
| 21 | + var newTheme = current === 'light' ? 'dark' : 'light'; |
| 22 | + |
| 23 | + document.documentElement.setAttribute('data-theme', newTheme); |
| 24 | + |
| 25 | + var lightCss = document.getElementById('jtd-light'); |
| 26 | + var darkCss = document.getElementById('jtd-dark'); |
| 27 | + var isDark = newTheme === 'dark'; |
| 28 | + if (lightCss) lightCss.disabled = isDark; |
| 29 | + if (darkCss) darkCss.disabled = !isDark; |
| 30 | + |
| 31 | + try { |
| 32 | + localStorage.setItem('jtd-theme', newTheme); |
| 33 | + } catch (e) {} |
| 34 | + } |
| 35 | +</script> |
| 36 | + |
| 37 | +<style> |
| 38 | + .theme-toggle { |
| 39 | + background: none; |
| 40 | + border: none; |
| 41 | + cursor: pointer; |
| 42 | + padding: 4px 8px; |
| 43 | + font-size: 1.1rem; |
| 44 | + color: var(--link-color); |
| 45 | + vertical-align: middle; |
| 46 | + margin-right: 0.5rem; |
| 47 | + } |
| 48 | + .theme-toggle:hover { |
| 49 | + opacity: 0.7; |
| 50 | + } |
| 51 | + /* Show correct icon based on theme */ |
| 52 | + .icon-sun { display: none; } |
| 53 | + .icon-moon { display: inline; } |
| 54 | + [data-theme="dark"] .icon-sun { display: inline; } |
| 55 | + [data-theme="dark"] .icon-moon { display: none; } |
| 56 | +</style> |
0 commit comments