Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,31 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="fragment" content="!">
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico" />
<link rel="stylesheet" href="mdwiki/extlib/css/darkmode.css">
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space here.

<script>

const docElem = document.documentElement;
const localStorageKey = 'mdwiki-dark-mode';

const savedDarkModePreference = localStorage.getItem(localStorageKey);
let shouldBeDark = false;

if (savedDarkModePreference === 'true') {
shouldBeDark = true;
} else if (savedDarkModePreference === null) {

if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
shouldBeDark = true;
}
}


if (shouldBeDark) {
docElem.classList.add('dark-mode');
}
</script>
<style type="text/css">
/* hide the main content while we assemble everything */
.md-hidden-load { display: none; }
Expand Down Expand Up @@ -260,6 +284,78 @@

</head>
<body>
<button id="darkModeToggle"
style="position: fixed; top: 6px; right: 60px; z-index: 9999; border-radius: 100px; padding: 10px 10px; cursor: pointer; font-size: 18px; transition: all 0.3s ease;border:none">
<span id="toggleIcon">🌙</span>
</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Copy link
Member

@paulbert paulbert Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate script addition, let's remove this one and keep the one in <head>.


<script>
$(document).ready(function () {
var $html = $('html');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you use this reference for checking if dark mode is set in code, and the body class is used in CSS. I think it'd be a little cleaner to just apply the dark-mode class once.

var $body = $('body');
var $navbar = $('#md-main-navbar');
var $darkModeToggleBtn = $('#darkModeToggle');
var $darkModeToggleNavbarLink = $('#darkModeToggleNavbar');
var $toggleIcon = $('#toggleIcon');
var localStorageKey = 'mdwiki-dark-mode';


function setDarkMode(isDark) {

if (isDark) {
$html.addClass('dark-mode');
$body.addClass('dark-mode');
$navbar.removeClass('navbar-default').addClass('navbar-inverse');
$darkModeToggleBtn.css({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to move this to the CSS.

'background-color': '#002f4a',
});
$toggleIcon.text('☀️');
} else {
$html.removeClass('dark-mode');
$body.removeClass('dark-mode');
$navbar.removeClass('navbar-inverse').addClass('navbar-default');
$darkModeToggleBtn.css({
'background-color': '#2c3f51',
});
$toggleIcon.text('🌙');
}
localStorage.setItem(localStorageKey, isDark);
}



var initialIsDark = $html.hasClass('dark-mode');
setDarkMode(initialIsDark);

$darkModeToggleBtn.on('click', function () {

setDarkMode(!$html.hasClass('dark-mode'));
});


$darkModeToggleNavbarLink.on('click', function (e) {
e.preventDefault();
setDarkMode(!$html.hasClass('dark-mode'));
});
$darkModeToggleBtn.hover(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be doable with CSS, also.

function () {
if ($html.hasClass('dark-mode')) {
$(this).css('background-color', '#004a75');
} else {
$(this).css('background-color', '#1A252E');
}
},
function () {
if ($html.hasClass('dark-mode')) {
$(this).css('background-color', '#002f4a');
} else {
$(this).css('background-color', '#2c3f51');
}
}
);
});
</script>
<noscript>
This website requires Javascript to be enabled. Please turn on Javascript
and reload the page.
Expand Down
57 changes: 57 additions & 0 deletions mdwiki/extlib/css/darkmode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
body.dark-mode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a semantic comment, but since this isn't an external library let's put this in a new mdwiki/css/ directory

background-color: #1a1a1a;
color: #bbbbbb;
}

body.dark-mode .navbar {
background-color: #002f4a;
border-color: #444;
}

body.dark-mode .navbar a {
color: #bbbbbb;
}

body.dark-mode .panel,
body.dark-mode .well {
background-color: #282828;
border-color: #444;
color: #e0e0e0;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
color: #bbbbbb;
}

body.dark-mode .mdle {
background-color: #000000;
}

body.dark-mode .dropdown-menu {
background-color: #000000;
}

body.dark-mode .list-group-item {
background-color: #1a1a1a;
}

body.dark-mode .dropdown-open {
background-color: #006fb1;
}

body.dark-mode .panel.panel-default {
border: solid;
border-width: 1.8px;
border-color: gray;
}

body.dark-mode .list-group-item {
border: solid;
border-width: 1.8px;
border-color: gray;
}