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/main.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/main.js')
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 63ab56053af..410bf2e34ca 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1519,11 +1519,18 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm // and it can be activated by resizing the sidebar into nothing. const sidebarButton = document.getElementById("sidebar-button"); if (sidebarButton) { - sidebarButton.addEventListener("click", e => { - removeClass(document.documentElement, "hide-sidebar"); - updateLocalStorage("hide-sidebar", "false"); - e.preventDefault(); - }); + if (document.querySelector(".rustdoc.src")) { + sidebarButton.addEventListener("click", e => { + window.rustdocToggleSrcSidebar(); + e.preventDefault(); + }); + } else { + sidebarButton.addEventListener("click", e => { + removeClass(document.documentElement, "hide-sidebar"); + updateLocalStorage("hide-sidebar", "false"); + e.preventDefault(); + }); + } } // Pointer capture. @@ -1646,7 +1653,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm return; } e.preventDefault(); - const pos = e.clientX - sidebar.offsetLeft - 3; + const pos = e.clientX - 3; if (pos < SIDEBAR_VANISH_THRESHOLD) { hideSidebar(); } else if (pos >= SIDEBAR_MIN) { |
