splitting all js into individual files to comparmentalize and getting rid of onload event (in favour of defer)

This commit is contained in:
Simon Martens
2022-11-15 21:27:27 +01:00
parent e5052dd4ea
commit 5e90e917f1
30 changed files with 771 additions and 809 deletions

30
HaWeb/wwwroot/js/theme.js Normal file
View File

@@ -0,0 +1,30 @@
// Functions for switching theme
const go_to_dark = function () {
localStorage.setItem("theme", "ha-toggledark");
document.documentElement.classList.add("dark");
};
const go_to_bright = function () {
document.documentElement.classList.remove("dark");
localStorage.setItem("theme", "ha-togglebright");
};
// Functions for reading theme settings
const get_theme_settings = function (standard) {
var theme = localStorage.getItem("theme");
if (theme === null) theme = standard;
let toggleSwitch = document.getElementById(theme).click();
};
if (
document.getElementById("ha-togglebright") !== null &&
this.document.getElementById("ha-toggledark") !== null
) {
document
.getElementById("ha-togglebright")
.addEventListener("click", go_to_bright);
document
.getElementById("ha-toggledark")
.addEventListener("click", go_to_dark);
}
get_theme_settings("ha-togglebright");