Skip to content

Commit 8a7ebd0

Browse files
committed
Hide the dark mode button when printing
The dark mode button makes no sense in a printed document. This change is slightly tricky because we used to hide the dark button by default and only showed it when the JavaScript initialization ran as expected, by setting the CSS `display` property to `block`. However, doing that also meant that the `display` property could not be overridden by a `@media print` block, because the `display` property was set on the dark mode button itself, and would therefore always be more specific than the `@media print` rule. So let's instead use a CSS class to indicate whether the dark mode button should be shown or not. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9aac747 commit 8a7ebd0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

assets/js/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ var DarkMode = {
652652
|| (!prefersDarkScheme && currentTheme === "dark")) {
653653
button.attr("src", `${baseURLPrefix}images/light-mode.svg`);
654654
}
655-
button.css("display", "block");
655+
button.addClass('active');
656656

657657
button.click(function(e) {
658658
e.preventDefault();

assets/sass/application.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ pre {
6464
align-self: center;
6565
margin: 5px;
6666
}
67+
68+
#dark-mode-button.active {
69+
display: block;
70+
}

assets/sass/print.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
div#main {
1111
box-decoration-break: clone;
1212
}
13+
14+
#dark-mode-button {
15+
display: none !important;
16+
}
1317
}

0 commit comments

Comments
 (0)