diff options
| author | bors <bors@rust-lang.org> | 2021-12-05 18:35:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-12-05 18:35:43 +0000 |
| commit | e2116acae59654bfab2a9729a024f3e2fd6d4b02 (patch) | |
| tree | acf2e464a8cda6c81c8bee7b12489ac8991210ba /src/librustdoc/html/static/js/source-script.js | |
| parent | 772d51f887fa407216860bf8ecf3f1a32fb795b4 (diff) | |
| parent | d7528e2157762fadb9665518fd1e4dee6d6a2809 (diff) | |
| download | rust-e2116acae59654bfab2a9729a024f3e2fd6d4b02.tar.gz rust-e2116acae59654bfab2a9729a024f3e2fd6d4b02.zip | |
Auto merge of #91356 - GuillaumeGomez:improve-rustdoc-layout, r=jsha
Improve rustdoc layout This is an overtake of https://github.com/rust-lang/rust/pull/89385 originally written by `@cynecx.` I kept the original commit and simply added the missing fixes into a new one. You can test it online [here](https://rustdoc.crud.net/imperio/improve-rustdoc-layout/std/index.html). r? `@jsha`
Diffstat (limited to 'src/librustdoc/html/static/js/source-script.js')
| -rw-r--r-- | src/librustdoc/html/static/js/source-script.js | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 4d9a59f836b..81dc0b2fb1e 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -77,16 +77,14 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { } function toggleSidebar() { - var sidebar = document.getElementById("source-sidebar"); - var child = this.children[0].children[0]; + var sidebar = document.querySelector("nav.sidebar"); + var child = this.children[0]; if (child.innerText === ">") { - sidebar.style.left = ""; - this.style.left = ""; + sidebar.classList.add("expanded"); child.innerText = "<"; updateLocalStorage("rustdoc-source-sidebar-show", "true"); } else { - sidebar.style.left = "-300px"; - this.style.left = "0"; + sidebar.classList.remove("expanded"); child.innerText = ">"; updateLocalStorage("rustdoc-source-sidebar-show", "false"); } @@ -97,20 +95,15 @@ function createSidebarToggle() { sidebarToggle.id = "sidebar-toggle"; sidebarToggle.onclick = toggleSidebar; - var inner1 = document.createElement("div"); - inner1.style.position = "relative"; + var inner = document.createElement("div"); - var inner2 = document.createElement("div"); - inner2.style.paddingTop = "3px"; if (getCurrentValue("rustdoc-source-sidebar-show") === "true") { - inner2.innerText = "<"; + inner.innerText = "<"; } else { - inner2.innerText = ">"; - sidebarToggle.style.left = "0"; + inner.innerText = ">"; } - inner1.appendChild(inner2); - sidebarToggle.appendChild(inner1); + sidebarToggle.appendChild(inner); return sidebarToggle; } @@ -120,15 +113,17 @@ function createSourceSidebar() { if (!window.rootPath.endsWith("/")) { window.rootPath += "/"; } - var main = document.getElementById("main"); + var container = document.querySelector("nav.sidebar"); var sidebarToggle = createSidebarToggle(); - main.insertBefore(sidebarToggle, main.firstChild); + container.insertBefore(sidebarToggle, container.firstChild); var sidebar = document.createElement("div"); sidebar.id = "source-sidebar"; if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") { - sidebar.style.left = "-300px"; + container.classList.remove("expanded"); + } else { + container.classList.add("expanded"); } var currentFile = getCurrentFilePath(); @@ -144,7 +139,7 @@ function createSourceSidebar() { currentFile, hasFoundFile); }); - main.insertBefore(sidebar, main.firstChild); + container.insertBefore(sidebar, document.querySelector(".sidebar-logo").nextSibling); // Focus on the current file in the source files sidebar. var selected_elem = sidebar.getElementsByClassName("selected")[0]; if (typeof selected_elem !== "undefined") { |
