"));
- let len = cx.current.len() - if it.is_mod() {1} else {0};
- for (i, name) in cx.current.iter().take(len).enumerate() {
+ for (i, name) in cx.current.iter().take(parentlen).enumerate() {
if i > 0 {
try!(write!(fmt, "::"));
}
@@ -2228,40 +2233,25 @@ impl<'a> fmt::Display for Sidebar<'a> {
}
try!(write!(fmt, "
"));
- fn block(w: &mut fmt::Formatter, short: &str, longty: &str,
- cur: &clean::Item, cx: &Context) -> fmt::Result {
- let items = match cx.sidebar.get(short) {
- Some(items) => items,
- None => return Ok(())
- };
- try!(write!(w, "{}
", short, longty));
- for &NameDoc(ref name, ref doc) in items {
- let curty = shortty(cur).to_static_str();
- let class = if cur.name.as_ref().unwrap() == name &&
- short == curty { "current" } else { "" };
- try!(write!(w, "
{name}",
- ty = short,
- class = class,
- href = if curty == "mod" {"../"} else {""},
- path = if short == "mod" {
- format!("{}/index.html", name)
- } else {
- format!("{}.{}.html", short, name)
- },
- title = Escape(doc.as_ref().unwrap()),
- name = name));
- }
- try!(write!(w, "
"));
- Ok(())
+ // sidebar refers to the enclosing module, not this module
+ let relpath = if shortty(it) == ItemType::Module { "../" } else { "" };
+ try!(write!(fmt,
+ "",
+ name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""),
+ ty = shortty(it).to_static_str(),
+ path = relpath));
+ if parentlen == 0 {
+ // there is no sidebar-items.js beyond the crate root path
+ // FIXME maybe dynamic crate loading can be merged here
+ } else {
+ try!(write!(fmt, "",
+ path = relpath));
}
- try!(block(fmt, "mod", "Modules", it, cx));
- try!(block(fmt, "struct", "Structs", it, cx));
- try!(block(fmt, "enum", "Enums", it, cx));
- try!(block(fmt, "trait", "Traits", it, cx));
- try!(block(fmt, "fn", "Functions", it, cx));
- try!(block(fmt, "macro", "Macros", it, cx));
Ok(())
}
}
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index aac3985f0cc..a9b233dd128 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -15,6 +15,27 @@
"use strict";
var resizeTimeout, interval;
+ // This mapping table should match the discriminants of
+ // `rustdoc::html::item_type::ItemType` type in Rust.
+ var itemTypes = ["mod",
+ "externcrate",
+ "import",
+ "struct",
+ "enum",
+ "fn",
+ "type",
+ "static",
+ "trait",
+ "impl",
+ "tymethod",
+ "method",
+ "structfield",
+ "variant",
+ "macro",
+ "primitive",
+ "associatedtype",
+ "constant"];
+
$('.js-only').removeClass('js-only');
function getQueryStringParams() {
@@ -552,27 +573,6 @@
showResults(results);
}
- // This mapping table should match the discriminants of
- // `rustdoc::html::item_type::ItemType` type in Rust.
- var itemTypes = ["mod",
- "externcrate",
- "import",
- "struct",
- "enum",
- "fn",
- "type",
- "static",
- "trait",
- "impl",
- "tymethod",
- "method",
- "structfield",
- "variant",
- "macro",
- "primitive",
- "associatedtype",
- "constant"];
-
function itemTypeFromName(typename) {
for (var i = 0; i < itemTypes.length; ++i) {
if (itemTypes[i] === typename) return i;
@@ -708,6 +708,50 @@
window.initSearch = initSearch;
+ // delayed sidebar rendering.
+ function initSidebarItems(items) {
+ var sidebar = $('.sidebar');
+ var current = window.sidebarCurrent;
+
+ function block(shortty, longty) {
+ var filtered = items[shortty];
+ if (!filtered) return;
+
+ var div = $('