diff options
| author | bors <bors@rust-lang.org> | 2022-07-01 11:09:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-01 11:09:35 +0000 |
| commit | ca1e68b3229e710c3948a361ee770d846a88e6da (patch) | |
| tree | cbd0e8977b42bd32f8ab140f36f825a9d8d74ed6 /src/librustdoc/html/static/js/source-script.js | |
| parent | 7e2733bb1dd9afe5fd20370ca4d539d42ac50419 (diff) | |
| parent | 6e918b4a97c8a2cb0923a639d76f840ac63b76c7 (diff) | |
| download | rust-ca1e68b3229e710c3948a361ee770d846a88e6da.tar.gz rust-ca1e68b3229e710c3948a361ee770d846a88e6da.zip | |
Auto merge of #98730 - matthiaskrgr:rollup-2c4d4x5, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #97629 ([core] add `Exclusive` to sync) - #98503 (fix data race in thread::scope) - #98670 (llvm-wrapper: adapt for LLVMConstExtractValue removal) - #98671 (Fix source sidebar bugs) - #98677 (For diagnostic information of Boolean, remind it as use the type: 'bool') - #98684 (add test for 72793) - #98688 (interpret: add From<&MplaceTy> for PlaceTy) - #98695 (use "or pattern") - #98709 (Remove unneeded methods declaration for old web browsers) - #98717 (get rid of tidy 'unnecessarily ignored' warnings) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/librustdoc/html/static/js/source-script.js')
| -rw-r--r-- | src/librustdoc/html/static/js/source-script.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 290c29d3141..acb1d8d7b5c 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -10,6 +10,7 @@ (function() { const rootPath = document.getElementById("rustdoc-vars").attributes["data-root-path"].value; +let oldScrollPosition = 0; function createDirEntry(elem, parent, fullPath, hasFoundFile) { const name = document.createElement("div"); @@ -65,10 +66,24 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) { function toggleSidebar() { const child = this.children[0]; if (child.innerText === ">") { + if (window.innerWidth < 701) { + // This is to keep the scroll position on mobile. + oldScrollPosition = window.scrollY; + document.body.style.position = "fixed"; + document.body.style.top = `-${oldScrollPosition}px`; + } addClass(document.documentElement, "source-sidebar-expanded"); child.innerText = "<"; updateLocalStorage("source-sidebar-show", "true"); } else { + if (window.innerWidth < 701) { + // This is to keep the scroll position on mobile. + document.body.style.position = ""; + document.body.style.top = ""; + // The scroll position is lost when resetting the style, hence why we store it in + // `oldScroll`. + window.scrollTo(0, oldScrollPosition); + } removeClass(document.documentElement, "source-sidebar-expanded"); child.innerText = ">"; updateLocalStorage("source-sidebar-show", "false"); |
