mirror of
https://github.com/Ellpeck/TinyLifeWeb.git
synced 2024-11-22 19:28:35 +01:00
improved the way dark mode works
This commit is contained in:
parent
55d255641c
commit
29ba63603d
4 changed files with 20 additions and 21 deletions
|
@ -21,7 +21,7 @@
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato&display=swap">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato&display=swap">
|
||||||
<link rel="stylesheet" href="https://fonts.cdnfonts.com/css/cadman">
|
<link rel="stylesheet" href="https://fonts.cdnfonts.com/css/cadman">
|
||||||
<link rel="stylesheet" href="/style/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
<link rel="icon" href="/favicon.ico">
|
<link rel="icon" href="/favicon.ico">
|
||||||
|
|
||||||
<meta property="og:title" content="{{ page.title }}">
|
<meta property="og:title" content="{{ page.title }}">
|
||||||
|
@ -39,6 +39,11 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body data-spy="scroll" data-target="#navbar" data-offset="80">
|
<body data-spy="scroll" data-target="#navbar" data-offset="80">
|
||||||
|
<script>
|
||||||
|
if (darkTheme)
|
||||||
|
$("body").addClass("dark-mode");
|
||||||
|
</script>
|
||||||
|
|
||||||
{% include navbar.html %}
|
{% include navbar.html %}
|
||||||
|
|
||||||
{{ content }}
|
{{ content }}
|
||||||
|
|
17
web/main.js
17
web/main.js
|
@ -1,20 +1,13 @@
|
||||||
const darkStorage = localStorage.getItem("dark");
|
const darkStorage = localStorage.getItem("dark");
|
||||||
const darkTheme = darkStorage === null ? window.matchMedia("(prefers-color-scheme: dark)").matches : darkStorage === "true";
|
const darkTheme = darkStorage === null ? window.matchMedia("(prefers-color-scheme: dark)").matches : darkStorage === "true";
|
||||||
if (darkTheme) {
|
|
||||||
$('head').append($("<link/>", {
|
|
||||||
rel: "stylesheet",
|
|
||||||
href: "/style/dark.css"
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('.navbar-collapse a').on('click', () => $('.navbar-collapse').collapse('hide'));
|
$(".navbar-collapse a").on("click", () => $(".navbar-collapse").collapse("hide"));
|
||||||
|
|
||||||
let mode = $('#dark-mode');
|
let mode = $("#dark-mode");
|
||||||
mode.prop('checked', darkTheme);
|
mode.prop("checked", darkTheme);
|
||||||
mode.on('click', function () {
|
mode.on("click", function () {
|
||||||
localStorage.setItem("dark", $(this).prop('checked'));
|
localStorage.setItem("dark", $(this).prop("checked"));
|
||||||
location.hash = "";
|
location.hash = "";
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
|
|
|
@ -169,6 +169,15 @@ pre.highlight {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.dark-mode {
|
||||||
|
color: #d8d8d8;
|
||||||
|
background-color: #1b1b1b;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.dark-mode .text-muted {
|
||||||
|
color: #929aa0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 576px) {
|
@media (max-width: 576px) {
|
||||||
|
|
||||||
.top-content {
|
.top-content {
|
|
@ -1,8 +0,0 @@
|
||||||
body {
|
|
||||||
color: #d8d8d8;
|
|
||||||
background-color: #1b1b1b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-muted {
|
|
||||||
color: #929aa0 !important;
|
|
||||||
}
|
|
Loading…
Reference in a new issue