Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dark mode #1888

Open
wants to merge 24 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8fe33e4
Consolidate the `<script>` lines
dscho Oct 20, 2024
4eaaaef
css: avoid redundant CSS rules
dscho Oct 20, 2024
d695dc2
css: remove the `link-*-color` variables
dscho Sep 27, 2024
59a2cba
css: switch to using CSS custom properties
dscho Sep 27, 2024
9a02604
Offer a dark mode if indicated by the operating system
dscho Sep 27, 2024
edd6c2c
Add a dark/light mode toggle
dscho Sep 27, 2024
61a7f52
dark-mode: adjust the background
dscho Oct 20, 2024
b4b1615
dark mode: dim images
dscho Sep 27, 2024
96bd35e
dark mode: make links stand out visually a bit more
dscho Sep 27, 2024
e5308b6
dark-mode: adapt verseblocks
dscho Sep 27, 2024
b724620
dark-mode: replace hard-coded #fff with the `--main-bg` property
dscho Sep 27, 2024
86fb650
dark mode: adapt front page
dscho Oct 20, 2024
074335a
dark-mode: use a not-too-dark color for navbar links
dscho Oct 20, 2024
bf2f371
dark mode: make the circled labels in the About section readable
dscho Oct 20, 2024
0d30e9a
dark-mode: adjust the search
dscho Oct 20, 2024
459abe4
dark-mode: decrease brightness of the ruler in the sidebar
dscho Oct 20, 2024
9bbc61c
dark mode: adjust colors for manual pages' drop-downs
dscho Oct 20, 2024
0fd3b92
TO-DROP: do not minify the CSS, for easier fiddling
dscho Sep 27, 2024
e0c17c7
TO-DROP: do not minify the Javascript, for debugging in Developer Tools
dscho Sep 27, 2024
e7b525a
Gnome image update
TheGiraffe3 Nov 28, 2024
185ece5
Finish converting logos that have backrounds
TheGiraffe3 Nov 28, 2024
877b383
Better PostGRESQL logo
TheGiraffe3 Dec 2, 2024
dcae7e6
Eclipse logo update
TheGiraffe3 Dec 3, 2024
d169ee1
Merge pull request #16 from TheGiraffe3/dark-mode
dscho Dec 3, 2024
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
33 changes: 33 additions & 0 deletions assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const baseURLPrefix = (() => {

$(document).ready(function() {
BrowserFallbacks.init();
DarkMode.init();
Search.init();
Dropdowns.init();
Forms.init();
Expand Down Expand Up @@ -541,6 +542,38 @@ var Downloads = {
},
}

var DarkMode = {
init: function() {
const button = $('#dark-mode-button');
if (!button.length) return;
button.show(3000);

// Check for dark mode preference at the OS level
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches;

// Get the user's theme preference from local storage, if it's available
const currentTheme = localStorage.getItem("theme");

if ((prefersDarkScheme && currentTheme !== "light")
|| (!prefersDarkScheme && currentTheme === "dark")) {
button.text("🌞");
}

button.click(function(e) {
e.preventDefault();
let theme
if (prefersDarkScheme) {
theme = document.documentElement.dataset.theme === "light" ? "dark" : "light"
} else {
theme = document.documentElement.dataset.theme === "dark" ? "light" : "dark"
}
document.documentElement.dataset.theme = theme
localStorage.setItem("theme", theme);
button.text(theme === "dark" ? "🌞" : "🌙");
});
},
}

// Scroll to Top
$('#scrollToTop').removeClass('no-js');
$(window).scroll(function() {
Expand Down
5 changes: 3 additions & 2 deletions assets/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@ $baseurl: "{{ .Site.BaseURL }}{{ if (and (ne .Site.BaseURL "/") (ne .Site.BaseUR
@import 'book2';
@import 'lists';
@import 'about';
@import 'dark-mode';

code {
display: inline;
padding: 0 5px;
}

pre {
background-color: #fff;
background-color: var(--main-bg);
border: solid 1px #efeee6;
border-radius: 3px;
color: $orange;
color: var(--orange);
display: block;
font-family: $fixed-width-font-family;
font-variant-ligatures: none;
Expand Down
11 changes: 5 additions & 6 deletions assets/sass/book.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import "variables";
@import "mixins";
@import "layout";

.ebooks img {
padding: 5px;
Expand All @@ -13,7 +12,7 @@
padding-bottom: 20px !important;
background-color: transparent !important;
overflow: hidden;
border: solid 1px lighten($base-border-color, 10%);
border: solid 1px var(--base-border-color-lighter-10);
}

#book-intro {
Expand All @@ -36,7 +35,7 @@
.license {
font-size: 11px;
line-height: 1.3;
color: $light-font-color;
color: var(--light-font-color);
}

a#open-book {
Expand All @@ -52,7 +51,7 @@
display: none;
padding-left: 22px;
font-size: 12px;
color: $light-font-color;
color: var(--light-font-color);
text-align: center;
text-indent: 40px;

Expand All @@ -74,7 +73,7 @@ ol.book-toc {
}

h2 {
color: $font-color;
color: var(--font-color);
}

a {
Expand Down Expand Up @@ -140,7 +139,7 @@ ol.book-toc {

&.active {
font-weight: bold;
color: $orange;
color: var(--orange);
}
}
}
Expand Down
178 changes: 178 additions & 0 deletions assets/sass/dark-mode.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
@mixin mode($mode: light, $theme: "") {
// Palette
$orange: #f14e32;
$blue: #009099;
$font-color: #4e443c;
$aside-font-color: lighten($font-color, 20%);
$light-font-color: #9a9994;
$link-color: #0388a6;
$nav-link-color: #413932;
$fixed-width-font-color: #4e443c;
$button-bg-color: rgba(223, 221, 213, 0.33);
$button-bg-hover-color: rgba(250, 250, 250, 0.9);
$mark-color: #ff0;
$base-border-color: #d8d7cf;
$callout-color: #e9e8e0;
$highlight-bg-color: #eee0b5;
$black-3: #333333;
$main-bg: #fcfcfa;
$bg-color: #f0efe7 url($baseurl + "images/bg/body.jpg");
$sidebar-bg-color: #efefe7;
$no-changes-bg-color: #f5f5f3;
$dropdown-active-bg-color: #fff;
$versions-footer-bg-color: #eae9e0;

@if $mode == dark {
$orange: #d7834f;
$blue: #007a7e;
$font-color: #b3b1b1;
$aside-font-color: darken($font-color, 10%);
$light-font-color: #bdbbb0;
$link-color: #5facaf;
$nav-link-color: #979594;
$fixed-width-font-color: #afa7a0;
$button-bg-hover-color: rgba(223, 221, 213, 0.6);
$mark-color: #aeae74;
$base-border-color: #b3b2a7;
$callout-color: #555555;
$highlight-bg-color: #7d724f;
$black-3: #cccccc;
$main-bg: #333333;
$bg-color: #2a2a2aff;
$sidebar-bg-color: #3d3d3a;
$no-changes-bg-color: #515150;
$dropdown-active-bg-color: #515150;
$versions-footer-bg-color: #1f1f1e;

:root#{$theme} {
div#masthead {
background: transparent;
}
div#masthead::before {
content: "";
width: 100%;
height: 295px;
@include background-image-2x($baseurl + "images/bg/isometric-grid", 35px, 21px, top right, repeat);
position: absolute;
filter: brightness(.4) contrast(1.6);
z-index: -1;
}
img {
filter: brightness(.6) contrast(1.2);
}
// let the logo shine slightly brighter
img[alt="Git"] {
filter: brightness(0.9) contrast(1.5);
}

a.subtle-button {
background-image: linear-gradient(#555555, #777777);
border-top: solid 1px #333333;
border-right: solid 1px #333333;
border-bottom: solid 1px #333333;
border-left: solid 1px #333333;
@include box-shadow(none);
}

a {
text-decoration: dashed 1px underline;
}

#front-nav img {
filter: none;
}

div.monitor {
filter: brightness(.85);
}

.monitor a {
color: #dbd7d7;
}

hr.sidebar {
filter: brightness(0.5);
}

#documentation #main div.verseblock pre.content {
color: var(--light-font-color);
background-color: #5e5951;
}

form#search {
@include box-shadow(none);
}

input.pagefind-ui__search-input {
background: var(--main-bg);
}

#reference-version {
background-color: rgba(111, 110, 105, 0.33);
}

#l10n-versions-dropdown footer a {
color: #6969dd;
}
}
}

