1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-12-04 10:24:42 +02:00

fix darkmode toggle

This commit is contained in:
FreddleSpl0it 2022-12-16 09:40:20 +01:00
parent 5160eff294
commit f1bb23ba2a
3 changed files with 6 additions and 6 deletions

View File

@ -304,13 +304,13 @@ $(document).ready(function() {
$('#dark-mode-toggle').prop('checked', false);
if ($('#rspamd_logo').length) $('#rspamd_logo').attr('src', '/img/rspamd_logo_dark.png');
if ($('#rspamd_logo_sm').length) $('#rspamd_logo_sm').attr('src', '/img/rspamd_logo_dark.png');
localStorage.setItem('darkmode', 'false');
localStorage.setItem('theme', 'light');
}else{
$('head').append('<link id="dark-mode-theme" rel="stylesheet" type="text/css" href="/css/themes/mailcow-darkmode.css">');
$('#dark-mode-toggle').prop('checked', true);
if ($('#rspamd_logo').length) $('#rspamd_logo').attr('src', '/img/rspamd_logo_light.png');
if ($('#rspamd_logo_sm').length) $('#rspamd_logo_sm').attr('src', '/img/rspamd_logo_light.png');
localStorage.setItem('darkmode', 'true');
localStorage.setItem('theme', 'dark');
}
}
});

View File

@ -1,5 +1,5 @@
$(document).ready(function() {
var darkmode = localStorage.getItem("darkmode");
var theme = localStorage.getItem("theme");
localStorage.clear();
localStorage.setItem("darkmode", darkmode);
localStorage.setItem("theme", theme);
});

View File

@ -11,8 +11,8 @@
<link rel="stylesheet" href="{{ css_path }}">
<script>
// check if darkmode is preferred by OS or set by localStorage
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ||
JSON.parse(localStorage.getItem("darkmode")) === true) {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches && localStorage.getItem("theme") !== "light" ||
localStorage.getItem("theme") === "dark") {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = 'dark-mode-theme';