Skip to content

Commit

Permalink
Docs: initialize theme earlier to avoid flicker
Browse files Browse the repository at this point in the history
Follow-on to aantron#268.
  • Loading branch information
aantron authored and Computer User committed Sep 28, 2023
1 parent 6348203 commit 4c5968c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/web/site/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ window.onscroll = scroll;

/* Theme mode */

var THEME_MODE_KEY = "dream-theme"
var THEME_MODE_KEY = "dream-theme"

function apply_theme(theme) {
if (theme === "light") {
Expand All @@ -73,11 +73,13 @@ function init_theme() {
var default_theme = "dark";
var stored_theme = localStorage.getItem(THEME_MODE_KEY) || default_theme;
apply_theme(stored_theme);
}

function prepare_button() {
var theme_toggle_button = document.querySelector(".toggle-theme-btn");
if (theme_toggle_button) {
theme_toggle_button.addEventListener("click", toggle_theme);
}
}

document.addEventListener("DOMContentLoaded", init_theme);
document.addEventListener("DOMContentLoaded", prepare_button);
4 changes: 4 additions & 0 deletions docs/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
</head>
<body class="index">

<script>
init_theme();
</script>

<header>
<div class="topmost">
<div class="titles">
Expand Down

0 comments on commit 4c5968c

Please sign in to comment.