diff options
| author | Michael Howell <michael@notriddle.com> | 2023-09-07 18:45:24 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2023-10-11 10:26:36 -0700 |
| commit | 0983438faa0431eb392be1d8ea9761fe4b1e90e2 (patch) | |
| tree | 6f929fb8f70645811b49d7309a715d72ae496c1f /src/librustdoc/html/static/js/storage.js | |
| parent | 3c23df49352264938a726f6a586d6019e602c5cf (diff) | |
| download | rust-0983438faa0431eb392be1d8ea9761fe4b1e90e2.tar.gz rust-0983438faa0431eb392be1d8ea9761fe4b1e90e2.zip | |
rustdoc: allow resizing the sidebar
Diffstat (limited to 'src/librustdoc/html/static/js/storage.js')
| -rw-r--r-- | src/librustdoc/html/static/js/storage.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js index c69641092ab..20220f2e69a 100644 --- a/src/librustdoc/html/static/js/storage.js +++ b/src/librustdoc/html/static/js/storage.js @@ -202,6 +202,30 @@ if (getSettingValue("source-sidebar-show") === "true") { addClass(document.documentElement, "src-sidebar-expanded"); } +if (getSettingValue("hide-sidebar") === "true") { + // At this point in page load, `document.body` is not available yet. + // Set a class on the `<html>` element instead. + addClass(document.documentElement, "hide-sidebar"); +} + +function updateSidebarWidth() { + const desktopSidebarWidth = getSettingValue("desktop-sidebar-width"); + if (desktopSidebarWidth && desktopSidebarWidth !== "null") { + document.documentElement.style.setProperty( + "--desktop-sidebar-width", + desktopSidebarWidth + "px" + ); + } + const srcSidebarWidth = getSettingValue("src-sidebar-width"); + if (srcSidebarWidth && srcSidebarWidth !== "null") { + document.documentElement.style.setProperty( + "--src-sidebar-width", + srcSidebarWidth + "px" + ); + } +} +updateSidebarWidth(); + // If we navigate away (for example to a settings page), and then use the back or // forward button to get back to a page, the theme may have changed in the meantime. // But scripts may not be re-loaded in such a case due to the bfcache @@ -214,5 +238,6 @@ if (getSettingValue("source-sidebar-show") === "true") { window.addEventListener("pageshow", ev => { if (ev.persisted) { setTimeout(updateTheme, 0); + setTimeout(updateSidebarWidth, 0); } }); |
