diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index e29abbec69c..4b96ed20487 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1807,10 +1807,6 @@ in storage.js plus the media query with (min-width: 701px) top: 0; } - .source .mobile-topbar { - display: none; - } - .sidebar-menu-toggle { width: 45px; /* Rare exception to specifying font sizes in rem. Since this is acting diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 6d21ffdc792..359dd41b13f 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -735,14 +735,15 @@ function loadCss(cssFileName) { let oldSidebarScrollPosition = null; function showSidebar() { - if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) { + const mobile_topbar = document.querySelector(".mobile-topbar"); + if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && mobile_topbar) { // This is to keep the scroll position on mobile. oldSidebarScrollPosition = window.scrollY; document.body.style.width = `${document.body.offsetWidth}px`; document.body.style.position = "fixed"; document.body.style.top = `-${oldSidebarScrollPosition}px`; - document.querySelector(".mobile-topbar").style.top = `${oldSidebarScrollPosition}px`; - document.querySelector(".mobile-topbar").style.position = "relative"; + mobile_topbar.style.top = `${oldSidebarScrollPosition}px`; + mobile_topbar.style.position = "relative"; } else { oldSidebarScrollPosition = null; } @@ -751,13 +752,14 @@ function loadCss(cssFileName) { } function hideSidebar() { - if (oldSidebarScrollPosition !== null) { + const mobile_topbar = document.querySelector(".mobile-topbar"); + if (oldSidebarScrollPosition !== null && mobile_topbar) { // This is to keep the scroll position on mobile. document.body.style.width = ""; document.body.style.position = ""; document.body.style.top = ""; - document.querySelector(".mobile-topbar").style.top = ""; - document.querySelector(".mobile-topbar").style.position = ""; + mobile_topbar.style.top = ""; + mobile_topbar.style.position = ""; // The scroll position is lost when resetting the style, hence why we store it in // `oldSidebarScrollPosition`. window.scrollTo(0, oldSidebarScrollPosition); diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 7caffeae3d6..01a2ea6c2ec 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -73,6 +73,7 @@ {#- -#} {#- -#} {{- layout.external_html.before_content|safe -}} + {%- if page.css_class != "source" -%} {#- -#} + {%- endif -%}