about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-10-08 23:32:05 +0200
committerGitHub <noreply@github.com>2022-10-08 23:32:05 +0200
commit92628633ee821eba88b243dea46c0019c407c24a (patch)
tree85ae870f8b8a10329cece97bf46f5a6e2a4407f9
parent7983e7a26f771cf30db20f77f5de6117a9762200 (diff)
parentd2e14e2d114bd3f7b56afdb4f6171577b13272c5 (diff)
downloadrust-92628633ee821eba88b243dea46c0019c407c24a.tar.gz
rust-92628633ee821eba88b243dea46c0019c407c24a.zip
Rollup merge of #102815 - notriddle:notriddle/mobile-topbar, r=GuillaumeGomez
rustdoc: remove mobile topbar from source pages instead of hiding it
-rw-r--r--src/librustdoc/html/static/css/rustdoc.css4
-rw-r--r--src/librustdoc/html/static/js/main.js14
-rw-r--r--src/librustdoc/html/templates/page.html2
-rw-r--r--src/test/rustdoc-gui/sidebar-source-code.goml2
4 files changed, 11 insertions, 11 deletions
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 480b893596c..4678c4856f7 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -1801,10 +1801,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 @@
     </div> {#- -#}
     <![endif]--> {#- -#}
     {{- layout.external_html.before_content|safe -}}
+    {%- if page.css_class != "source" -%}
     <nav class="mobile-topbar"> {#- -#}
         <button class="sidebar-menu-toggle">&#9776;</button> {#- -#}
         <a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
@@ -86,6 +87,7 @@
         </a> {#- -#}
         <h2 class="location"></h2> {#- -#}
     </nav> {#- -#}
+    {%- endif -%}
     <nav class="sidebar"> {#- -#}
         <a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
             <div class="logo-container"> {#- -#}
diff --git a/src/test/rustdoc-gui/sidebar-source-code.goml b/src/test/rustdoc-gui/sidebar-source-code.goml
index 4993384a27f..9ba66368772 100644
--- a/src/test/rustdoc-gui/sidebar-source-code.goml
+++ b/src/test/rustdoc-gui/sidebar-source-code.goml
@@ -42,4 +42,4 @@ assert-false: ".source-sidebar-expanded"
 assert: "nav.sidebar"
 
 // Check that the topbar is not visible
-assert-property: (".mobile-topbar", {"offsetParent": "null"})
+assert-false: ".mobile-topbar"