Skip to content
Merged
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
25 changes: 22 additions & 3 deletions templates/base.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
</head>
<body>
<script>
var colorSchemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
function getSystemTheme() {
return colorSchemeMediaQuery.matches ? 'dark' : 'light';
}
function getStoredTheme() {
return localStorage.getItem('theme');
}
function getTheme() {
return getStoredTheme() || getSystemTheme();
Comment thread
StanFromIreland marked this conversation as resolved.
}
function applyTheme(t) {
document.documentElement.setAttribute('data-bs-theme', t);
document.documentElement.classList.toggle('dark', t === 'dark');
}
applyTheme(localStorage.getItem('theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'));
applyTheme(getTheme());
</script>
<header>
<nav class="navbar navbar-expand-md fixed-top">
Expand Down Expand Up @@ -136,8 +146,17 @@
window.addEventListener('resize', padnavbar);
document.getElementById('theme-toggle').addEventListener('click', function() {
var next = document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'light' : 'dark';
localStorage.setItem('theme', next);
applyTheme(next);
if (next === getSystemTheme()) {
localStorage.removeItem('theme');
Comment thread
m-aciek marked this conversation as resolved.
} else {
localStorage.setItem('theme', next);
}
applyTheme(getTheme());
});
colorSchemeMediaQuery.addEventListener('change', function() {
if (!getStoredTheme()) {
applyTheme(getTheme());
}
});
</script>
<script src="https://code.jquery.com/jquery-4.0.0.slim.min.js" integrity="sha256-8DGpv13HIm+5iDNWw1XqxgFB4mj+yOKFNb+tHBZOowc=" crossorigin="anonymous">
Expand Down
Loading