-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.js
27 lines (23 loc) · 1.06 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if (window.CSS && CSS.supports("color", "var(--primary)")) {
var toggleColorMode = function toggleColorMode(e) {
// Switch to Light Mode
if (e.currentTarget.classList.contains("light--hidden")) {
// Sets the custom html attribute
document.documentElement.setAttribute("color-mode", "light"); // Sets the user's preference in local storage
localStorage.setItem("color-mode", "light");
return;
}
/* Switch to Dark Mode
Sets the custom html attribute */
document.documentElement.setAttribute("color-mode", "dark"); // Sets the user's preference in local storage
localStorage.setItem("color-mode", "dark");
}; // Get the buttons in the DOM
var toggleColorButtons = document.querySelectorAll(".color-mode__btn"); // Set up event listeners
toggleColorButtons.forEach(function(btn) {
btn.addEventListener("click", toggleColorMode);
});
} else {
// If the feature isn't supported, then we hide the toggle buttons
var btnContainer = document.querySelector(".color-mode__header");
btnContainer.style.display = "none";
}