From 859bbc5deffbee7870433c541cdbeb4a4a23780f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 17 Dec 2023 23:06:31 -0700 Subject: 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. --- src/librustdoc/html/static/js/main.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/librustdoc/html/static/js/main.js') 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) { -- cgit 1.4.1-3-g733a5