12
12
const rootPath = document . getElementById ( "rustdoc-vars" ) . attributes [ "data-root-path" ] . value ;
13
13
let oldScrollPosition = 0 ;
14
14
15
+ const NAME_OFFSET = 0 ;
16
+ const DIRS_OFFSET = 1 ;
17
+ const FILES_OFFSET = 2 ;
18
+
15
19
function closeSidebarIfMobile ( ) {
16
20
if ( window . innerWidth < window . RUSTDOC_MOBILE_BREAKPOINT ) {
17
21
updateLocalStorage ( "source-sidebar-show" , "false" ) ;
@@ -24,15 +28,15 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
24
28
25
29
dirEntry . className = "dir-entry" ;
26
30
27
- fullPath += elem [ "name" ] + "/" ;
31
+ fullPath += elem [ NAME_OFFSET ] + "/" ;
28
32
29
- summary . innerText = elem [ "name" ] ;
33
+ summary . innerText = elem [ NAME_OFFSET ] ;
30
34
dirEntry . appendChild ( summary ) ;
31
35
32
36
const folders = document . createElement ( "div" ) ;
33
37
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 ] ) {
36
40
if ( createDirEntry ( dir , folders , fullPath , false ) ) {
37
41
dirEntry . open = true ;
38
42
hasFoundFile = true ;
@@ -43,8 +47,8 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
43
47
44
48
const files = document . createElement ( "div" ) ;
45
49
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 ] ) {
48
52
const file = document . createElement ( "a" ) ;
49
53
file . innerText = file_text ;
50
54
file . href = rootPath + "src/" + fullPath + file_text + ".html" ;
@@ -125,7 +129,7 @@ function createSourceSidebar() {
125
129
title . innerText = "Files" ;
126
130
sidebar . appendChild ( title ) ;
127
131
Object . keys ( sourcesIndex ) . forEach ( key => {
128
- sourcesIndex [ key ] . name = key ;
132
+ sourcesIndex [ key ] [ NAME_OFFSET ] = key ;
129
133
hasFoundFile = createDirEntry ( sourcesIndex [ key ] , sidebar , "" ,
130
134
hasFoundFile ) ;
131
135
} ) ;
0 commit comments