diff options
| author | Michael Howell <michael@notriddle.com> | 2022-10-08 10:43:23 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2022-10-08 10:48:19 -0700 |
| commit | d2e14e2d114bd3f7b56afdb4f6171577b13272c5 (patch) | |
| tree | 8c4fbbc43b62105525a258e548a13eb77716079d /src/librustdoc/html/static/js/main.js | |
| parent | bba9785dd73f61aacd301a2cb379e1e85a129047 (diff) | |
| download | rust-d2e14e2d114bd3f7b56afdb4f6171577b13272c5.tar.gz rust-d2e14e2d114bd3f7b56afdb4f6171577b13272c5.zip | |
rustdoc: remove mobile topbar from source pages instead of hiding it
Diffstat (limited to 'src/librustdoc/html/static/js/main.js')
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 14 |
1 files changed, 8 insertions, 6 deletions
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); |
