summary refs log tree commit diff stats
path: root/nimdoc/rst2html
diff options
context:
space:
mode:
authorSebastian Reinhard <sebastian@sebbert.me>2020-12-06 10:13:19 +0100
committerGitHub <noreply@github.com>2020-12-06 10:13:19 +0100
commit93b6fac46888df89bbed86daf097360fa03d9ebb (patch)
tree1c4afc5f92b8fe19898726f6793e4dace74f94b9 /nimdoc/rst2html
parent1e320bc8c5112b152ebc3092331b8b1fe0ae5191 (diff)
downloadNim-93b6fac46888df89bbed86daf097360fa03d9ebb.tar.gz
nimdoc: Initialize theme switch and pragma dots on DOMContentLoaded (#16247)
The default HTML template for nimdoc currently initializes the dark mode switch and pragma dots when the onload event is fired. But since the onload event does not fire until all external resources (images, stylesheets, fonts, etc.) have been loaded, the light theme is shown for a brief moment before the document is fully loaded, and it switches to the dark theme. This is quite jarring, especially on slower internet connections. So let's instead initialize these things on the DOMContentLoaded event, which is fired right after the document has been parsed and the initial DOM structure is ready. This means that we now display the dark mode immediately, without having to wait for external resources to load first.

For reference, see:
- https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event
- https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event

I have updated the snapshot tests in `nimdoc/`, and done some manual testing of both the theme switch and the pragma dots, to confirm that this does not break anything. Please let me know if I've missed anything.
Diffstat (limited to 'nimdoc/rst2html')
-rw-r--r--nimdoc/rst2html/expected/rst_examples.html4
1 files changed, 3 insertions, 1 deletions
diff --git a/nimdoc/rst2html/expected/rst_examples.html b/nimdoc/rst2html/expected/rst_examples.html
index 8a08e8df5..0b9207688 100644
--- a/nimdoc/rst2html/expected/rst_examples.html
+++ b/nimdoc/rst2html/expected/rst_examples.html
@@ -56,10 +56,12 @@ function main() {
     }
   }
 }
+
+window.addEventListener('DOMContentLoaded', main);
 </script>
 
 </head>
-<body onload="main()">
+<body>
 <div class="document" id="documentId">
   <div class="container">
     <h1 class="title">Not a Nim Manual</h1>