1212const rootPath = document . getElementById ( "rustdoc-vars" ) . attributes [ "data-root-path" ] . value ;
1313let oldScrollPosition = 0 ;
1414
15+ const NAME_OFFSET = 0 ;
16+ const DIRS_OFFSET = 1 ;
17+ const FILES_OFFSET = 2 ;
18+
1519function closeSidebarIfMobile ( ) {
1620 if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT ) {
1721 updateLocalStorage ( "source-sidebar-show" , "false" ) ;
@@ -24,15 +28,15 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
2428
2529 dirEntry . className = "dir-entry" ;
2630
27- fullPath += elem [ "name" ] + "/" ;
31+ fullPath += elem [ NAME_OFFSET ] + "/" ;
2832
29- summary . innerText = elem [ "name" ] ;
33+ summary . innerText = elem [ NAME_OFFSET ] ;
3034 dirEntry . appendChild ( summary ) ;
3135
3236 const folders = document . createElement ( "div" ) ;
3337 folders . className = "folders" ;
34- if ( elem . dirs ) {
35- for ( const dir of elem . dirs ) {
38+ if ( elem [ DIRS_OFFSET ] ) {
39+ for ( const dir of elem [ DIRS_OFFSET ] ) {
3640 if ( createDirEntry ( dir , folders , fullPath , false ) ) {
3741 dirEntry . open = true ;
3842 hasFoundFile = true ;
@@ -43,8 +47,8 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
4347
4448 const files = document . createElement ( "div" ) ;
4549 files . className = "files" ;
46- if ( elem . files ) {
47- for ( const file_text of elem . files ) {
50+ if ( elem [ FILES_OFFSET ] ) {
51+ for ( const file_text of elem [ FILES_OFFSET ] ) {
4852 const file = document . createElement ( "a" ) ;
4953 file . innerText = file_text ;
5054 file . href = rootPath + "src/" + fullPath + file_text + ".html" ;
@@ -125,7 +129,7 @@ function createSourceSidebar() {
125129 title . innerText = "Files" ;
126130 sidebar . appendChild ( title ) ;
127131 Object . keys ( sourcesIndex ) . forEach ( key => {
128- sourcesIndex [ key ] . name = key ;
132+ sourcesIndex [ key ] [ NAME_OFFSET ] = key ;
129133 hasFoundFile = createDirEntry ( sourcesIndex [ key ] , sidebar , "" ,
130134 hasFoundFile ) ;
131135 } ) ;
0 commit comments