User Theme saved to local storage

The theme will no longer reset to the default on page change or reload.
This commit is contained in:
Corban-Lee Jones 2024-01-23 09:18:31 +00:00
parent 4d7f2ba3ea
commit e342680351

View File

@ -1,15 +1,22 @@
$("#themeToggle").on("click", function() {
const currentTheme = $("body").attr("data-bs-theme");
$(document).ready(function() {
// Activate all tooltips
$('[data-bs-toggle="tooltip"]').tooltip();
if (currentTheme == "light") {
$("body").attr("data-bs-theme", "dark");
// Apply the user preferred theme
const theme = localStorage.getItem("theme");
if (theme == "light" || theme == "dark") {
$("body").attr("data-bs-theme", theme);
}
else {
$("body").attr("data-bs-theme", "light");
}
});
$(document).ready(function() {
// Activate all tooltips
$('[data-bs-toggle="tooltip"]').tooltip();
$("#themeToggle").on("click", function() {
var theme = $("body").attr("data-bs-theme");
theme = theme == "light" ? "dark" : "light";
localStorage.setItem("theme", theme)
$("body").attr("data-bs-theme", theme);
});