:root#{$theme} {
--orange: #{$orange};
--orange-darker-5: #{darken($orange, 5%)};
--blue: #{$blue};
--font-color: #{$font-color};
--aside-font-color: #{$aside-font-color};
--light-font-color: #{$light-font-color};
--light-font-color-darker-10: #{darken($light-font-color, 10%)};
--light-font-color-darker-25: #{darken($light-font-color, 25%)};
--light-font-color-darker-35: #{darken($light-font-color, 35%)};
--light-font-color-darker-55: #{darken($light-font-color, 55%)};
--light-font-color-lighter-20: #{lighten($light-font-color, 20%)};
--link-color: #{$link-color};
--nav-link-color: #{$nav-link-color};
--link-hover-color: #{lighten($link-color, 10%)};
--fixed-width-font-color: #{$fixed-width-font-color};
--button-bg-color: #{$button-bg-color};
--button-bg-hover-color: #{$button-bg-hover-color};
--mark-color: #{$mark-color};
--base-border-color: #{$base-border-color};
--base-border-color-darker-8: #{darken($base-border-color, 8%)};
--base-border-color-lighter-10: #{lighten($base-border-color, 10%)};
--callout-color: #{$callout-color};
--highlight-bg-color: #{$highlight-bg-color};

--black-3: #{$black-3};
--main-bg: #{$main-bg};
--sidebar-bg-color: #{$sidebar-bg-color};
--bg-color: #{$bg-color};
--no-changes-bg-color: #{$no-changes-bg-color};
--dropdown-active-bg-color: #{$dropdown-active-bg-color};
--versions-footer-bg-color: #{$versions-footer-bg-color};
}
}

