|
4 | 4 |
|
5 | 5 | "use strict"; |
6 | 6 |
|
7 | | -// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY |
8 | | -// If you update this line, then you also need to update the media query with the same |
9 | | -// warning in rustdoc.css |
10 | | -window.RUSTDOC_MOBILE_BREAKPOINT = 700; |
11 | | - |
12 | 7 | // Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL |
13 | 8 | // for a resource under the root-path, with the resource-suffix. |
14 | 9 | function resourcePath(basename, extension) { |
@@ -739,65 +734,18 @@ function preLoadCss(cssUrl) { |
739 | 734 | window.rustdoc_add_line_numbers_to_examples(); |
740 | 735 | } |
741 | 736 |
|
742 | | - let oldSidebarScrollPosition = null; |
743 | | - |
744 | | - // Scroll locking used both here and in source-script.js |
745 | | - |
746 | | - window.rustdocMobileScrollLock = function() { |
747 | | - const mobile_topbar = document.querySelector(".mobile-topbar"); |
748 | | - if (window.innerWidth <= window.RUSTDOC_MOBILE_BREAKPOINT) { |
749 | | - // This is to keep the scroll position on mobile. |
750 | | - oldSidebarScrollPosition = window.scrollY; |
751 | | - document.body.style.width = `${document.body.offsetWidth}px`; |
752 | | - document.body.style.position = "fixed"; |
753 | | - document.body.style.top = `-${oldSidebarScrollPosition}px`; |
754 | | - if (mobile_topbar) { |
755 | | - mobile_topbar.style.top = `${oldSidebarScrollPosition}px`; |
756 | | - mobile_topbar.style.position = "relative"; |
757 | | - } |
758 | | - } else { |
759 | | - oldSidebarScrollPosition = null; |
760 | | - } |
761 | | - }; |
762 | | - |
763 | | - window.rustdocMobileScrollUnlock = function() { |
764 | | - const mobile_topbar = document.querySelector(".mobile-topbar"); |
765 | | - if (oldSidebarScrollPosition !== null) { |
766 | | - // This is to keep the scroll position on mobile. |
767 | | - document.body.style.width = ""; |
768 | | - document.body.style.position = ""; |
769 | | - document.body.style.top = ""; |
770 | | - if (mobile_topbar) { |
771 | | - mobile_topbar.style.top = ""; |
772 | | - mobile_topbar.style.position = ""; |
773 | | - } |
774 | | - // The scroll position is lost when resetting the style, hence why we store it in |
775 | | - // `oldSidebarScrollPosition`. |
776 | | - window.scrollTo(0, oldSidebarScrollPosition); |
777 | | - oldSidebarScrollPosition = null; |
778 | | - } |
779 | | - }; |
780 | | - |
781 | 737 | function showSidebar() { |
782 | 738 | window.hideAllModals(false); |
783 | | - window.rustdocMobileScrollLock(); |
784 | 739 | const sidebar = document.getElementsByClassName("sidebar")[0]; |
785 | 740 | addClass(sidebar, "shown"); |
786 | 741 | } |
787 | 742 |
|
788 | 743 | function hideSidebar() { |
789 | | - window.rustdocMobileScrollUnlock(); |
790 | 744 | const sidebar = document.getElementsByClassName("sidebar")[0]; |
791 | 745 | removeClass(sidebar, "shown"); |
792 | 746 | } |
793 | 747 |
|
794 | 748 | window.addEventListener("resize", () => { |
795 | | - if (window.innerWidth > window.RUSTDOC_MOBILE_BREAKPOINT && |
796 | | - oldSidebarScrollPosition !== null) { |
797 | | - // If the user opens the sidebar in "mobile" mode, and then grows the browser window, |
798 | | - // we need to switch away from mobile mode and make the main content area scrollable. |
799 | | - hideSidebar(); |
800 | | - } |
801 | 749 | if (window.CURRENT_TOOLTIP_ELEMENT) { |
802 | 750 | // As a workaround to the behavior of `contains: layout` used in doc togglers, |
803 | 751 | // tooltip popovers are positioned using javascript. |
|
0 commit comments