diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 8c14d1bbe8f..61de5f4bc4c 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -65,6 +65,7 @@ r##" {before_content} diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9dc01bb0916..d42faebd39e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3542,6 +3542,7 @@ impl<'a> fmt::Display for Sidebar<'a> { let cx = self.cx; let it = self.item; let parentlen = cx.current.len() - if it.is_mod() {1} else {0}; + let mut should_close = false; if it.is_struct() || it.is_trait() || it.is_primitive() || it.is_union() || it.is_enum() || it.is_mod() || it.is_typedef() @@ -3575,6 +3576,8 @@ impl<'a> fmt::Display for Sidebar<'a> { } } + write!(fmt, "
")?; + } Ok(()) } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index bdd7b7dd0b7..0db739fe061 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -106,6 +106,24 @@ return (elem.offsetParent === null) } + function showSidebar() { + document.getElementsByClassName("sidebar-elems")[0].style.display = "block"; + var sidebar = document.getElementsByClassName('sidebar')[0]; + sidebar.style.position = 'fixed'; + sidebar.style.width = '100%'; + sidebar.style.marginLeft = '0'; + document.getElementsByTagName("body")[0].style.marginTop = '45px'; + } + + function hideSidebar() { + document.getElementsByClassName("sidebar-elems")[0].style.display = ""; + var sidebar = document.getElementsByClassName('sidebar')[0]; + sidebar.style.position = ''; + sidebar.style.width = ''; + sidebar.style.marginLeft = ''; + document.getElementsByTagName("body")[0].style.marginTop = ''; + } + // used for special search precedence var TY_PRIMITIVE = itemTypes.indexOf("primitive"); @@ -130,6 +148,8 @@ } function highlightSourceLines(ev) { + // If we're in mobile mode, we should add the sidebar in any case. + hideSidebar(); var search = document.getElementById("search"); var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); if (match) { @@ -1459,7 +1479,7 @@ // delayed sidebar rendering. function initSidebarItems(items) { - var sidebar = document.getElementsByClassName('sidebar')[0]; + var sidebar = document.getElementsByClassName('sidebar-elems')[0]; var current = window.sidebarCurrent; function block(shortty, longty) { @@ -1829,6 +1849,22 @@ removeClass(search, "hidden"); search.innerHTML = '