Skip to content

Commit 2eaf93e

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 c92e9f2 commit 2eaf93e

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

656656
button.on('click', function(e) {
657657
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
@@ -29,4 +29,8 @@
2929
div#main {
3030
box-decoration-break: clone;
3131
}
32+
33+
#dark-mode-button {
34+
display: none !important;
35+
}
3236
}

0 commit comments

Comments
 (0)