Toggle light and dark modes + header color

This commit is contained in:
William Bouzourène 2025-01-17 00:05:34 +01:00
parent b1f7777c3e
commit 150c289741
6 changed files with 118 additions and 10 deletions

View file

@ -3,5 +3,58 @@ $(document).ready(function() {
if(!confirm("Êtes-vous sûr ?")) {
e.preventDefault();
}
})
});
});
$(document).ready(function() {
$(".toggle-dark-mode").on("click", function() {
var currentState = $("html").attr("data-bs-theme");
var newState = "dark";
if (currentState === "dark") {
newState = "light";
}
setColorMode(newState);
});
});
$(document).ready(function() {
var currentState = $("html").attr("data-bs-theme");
var storedState = localStorage.getItem("color-mode");
if (storedState && storedState !== currentState) {
return setColorMode(storedState);
}
if (currentState === "auto") {
var newState = "light";
if (
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
) {
newState = "dark";
}
return setColorMode(newState);
}
});
function setColorMode(color) {
if (color == "dark") {
$(".toggle-dark-mode").children("i").removeClass("bi-moon");
$(".toggle-dark-mode").children("i").addClass("bi-sun");
} else {
$(".toggle-dark-mode").children("i").removeClass("bi-sun");
$(".toggle-dark-mode").children("i").addClass("bi-moon");
}
$("html").attr("data-bs-theme", color);
localStorage.setItem("color-mode", color);
$.post("/set-color-mode", {color_mode: color});
}
$(document).ready(function() {
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
});