Skip to content
Snippets Groups Projects
Commit 2210d085 authored by Michael Long's avatar Michael Long
Browse files

darkmode can be disabled in modopts.ini, and darkmode will use macos...

darkmode can be disabled in modopts.ini, and darkmode will use macos preferences if not set previously
parent 13ae760a
No related branches found
No related tags found
2 merge requests!463MRC mods by Codefenix (2024-10-20),!68dark mode for webv4
...@@ -174,3 +174,5 @@ ...@@ -174,3 +174,5 @@
forum_extended_ascii=false forum_extended_ascii=false
max_messages=0 max_messages=0
nodelist_ibbs = true nodelist_ibbs = true
darkmode_off=false
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<?xjs if (!settings.darkmode_off) { ?>
<li class="nav-item dark-switch"> <li class="nav-item dark-switch">
<div class="form-group"> <div class="form-group">
<div class="checkbox checbox-switch darkswitchbox"> <div class="checkbox checbox-switch darkswitchbox">
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
</div> </div>
</div> </div>
</li> </li>
<?xjs } ?>
<?xjs if (user.alias === settings.guest || user.number < 1) { ?> <?xjs if (user.alias === settings.guest || user.number < 1) { ?>
<?xjs if (settings.user_registration) { ?> <?xjs if (settings.user_registration) { ?>
<li> <li>
......
...@@ -56,7 +56,9 @@ ...@@ -56,7 +56,9 @@
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet"> <link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="./css/offcanvas.css" rel="stylesheet"> <link href="./css/offcanvas.css" rel="stylesheet">
<link href="./css/style.css" rel="stylesheet"> <link href="./css/style.css" rel="stylesheet">
<?xjs if (!settings.darkmode_off) { ?>
<link href="./css/checkbox.css" rel="stylesheet"> <link href="./css/checkbox.css" rel="stylesheet">
<?xjs } ?>
<? if (file_exists(settings.web_root + 'css/custom.css')) { ?> <? if (file_exists(settings.web_root + 'css/custom.css')) { ?>
<link href="./css/custom.css" rel="stylesheet"> <link href="./css/custom.css" rel="stylesheet">
<? } ?> <? } ?>
......
...@@ -91,18 +91,22 @@ function registerEventListener(scope, callback, params) { ...@@ -91,18 +91,22 @@ function registerEventListener(scope, callback, params) {
}; };
} }
document.addEventListener("DOMContentLoaded", function(){ document.addEventListener("DOMContentLoaded", function () {
// originally based on dark-mode-switch by Christian Oliff // originally based on dark-mode-switch by Christian Oliff
var darkSwitch = document.getElementById("darkSwitch"); var darkSwitch = document.getElementById("darkSwitch");
if (darkSwitch) { if (darkSwitch) {
initTheme(); initTheme();
darkSwitch.addEventListener("change", function(event) { darkSwitch.addEventListener("change", function (event) {
resetTheme(); resetTheme();
}); });
function initTheme() { function initTheme() {
var darkThemeSelected = var darkThemeSelected;
localStorage.getItem("darkSwitch") !== null && if (localStorage.getItem("darkSwitch") !== null) {
localStorage.getItem("darkSwitch") === "dark"; darkThemeSelected = localStorage.getItem("darkSwitch") === "dark";
} else {
darkThemeSelected = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
}
darkSwitch.checked = darkThemeSelected; darkSwitch.checked = darkThemeSelected;
if (darkThemeSelected) { if (darkThemeSelected) {
jQuery("body").addClass("dark") jQuery("body").addClass("dark")
...@@ -110,13 +114,14 @@ document.addEventListener("DOMContentLoaded", function(){ ...@@ -110,13 +114,14 @@ document.addEventListener("DOMContentLoaded", function(){
jQuery("body").removeClass("dark"); jQuery("body").removeClass("dark");
} }
} }
function resetTheme() { function resetTheme() {
if (darkSwitch.checked) { if (darkSwitch.checked) {
jQuery("body").addClass("dark"); jQuery("body").addClass("dark");
localStorage.setItem("darkSwitch", "dark"); localStorage.setItem("darkSwitch", "dark");
} else { } else {
jQuery("body").removeClass("dark"); jQuery("body").removeClass("dark");
localStorage.removeItem("darkSwitch"); localStorage.setItem("darkSwitch", "light");
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment