diff options
author | drtheuns <randall@theuns.org> | 2021-06-07 18:40:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 18:40:09 +0200 |
commit | 51ab7ccec1ffa21cef67f1a75dea889653751cfc (patch) | |
tree | 01682df2b1b150b0592a112cbf6a5c3d6b058c5c /nimdoc/rst2html/expected/rst_examples.html | |
parent | 21f3b8539a2e440f7cb69502721b6c56070e122f (diff) | |
download | Nim-51ab7ccec1ffa21cef67f1a75dea889653751cfc.tar.gz |
Fix JS error on index page and detect dark mode (#18191)
* Fix JS error on index page and detect dark mode The theindex.html page doesn't have a dark mode switch so the main function will error because `toggleSwitch` is not defined. Checks have been added to prevent this from happening. Also add automatic detection of system settings for dark-mode. This could also be done with pure css, but then the dark mode variable declarations would have to be duplicated to work with the switch so I went with this approach. * Fix nimdoc tests * Fix rst2html tests
Diffstat (limited to 'nimdoc/rst2html/expected/rst_examples.html')
-rw-r--r-- | nimdoc/rst2html/expected/rst_examples.html | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/nimdoc/rst2html/expected/rst_examples.html b/nimdoc/rst2html/expected/rst_examples.html index 5c434193e..68b796be7 100644 --- a/nimdoc/rst2html/expected/rst_examples.html +++ b/nimdoc/rst2html/expected/rst_examples.html @@ -34,7 +34,6 @@ function main() { } } - const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'); function switchTheme(e) { if (e.target.checked) { document.documentElement.setAttribute('data-theme', 'dark'); @@ -45,13 +44,19 @@ function main() { } } - toggleSwitch.addEventListener('change', switchTheme, false); + const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'); + if (toggleSwitch !== null) { + toggleSwitch.addEventListener('change', switchTheme, false); + } - const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null; + var currentTheme = localStorage.getItem('theme'); + if (!currentTheme && window.matchMedia('(prefers-color-scheme: dark)').matches) { + currentTheme = 'dark'; + } if (currentTheme) { document.documentElement.setAttribute('data-theme', currentTheme); - if (currentTheme === 'dark') { + if (currentTheme === 'dark' && toggleSwitch !== null) { toggleSwitch.checked = true; } } |