Skip to content

Commit

Permalink
style(cdviz-site): basic autodetection of drack mode (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Nov 22, 2024
1 parent 1addb82 commit 8d7d7b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
15 changes: 15 additions & 0 deletions cdviz-site/landingpage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
- partners
- investors
-->
<script>
function initColorScheme() {
// It's best to inline this in `head` to reduce (doesn't avoid completly) FOUC (flash of unstyled content) when changing pages or themes
if (
localStorage.getItem("color-scheme") === "dark" ||
(!("color-scheme" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}
initColorScheme();
</script>
</head>

<body class="mx-auto max-w-6xl bg-background font-body text-text">
Expand Down
13 changes: 0 additions & 13 deletions cdviz-site/landingpage/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,4 @@ function selectHeroImage() {
heroImage.src = `./assets/illustrations/hero-${randomInt}.webp`;
}

function initColorMode() {
// It's best to inline this in `head` to avoid FOUC (flash of unstyled content) when changing pages or themes
if (
localStorage.getItem("color-theme") === "dark" ||
(!("color-theme" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}
initColorMode();
selectHeroImage();

0 comments on commit 8d7d7b8

Please sign in to comment.