@@ -66,26 +66,18 @@ function showMain() {
66
66
( function ( ) {
67
67
window . rootPath = getVar ( "root-path" ) ;
68
68
window . currentCrate = getVar ( "current-crate" ) ;
69
- window . searchJS = resourcePath ( "search" , ".js" ) ;
70
- window . searchIndexJS = resourcePath ( "search-index" , ".js" ) ;
71
- window . settingsJS = resourcePath ( "settings" , ".js" ) ;
72
- const sidebarVars = document . getElementById ( "sidebar-vars" ) ;
73
- if ( sidebarVars ) {
74
- window . sidebarCurrent = {
75
- name : sidebarVars . attributes [ "data-name" ] . value ,
76
- ty : sidebarVars . attributes [ "data-ty" ] . value ,
77
- relpath : sidebarVars . attributes [ "data-relpath" ] . value ,
78
- } ;
79
- // FIXME: It would be nicer to generate this text content directly in HTML,
80
- // but with the current code it's hard to get the right information in the right place.
81
- const mobileLocationTitle = document . querySelector ( ".mobile-topbar h2.location" ) ;
82
- const locationTitle = document . querySelector ( ".sidebar h2.location" ) ;
83
- if ( mobileLocationTitle && locationTitle ) {
84
- mobileLocationTitle . innerHTML = locationTitle . innerHTML ;
85
- }
86
- }
87
69
} ( ) ) ;
88
70
71
+ function setMobileTopbar ( ) {
72
+ // FIXME: It would be nicer to generate this text content directly in HTML,
73
+ // but with the current code it's hard to get the right information in the right place.
74
+ const mobileLocationTitle = document . querySelector ( ".mobile-topbar h2.location" ) ;
75
+ const locationTitle = document . querySelector ( ".sidebar h2.location" ) ;
76
+ if ( mobileLocationTitle && locationTitle ) {
77
+ mobileLocationTitle . innerHTML = locationTitle . innerHTML ;
78
+ }
79
+ }
80
+
89
81
// Gets the human-readable string for the virtual-key code of the
90
82
// given KeyboardEvent, ev.
91
83
//
@@ -227,7 +219,7 @@ function loadCss(cssFileName) {
227
219
// Sending request for the CSS and the JS files at the same time so it will
228
220
// hopefully be loaded when the JS will generate the settings content.
229
221
loadCss ( "settings" ) ;
230
- loadScript ( window . settingsJS ) ;
222
+ loadScript ( resourcePath ( "settings" , ".js" ) ) ;
231
223
} ;
232
224
233
225
window . searchState = {
@@ -304,8 +296,8 @@ function loadCss(cssFileName) {
304
296
function loadSearch ( ) {
305
297
if ( ! searchLoaded ) {
306
298
searchLoaded = true ;
307
- loadScript ( window . searchJS ) ;
308
- loadScript ( window . searchIndexJS ) ;
299
+ loadScript ( resourcePath ( "search" , ".js" ) ) ;
300
+ loadScript ( resourcePath ( "search-index" , ".js" ) ) ;
309
301
}
310
302
}
311
303
@@ -485,40 +477,11 @@ function loadCss(cssFileName) {
485
477
document . addEventListener ( "keypress" , handleShortcut ) ;
486
478
document . addEventListener ( "keydown" , handleShortcut ) ;
487
479
488
- // delayed sidebar rendering.
489
- window . initSidebarItems = items => {
490
- const sidebar = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
491
- let others ;
492
- const current = window . sidebarCurrent ;
493
-
494
- function addSidebarCrates ( crates ) {
495
- if ( ! hasClass ( document . body , "crate" ) ) {
496
- // We only want to list crates on the crate page.
497
- return ;
498
- }
499
- // Draw a convenient sidebar of known crates if we have a listing
500
- const div = document . createElement ( "div" ) ;
501
- div . className = "block crate" ;
502
- div . innerHTML = "<h3>Crates</h3>" ;
503
- const ul = document . createElement ( "ul" ) ;
504
- div . appendChild ( ul ) ;
505
-
506
- for ( const crate of crates ) {
507
- let klass = "crate" ;
508
- if ( window . rootPath !== "./" && crate === window . currentCrate ) {
509
- klass += " current" ;
510
- }
511
- const link = document . createElement ( "a" ) ;
512
- link . href = window . rootPath + crate + "/index.html" ;
513
- link . className = klass ;
514
- link . textContent = crate ;
515
-
516
- const li = document . createElement ( "li" ) ;
517
- li . appendChild ( link ) ;
518
- ul . appendChild ( li ) ;
519
- }
520
- others . appendChild ( div ) ;
480
+ function addSidebarItems ( ) {
481
+ if ( ! window . SIDEBAR_ITEMS ) {
482
+ return ;
521
483
}
484
+ const sidebar = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
522
485
523
486
/**
524
487
* Append to the sidebar a "block" of links - a heading along with a list (`<ul>`) of items.
@@ -529,7 +492,7 @@ function loadCss(cssFileName) {
529
492
* "Modules", or "Macros".
530
493
*/
531
494
function block ( shortty , id , longty ) {
532
- const filtered = items [ shortty ] ;
495
+ const filtered = window . SIDEBAR_ITEMS [ shortty ] ;
533
496
if ( ! filtered ) {
534
497
return ;
535
498
}
@@ -546,17 +509,18 @@ function loadCss(cssFileName) {
546
509
const desc = item [ 1 ] ; // can be null
547
510
548
511
let klass = shortty ;
549
- if ( name === current . name && shortty === current . ty ) {
550
- klass += " current" ;
551
- }
552
512
let path ;
553
513
if ( shortty === "mod" ) {
554
514
path = name + "/index.html" ;
555
515
} else {
556
516
path = shortty + "." + name + ".html" ;
557
517
}
518
+ const current_page = document . location . href . split ( "/" ) . pop ( ) ;
519
+ if ( path === current_page ) {
520
+ klass += " current" ;
521
+ }
558
522
const link = document . createElement ( "a" ) ;
559
- link . href = current . relpath + path ;
523
+ link . href = path ;
560
524
link . title = desc ;
561
525
link . className = klass ;
562
526
link . textContent = name ;
@@ -565,14 +529,10 @@ function loadCss(cssFileName) {
565
529
ul . appendChild ( li ) ;
566
530
}
567
531
div . appendChild ( ul ) ;
568
- others . appendChild ( div ) ;
532
+ sidebar . appendChild ( div ) ;
569
533
}
570
534
571
535
if ( sidebar ) {
572
- others = document . createElement ( "div" ) ;
573
- others . className = "others" ;
574
- sidebar . appendChild ( others ) ;
575
-
576
536
const isModule = hasClass ( document . body , "mod" ) ;
577
537
if ( ! isModule ) {
578
538
block ( "primitive" , "primitives" , "Primitive Types" ) ;
@@ -590,12 +550,8 @@ function loadCss(cssFileName) {
590
550
block ( "keyword" , "keywords" , "Keywords" ) ;
591
551
block ( "traitalias" , "trait-aliases" , "Trait Aliases" ) ;
592
552
}
593
-
594
- // `crates{version}.js` should always be loaded before this script, so we can use
595
- // it safely.
596
- addSidebarCrates ( window . ALL_CRATES ) ;
597
553
}
598
- } ;
554
+ }
599
555
600
556
window . register_implementors = imp => {
601
557
const implementors = document . getElementById ( "implementors-list" ) ;
@@ -680,6 +636,39 @@ function loadCss(cssFileName) {
680
636
window . register_implementors ( window . pending_implementors ) ;
681
637
}
682
638
639
+ function addSidebarCrates ( ) {
640
+ if ( ! window . ALL_CRATES ) {
641
+ return ;
642
+ }
643
+ const sidebarElems = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
644
+ if ( ! sidebarElems ) {
645
+ return ;
646
+ }
647
+ // Draw a convenient sidebar of known crates if we have a listing
648
+ const div = document . createElement ( "div" ) ;
649
+ div . className = "block crate" ;
650
+ div . innerHTML = "<h3>Crates</h3>" ;
651
+ const ul = document . createElement ( "ul" ) ;
652
+ div . appendChild ( ul ) ;
653
+
654
+ for ( const crate of window . ALL_CRATES ) {
655
+ let klass = "crate" ;
656
+ if ( window . rootPath !== "./" && crate === window . currentCrate ) {
657
+ klass += " current" ;
658
+ }
659
+ const link = document . createElement ( "a" ) ;
660
+ link . href = window . rootPath + crate + "/index.html" ;
661
+ link . className = klass ;
662
+ link . textContent = crate ;
663
+
664
+ const li = document . createElement ( "li" ) ;
665
+ li . appendChild ( link ) ;
666
+ ul . appendChild ( li ) ;
667
+ }
668
+ sidebarElems . appendChild ( div ) ;
669
+ }
670
+
671
+
683
672
function labelForToggleButton ( sectionIsCollapsed ) {
684
673
if ( sectionIsCollapsed ) {
685
674
// button will expand the section
@@ -924,6 +913,9 @@ function loadCss(cssFileName) {
924
913
buildHelperPopup = ( ) => { } ;
925
914
} ;
926
915
916
+ setMobileTopbar ( ) ;
917
+ addSidebarItems ( ) ;
918
+ addSidebarCrates ( ) ;
927
919
onHashChange ( null ) ;
928
920
window . addEventListener ( "hashchange" , onHashChange ) ;
929
921
searchState . setup ( ) ;
0 commit comments