1010( function ( ) {
1111
1212const rootPath = document . getElementById ( "rustdoc-vars" ) . attributes [ "data-root-path" ] . value ;
13- let oldScrollPosition = null ;
1413
1514const NAME_OFFSET = 0 ;
1615const DIRS_OFFSET = 1 ;
@@ -70,44 +69,18 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
7069function toggleSidebar ( ) {
7170 const child = this . parentNode . children [ 0 ] ;
7271 if ( child . innerText === ">" ) {
73- if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT ) {
74- // This is to keep the scroll position on mobile.
75- oldScrollPosition = window . scrollY ;
76- document . body . style . position = "fixed" ;
77- document . body . style . top = `-${ oldScrollPosition } px` ;
78- } else {
79- oldScrollPosition = null ;
80- }
72+ window . rustdocMobileScrollLock ( ) ;
8173 addClass ( document . documentElement , "source-sidebar-expanded" ) ;
8274 child . innerText = "<" ;
8375 updateLocalStorage ( "source-sidebar-show" , "true" ) ;
8476 } else {
85- if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null ) {
86- // This is to keep the scroll position on mobile.
87- document . body . style . position = "" ;
88- document . body . style . top = "" ;
89- // The scroll position is lost when resetting the style, hence why we store it in
90- // `oldScrollPosition`.
91- window . scrollTo ( 0 , oldScrollPosition ) ;
92- oldScrollPosition = null ;
93- }
77+ window . rustdocMobileScrollUnlock ( ) ;
9478 removeClass ( document . documentElement , "source-sidebar-expanded" ) ;
9579 child . innerText = ">" ;
9680 updateLocalStorage ( "source-sidebar-show" , "false" ) ;
9781 }
9882}
9983
100- window . addEventListener ( "resize" , ( ) => {
101- if ( window . innerWidth >= window . RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null ) {
102- // If the user opens the sidebar in "mobile" mode, and then grows the browser window,
103- // we need to switch away from mobile mode and make the main content area scrollable.
104- document . body . style . position = "" ;
105- document . body . style . top = "" ;
106- window . scrollTo ( 0 , oldScrollPosition ) ;
107- oldScrollPosition = null ;
108- }
109- } ) ;
110-
11184function createSidebarToggle ( ) {
11285 const sidebarToggle = document . createElement ( "div" ) ;
11386 sidebarToggle . id = "sidebar-toggle" ;
@@ -125,7 +98,7 @@ function createSidebarToggle() {
12598 return sidebarToggle ;
12699}
127100
128- // This function is called from "source-files.js", generated in `html/render/mod .rs`.
101+ // This function is called from "source-files.js", generated in `html/render/write_shared .rs`.
129102// eslint-disable-next-line no-unused-vars
130103function createSourceSidebar ( ) {
131104 const container = document . querySelector ( "nav.sidebar" ) ;
0 commit comments