@@ -735,14 +735,15 @@ function loadCss(cssFileName) {
735
735
let oldSidebarScrollPosition = null ;
736
736
737
737
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 ) {
739
740
// This is to keep the scroll position on mobile.
740
741
oldSidebarScrollPosition = window . scrollY ;
741
742
document . body . style . width = `${ document . body . offsetWidth } px` ;
742
743
document . body . style . position = "fixed" ;
743
744
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" ;
746
747
} else {
747
748
oldSidebarScrollPosition = null ;
748
749
}
@@ -751,13 +752,14 @@ function loadCss(cssFileName) {
751
752
}
752
753
753
754
function hideSidebar ( ) {
754
- if ( oldSidebarScrollPosition !== null ) {
755
+ const mobile_topbar = document . querySelector ( ".mobile-topbar" ) ;
756
+ if ( oldSidebarScrollPosition !== null && mobile_topbar ) {
755
757
// This is to keep the scroll position on mobile.
756
758
document . body . style . width = "" ;
757
759
document . body . style . position = "" ;
758
760
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 = "" ;
761
763
// The scroll position is lost when resetting the style, hence why we store it in
762
764
// `oldSidebarScrollPosition`.
763
765
window . scrollTo ( 0 , oldSidebarScrollPosition ) ;
0 commit comments