11// From rust:
2- /* global ALIASES, currentCrate, rootPath */
2+ /* global ALIASES */
33
44// Local js definitions:
55/* global addClass, getCurrentValue, hasClass */
@@ -40,6 +40,21 @@ if (!DOMTokenList.prototype.remove) {
4040 } ;
4141}
4242
43+ ( function ( ) {
44+ var rustdocVars = document . getElementById ( "rustdoc-vars" ) ;
45+ if ( rustdocVars ) {
46+ window . rootPath = rustdocVars . attributes [ "data-root-path" ] . value ;
47+ window . currentCrate = rustdocVars . attributes [ "data-current-crate" ] . value ;
48+ }
49+ var sidebarVars = document . getElementById ( "sidebar-vars" ) ;
50+ if ( sidebarVars ) {
51+ window . sidebarCurrent = {
52+ name : sidebarVars . attributes [ "data-name" ] . value ,
53+ ty : sidebarVars . attributes [ "data-ty" ] . value ,
54+ relpath : sidebarVars . attributes [ "data-relpath" ] . value ,
55+ } ;
56+ }
57+ } ( ) ) ;
4358
4459// Gets the human-readable string for the virtual-key code of the
4560// given KeyboardEvent, ev.
@@ -565,7 +580,7 @@ function defocusSearchBar() {
565580 var i , match ,
566581 url = document . location . href ,
567582 stripped = "" ,
568- len = rootPath . match ( / \. \. \/ / g) . length + 1 ;
583+ len = window . rootPath . match ( / \. \. \/ / g) . length + 1 ;
569584
570585 for ( i = 0 ; i < len ; ++ i ) {
571586 match = url . match ( / \/ [ ^ \/ ] * $ / ) ;
@@ -1504,15 +1519,15 @@ function defocusSearchBar() {
15041519
15051520 if ( type === "mod" ) {
15061521 displayPath = path + "::" ;
1507- href = rootPath + path . replace ( / : : / g, "/" ) + "/" +
1522+ href = window . rootPath + path . replace ( / : : / g, "/" ) + "/" +
15081523 name + "/index.html" ;
15091524 } else if ( type === "primitive" || type === "keyword" ) {
15101525 displayPath = "" ;
1511- href = rootPath + path . replace ( / : : / g, "/" ) +
1526+ href = window . rootPath + path . replace ( / : : / g, "/" ) +
15121527 "/" + type + "." + name + ".html" ;
15131528 } else if ( type === "externcrate" ) {
15141529 displayPath = "" ;
1515- href = rootPath + name + "/index.html" ;
1530+ href = window . rootPath + name + "/index.html" ;
15161531 } else if ( item . parent !== undefined ) {
15171532 var myparent = item . parent ;
15181533 var anchor = "#" + type + "." + name ;
@@ -1535,13 +1550,13 @@ function defocusSearchBar() {
15351550 } else {
15361551 displayPath = path + "::" + myparent . name + "::" ;
15371552 }
1538- href = rootPath + path . replace ( / : : / g, "/" ) +
1553+ href = window . rootPath + path . replace ( / : : / g, "/" ) +
15391554 "/" + pageType +
15401555 "." + pageName +
15411556 ".html" + anchor ;
15421557 } else {
15431558 displayPath = item . path + "::" ;
1544- href = rootPath + item . path . replace ( / : : / g, "/" ) +
1559+ href = window . rootPath + item . path . replace ( / : : / g, "/" ) +
15451560 "/" + type + "." + name + ".html" ;
15461561 }
15471562 return [ displayPath , href ] ;
@@ -1973,7 +1988,7 @@ function defocusSearchBar() {
19731988 startSearch ( ) ;
19741989
19751990 // Draw a convenient sidebar of known crates if we have a listing
1976- if ( rootPath === "../" || rootPath === "./" ) {
1991+ if ( window . rootPath === "../" || window . rootPath === "./" ) {
19771992 var sidebar = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
19781993 if ( sidebar ) {
19791994 var div = document . createElement ( "div" ) ;
@@ -1992,11 +2007,11 @@ function defocusSearchBar() {
19922007 crates . sort ( ) ;
19932008 for ( var i = 0 ; i < crates . length ; ++ i ) {
19942009 var klass = "crate" ;
1995- if ( rootPath !== "./" && crates [ i ] === window . currentCrate ) {
2010+ if ( window . rootPath !== "./" && crates [ i ] === window . currentCrate ) {
19962011 klass += " current" ;
19972012 }
19982013 var link = document . createElement ( "a" ) ;
1999- link . href = rootPath + crates [ i ] + "/index.html" ;
2014+ link . href = window . rootPath + crates [ i ] + "/index.html" ;
20002015 // The summary in the search index has HTML, so we need to
20012016 // dynamically render it as plaintext.
20022017 link . title = convertHTMLToPlaintext ( rawSearchIndex [ crates [ i ] ] . doc ) ;
@@ -2118,7 +2133,7 @@ function defocusSearchBar() {
21182133
21192134 var libs = Object . getOwnPropertyNames ( imp ) ;
21202135 for ( var i = 0 , llength = libs . length ; i < llength ; ++ i ) {
2121- if ( libs [ i ] === currentCrate ) { continue ; }
2136+ if ( libs [ i ] === window . currentCrate ) { continue ; }
21222137 var structs = imp [ libs [ i ] ] ;
21232138
21242139 struct_loop:
@@ -2143,7 +2158,7 @@ function defocusSearchBar() {
21432158 var href = elem . getAttribute ( "href" ) ;
21442159
21452160 if ( href && href . indexOf ( "http" ) !== 0 ) {
2146- elem . setAttribute ( "href" , rootPath + href ) ;
2161+ elem . setAttribute ( "href" , window . rootPath + href ) ;
21472162 }
21482163 } ) ;
21492164
0 commit comments