Skip to content

Commit d2e14e2

Browse files
committed
rustdoc: remove mobile topbar from source pages instead of hiding it
1 parent bba9785 commit d2e14e2

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/librustdoc/html/static/css/rustdoc.css

-4
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,6 @@ in storage.js plus the media query with (min-width: 701px)
18071807
top: 0;
18081808
}
18091809

1810-
.source .mobile-topbar {
1811-
display: none;
1812-
}
1813-
18141810
.sidebar-menu-toggle {
18151811
width: 45px;
18161812
/* Rare exception to specifying font sizes in rem. Since this is acting

src/librustdoc/html/static/js/main.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -735,14 +735,15 @@ function loadCss(cssFileName) {
735735
let oldSidebarScrollPosition = null;
736736

737737
function showSidebar() {
738-
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
738+
const mobile_topbar = document.querySelector(".mobile-topbar");
739+
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && mobile_topbar) {
739740
// This is to keep the scroll position on mobile.
740741
oldSidebarScrollPosition = window.scrollY;
741742
document.body.style.width = `${document.body.offsetWidth}px`;
742743
document.body.style.position = "fixed";
743744
document.body.style.top = `-${oldSidebarScrollPosition}px`;
744-
document.querySelector(".mobile-topbar").style.top = `${oldSidebarScrollPosition}px`;
745-
document.querySelector(".mobile-topbar").style.position = "relative";
745+
mobile_topbar.style.top = `${oldSidebarScrollPosition}px`;
746+
mobile_topbar.style.position = "relative";
746747
} else {
747748
oldSidebarScrollPosition = null;
748749
}
@@ -751,13 +752,14 @@ function loadCss(cssFileName) {
751752
}
752753

753754
function hideSidebar() {
754-
if (oldSidebarScrollPosition !== null) {
755+
const mobile_topbar = document.querySelector(".mobile-topbar");
756+
if (oldSidebarScrollPosition !== null && mobile_topbar) {
755757
// This is to keep the scroll position on mobile.
756758
document.body.style.width = "";
757759
document.body.style.position = "";
758760
document.body.style.top = "";
759-
document.querySelector(".mobile-topbar").style.top = "";
760-
document.querySelector(".mobile-topbar").style.position = "";
761+
mobile_topbar.style.top = "";
762+
mobile_topbar.style.position = "";
761763
// The scroll position is lost when resetting the style, hence why we store it in
762764
// `oldSidebarScrollPosition`.
763765
window.scrollTo(0, oldSidebarScrollPosition);

src/librustdoc/html/templates/page.html

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
</div> {#- -#}
7474
<![endif]--> {#- -#}
7575
{{- layout.external_html.before_content|safe -}}
76+
{%- if page.css_class != "source" -%}
7677
<nav class="mobile-topbar"> {#- -#}
7778
<button class="sidebar-menu-toggle">&#9776;</button> {#- -#}
7879
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
@@ -86,6 +87,7 @@
8687
</a> {#- -#}
8788
<h2 class="location"></h2> {#- -#}
8889
</nav> {#- -#}
90+
{%- endif -%}
8991
<nav class="sidebar"> {#- -#}
9092
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
9193
<div class="logo-container"> {#- -#}

src/test/rustdoc-gui/sidebar-source-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ assert-false: ".source-sidebar-expanded"
4242
assert: "nav.sidebar"
4343

4444
// Check that the topbar is not visible
45-
assert-property: (".mobile-topbar", {"offsetParent": "null"})
45+
assert-false: ".mobile-topbar"

0 commit comments

Comments
 (0)