Skip to content

Commit eddeaf2

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 350ec93 commit eddeaf2

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
@@ -653,7 +653,7 @@ var DarkMode = {
653653
|| (!prefersDarkScheme && currentTheme === "dark")) {
654654
button.attr("src", `${baseURLPrefix}images/light-mode.svg`);
655655
}
656-
button.css("display", "block");
656+
button.addClass('active');
657657

658658
button.click(function(e) {
659659
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
@@ -26,4 +26,8 @@
2626
div#main {
2727
box-decoration-break: clone;
2828
}
29+
30+
#dark-mode-button {
31+
display: none !important;
32+
}
2933
}

0 commit comments

Comments
 (0)