@include mode
@include mode($mode: dark, $theme: '[data-theme="dark"]')

@media screen and (prefers-color-scheme: dark) {
@include mode($mode: dark)
@include mode($mode: light, $theme: '[data-theme="light"]')
}

#dark-mode-button {
display: none;
z-index: 10;
position: fixed;
right: 20px;
bottom: 2rem;
border-radius: 50px;
border: 2px solid transparent;
font-size: x-large;
padding: 10px 5px 10px 5px;
background-color: var(--button-bg-color);
&:hover {
background-color: var(--button-bg-hover-color);
}
text-decoration: none;
}
11 changes: 5 additions & 6 deletions assets/sass/downloads.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import "variables";
@import "mixins";
@import "layout";

#logo-license {
@extend .callout;
Expand All @@ -10,7 +9,7 @@
p {
font-size: 12px;
line-height: 1.4;
color: $light-font-color;
color: var(--light-font-color);
}

p + p {
Expand Down Expand Up @@ -56,7 +55,7 @@

a {
display: block;
color: $font-color;
color: var(--font-color);
text-align: center;
background-repeat: no-repeat;
background-position: 0 0;
Expand All @@ -75,7 +74,7 @@
h3 {
font-size: 18px;
font-weight: bold;
color: $orange;
color: var(--orange);
}

p {
Expand All @@ -90,7 +89,7 @@
}

h3 {
color: darken($orange, 5%);
color: var(--orange-darker-5);
}
}
}
Expand All @@ -100,7 +99,7 @@
top: 8px;
left: 12px;
display: none;
color: $orange;
color: var(--orange);
}

.downloading .hide {
Expand Down
8 changes: 4 additions & 4 deletions assets/sass/errors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ body {
font-size: $base-font-size;
line-height: $base-line-height;
font-family: $base-font-family;
color: $font-color;
background: #f0efe7 url($baseurl + "images/bg/body.jpg");
color: var(--font-color);
background: var(--bg-color);
}

// windows chrome makes a mess of Adelle web font
Expand Down Expand Up @@ -43,9 +43,9 @@ nav ul {
li {
a {
display: block;
color: $orange;
color: var(--orange);
&:hover {
color: darken($orange, 5%);
color: var(--orange-darker-5);
}
}
}
Expand Down
Loading
Loading