Skip to content

Commit

Permalink
css: Add dark theme
Browse files Browse the repository at this point in the history
- add CSS override for dark theme
- add javascript to toggle that
- TODO: add user configuration with peristence (probably using local
  storage or cookies to make this device specific)

Fixes WeblateOrg#2969
  • Loading branch information
nijel committed Jun 7, 2023
1 parent ecdac01 commit e4d5769
Show file tree
Hide file tree
Showing 4 changed files with 2,692 additions and 0 deletions.
13 changes: 13 additions & 0 deletions weblate/static/loader-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,19 @@ $(function () {
}
});

/* Dark theme handling */
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
const darkStyleElement = document.getElementById("style-dark");
function toggleDarkScheme() {
if (prefersDarkScheme.matches) {
darkStyleElement.setAttribute("media", "screen");
} else {
darkStyleElement.setAttribute("media", "not all");
}
}
prefersDarkScheme.addEventListener("change", toggleDarkScheme);
toggleDarkScheme();

/* Warn users that they do not want to use developer console in most cases */
console.log(
"%c%s",
Expand Down
4 changes: 4 additions & 0 deletions weblate/static/style-bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

:root {
color-scheme: only light;
}

.avatar {
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
Expand Down

0 comments on commit e4d5769

Please sign in to comment.