diff options
| author | Michael Howell <michael@notriddle.com> | 2023-12-17 23:06:31 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-12-17 23:06:31 -0700 |
| commit | 859bbc5deffbee7870433c541cdbeb4a4a23780f (patch) | |
| tree | 57e41fe2cc034bc00b157e60682937bdf850ca79 /src/librustdoc/html/static/js/src-script.js | |
| parent | 43dcc9b786c922251c3fbe75a0142f50f07053ca (diff) | |
| download | rust-859bbc5deffbee7870433c541cdbeb4a4a23780f.tar.gz rust-859bbc5deffbee7870433c541cdbeb4a4a23780f.zip | |
rustdoc: clean up source sidebar hide button
This is a redesign of the feature, with parts pulled from https://github.com/rust-lang/rust/pull/119049 but with a button that looks more like a button and matches the one used on other sidebar pages.
Diffstat (limited to 'src/librustdoc/html/static/js/src-script.js')
| -rw-r--r-- | src/librustdoc/html/static/js/src-script.js | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js index fc1d2d37845..2a3a6e7afb3 100644 --- a/src/librustdoc/html/static/js/src-script.js +++ b/src/librustdoc/html/static/js/src-script.js @@ -71,68 +71,34 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) { return hasFoundFile; } -let toggleLabel; - -function getToggleLabel() { - toggleLabel = toggleLabel || document.querySelector("#src-sidebar-toggle button"); - return toggleLabel; -} - window.rustdocCloseSourceSidebar = () => { removeClass(document.documentElement, "src-sidebar-expanded"); - getToggleLabel().innerText = ">"; updateLocalStorage("source-sidebar-show", "false"); }; window.rustdocShowSourceSidebar = () => { addClass(document.documentElement, "src-sidebar-expanded"); - getToggleLabel().innerText = "<"; updateLocalStorage("source-sidebar-show", "true"); }; -function toggleSidebar() { - const child = this.parentNode.children[0]; - if (child.innerText === ">") { - window.rustdocShowSourceSidebar(); - } else { +window.rustdocToggleSrcSidebar = () => { + if (document.documentElement.classList.contains("src-sidebar-expanded")) { window.rustdocCloseSourceSidebar(); - } -} - -function createSidebarToggle() { - const sidebarToggle = document.createElement("div"); - sidebarToggle.id = "src-sidebar-toggle"; - - const inner = document.createElement("button"); - - if (getCurrentValue("source-sidebar-show") === "true") { - inner.innerText = "<"; } else { - inner.innerText = ">"; + window.rustdocShowSourceSidebar(); } - inner.onclick = toggleSidebar; - - sidebarToggle.appendChild(inner); - return sidebarToggle; -} +}; // This function is called from "src-files.js", generated in `html/render/write_shared.rs`. // eslint-disable-next-line no-unused-vars function createSrcSidebar() { const container = document.querySelector("nav.sidebar"); - const sidebarToggle = createSidebarToggle(); - container.insertBefore(sidebarToggle, container.firstChild); - const sidebar = document.createElement("div"); sidebar.id = "src-sidebar"; let hasFoundFile = false; - const title = document.createElement("div"); - title.className = "title"; - title.innerText = "Files"; - sidebar.appendChild(title); for (const [key, source] of srcIndex) { source[NAME_OFFSET] = key; hasFoundFile = createDirEntry(source, sidebar, "", hasFoundFile); |
