Skip to content

Commit

Permalink
Add javascript dark toggle mode (#308)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
  • Loading branch information
jarrodmillman and stefanv authored Oct 24, 2023
1 parent e58fa36 commit 648257a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions assets/js/dark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Theme interaction
*/

var prefersDark = window.matchMedia("(prefers-color-scheme: dark)");

/**
* set the the body theme to the one specified by the user browser
*
* @param {event} e
*/
function autoTheme(e) {
targetTheme = prefersDark.matches ? "dark" : "light";
document.documentElement.setAttribute("data-theme", targetTheme);
}

autoTheme();
prefersDark.onchange = autoTheme;

0 comments on commit 648257a

Please sign in to comment.