1
1
// From rust:
2
- /* global ALIASES, currentCrate, rootPath */
2
+ /* global ALIASES */
3
3
4
4
// Local js definitions:
5
5
/* global addClass, getCurrentValue, hasClass */
@@ -40,6 +40,21 @@ if (!DOMTokenList.prototype.remove) {
40
40
} ;
41
41
}
42
42
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
+ } ( ) ) ;
43
58
44
59
// Gets the human-readable string for the virtual-key code of the
45
60
// given KeyboardEvent, ev.
@@ -565,7 +580,7 @@ function defocusSearchBar() {
565
580
var i , match ,
566
581
url = document . location . href ,
567
582
stripped = "" ,
568
- len = rootPath . match ( / \. \. \/ / g) . length + 1 ;
583
+ len = window . rootPath . match ( / \. \. \/ / g) . length + 1 ;
569
584
570
585
for ( i = 0 ; i < len ; ++ i ) {
571
586
match = url . match ( / \/ [ ^ \/ ] * $ / ) ;
@@ -1504,15 +1519,15 @@ function defocusSearchBar() {
1504
1519
1505
1520
if ( type === "mod" ) {
1506
1521
displayPath = path + "::" ;
1507
- href = rootPath + path . replace ( / : : / g, "/" ) + "/" +
1522
+ href = window . rootPath + path . replace ( / : : / g, "/" ) + "/" +
1508
1523
name + "/index.html" ;
1509
1524
} else if ( type === "primitive" || type === "keyword" ) {
1510
1525
displayPath = "" ;
1511
- href = rootPath + path . replace ( / : : / g, "/" ) +
1526
+ href = window . rootPath + path . replace ( / : : / g, "/" ) +
1512
1527
"/" + type + "." + name + ".html" ;
1513
1528
} else if ( type === "externcrate" ) {
1514
1529
displayPath = "" ;
1515
- href = rootPath + name + "/index.html" ;
1530
+ href = window . rootPath + name + "/index.html" ;
1516
1531
} else if ( item . parent !== undefined ) {
1517
1532
var myparent = item . parent ;
1518
1533
var anchor = "#" + type + "." + name ;
@@ -1535,13 +1550,13 @@ function defocusSearchBar() {
1535
1550
} else {
1536
1551
displayPath = path + "::" + myparent . name + "::" ;
1537
1552
}
1538
- href = rootPath + path . replace ( / : : / g, "/" ) +
1553
+ href = window . rootPath + path . replace ( / : : / g, "/" ) +
1539
1554
"/" + pageType +
1540
1555
"." + pageName +
1541
1556
".html" + anchor ;
1542
1557
} else {
1543
1558
displayPath = item . path + "::" ;
1544
- href = rootPath + item . path . replace ( / : : / g, "/" ) +
1559
+ href = window . rootPath + item . path . replace ( / : : / g, "/" ) +
1545
1560
"/" + type + "." + name + ".html" ;
1546
1561
}
1547
1562
return [ displayPath , href ] ;
@@ -1973,7 +1988,7 @@ function defocusSearchBar() {
1973
1988
startSearch ( ) ;
1974
1989
1975
1990
// Draw a convenient sidebar of known crates if we have a listing
1976
- if ( rootPath === "../" || rootPath === "./" ) {
1991
+ if ( window . rootPath === "../" || window . rootPath === "./" ) {
1977
1992
var sidebar = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
1978
1993
if ( sidebar ) {
1979
1994
var div = document . createElement ( "div" ) ;
@@ -1992,11 +2007,11 @@ function defocusSearchBar() {
1992
2007
crates . sort ( ) ;
1993
2008
for ( var i = 0 ; i < crates . length ; ++ i ) {
1994
2009
var klass = "crate" ;
1995
- if ( rootPath !== "./" && crates [ i ] === window . currentCrate ) {
2010
+ if ( window . rootPath !== "./" && crates [ i ] === window . currentCrate ) {
1996
2011
klass += " current" ;
1997
2012
}
1998
2013
var link = document . createElement ( "a" ) ;
1999
- link . href = rootPath + crates [ i ] + "/index.html" ;
2014
+ link . href = window . rootPath + crates [ i ] + "/index.html" ;
2000
2015
// The summary in the search index has HTML, so we need to
2001
2016
// dynamically render it as plaintext.
2002
2017
link . title = convertHTMLToPlaintext ( rawSearchIndex [ crates [ i ] ] . doc ) ;
@@ -2118,7 +2133,7 @@ function defocusSearchBar() {
2118
2133
2119
2134
var libs = Object . getOwnPropertyNames ( imp ) ;
2120
2135
for ( var i = 0 , llength = libs . length ; i < llength ; ++ i ) {
2121
- if ( libs [ i ] === currentCrate ) { continue ; }
2136
+ if ( libs [ i ] === window . currentCrate ) { continue ; }
2122
2137
var structs = imp [ libs [ i ] ] ;
2123
2138
2124
2139
struct_loop:
@@ -2143,7 +2158,7 @@ function defocusSearchBar() {
2143
2158
var href = elem . getAttribute ( "href" ) ;
2144
2159
2145
2160
if ( href && href . indexOf ( "http" ) !== 0 ) {
2146
- elem . setAttribute ( "href" , rootPath + href ) ;
2161
+ elem . setAttribute ( "href" , window . rootPath + href ) ;
2147
2162
}
2148
2163
} ) ;
2149
2164
0 commit comments