10
10
( function ( ) {
11
11
12
12
const rootPath = document . getElementById ( "rustdoc-vars" ) . attributes [ "data-root-path" ] . value ;
13
- let oldScrollPosition = null ;
14
13
15
14
const NAME_OFFSET = 0 ;
16
15
const DIRS_OFFSET = 1 ;
@@ -70,44 +69,18 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
70
69
function toggleSidebar ( ) {
71
70
const child = this . parentNode . children [ 0 ] ;
72
71
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 ( ) ;
81
73
addClass ( document . documentElement , "source-sidebar-expanded" ) ;
82
74
child . innerText = "<" ;
83
75
updateLocalStorage ( "source-sidebar-show" , "true" ) ;
84
76
} 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 ( ) ;
94
78
removeClass ( document . documentElement , "source-sidebar-expanded" ) ;
95
79
child . innerText = ">" ;
96
80
updateLocalStorage ( "source-sidebar-show" , "false" ) ;
97
81
}
98
82
}
99
83
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
-
111
84
function createSidebarToggle ( ) {
112
85
const sidebarToggle = document . createElement ( "div" ) ;
113
86
sidebarToggle . id = "sidebar-toggle" ;
@@ -125,7 +98,7 @@ function createSidebarToggle() {
125
98
return sidebarToggle ;
126
99
}
127
100
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`.
129
102
// eslint-disable-next-line no-unused-vars
130
103
function createSourceSidebar ( ) {
131
104
const container = document . querySelector ( "nav.sidebar" ) ;
0 commit comments