Skip to content

Commit 648257a

Browse files
Add javascript dark toggle mode (#308)
Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
1 parent e58fa36 commit 648257a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

assets/js/dark.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************************************************
2+
* Theme interaction
3+
*/
4+
5+
var prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
6+
7+
/**
8+
* set the the body theme to the one specified by the user browser
9+
*
10+
* @param {event} e
11+
*/
12+
function autoTheme(e) {
13+
targetTheme = prefersDark.matches ? "dark" : "light";
14+
document.documentElement.setAttribute("data-theme", targetTheme);
15+
}
16+
17+
autoTheme();
18+
prefersDark.onchange = autoTheme;

0 commit comments

Comments
 (0)