From 1b4b78d075da2b384f8f5e85e4442dbd1b52734a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 1 Feb 2025 08:43:26 -0700 Subject: [PATCH] Take advantage of querySelector overload --- src/librustdoc/html/static/js/main.js | 28 +++++++++++++-------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index c8fff63221cb..a9eee808b05a 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1790,14 +1790,12 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm */ let pendingSidebarResizingFrame = false; - /** @type {HTMLElement} */ - // @ts-expect-error + /** @type {HTMLElement|null} */ const resizer = document.querySelector(".sidebar-resizer"); - /** @type {HTMLElement} */ - // @ts-expect-error + /** @type {HTMLElement|null} */ const sidebar = document.querySelector(".sidebar"); // If this page has no sidebar at all, bail out. - if (!(resizer instanceof HTMLElement) || !(sidebar instanceof HTMLElement)) { + if (!resizer || !sidebar) { return; } @@ -1813,7 +1811,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm // from settings.js, which uses a separate function. It's done here because // the minimum sidebar size is rather uncomfortable, and it must pass // through that size when using the shrink-to-nothing gesture. - function hideSidebar() { + const hideSidebar = function hideSidebar() { if (isSrcPage) { window.rustdocCloseSourceSidebar(); updateLocalStorage("src-sidebar-width", null); @@ -1838,7 +1836,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm sidebar.style.removeProperty("--desktop-sidebar-width"); resizer.style.removeProperty("--desktop-sidebar-width"); } - } + }; // Call this function to show the sidebar from the resize handle. // On docs pages, this can only happen if the user has grabbed the resize @@ -1846,14 +1844,14 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm // the visible range without releasing it. You can, however, grab the // resize handle on a source page with the sidebar closed, because it // remains visible all the time on there. - function showSidebar() { + const showSidebar = function showSidebar() { if (isSrcPage) { window.rustdocShowSourceSidebar(); } else { removeClass(document.documentElement, "hide-sidebar"); updateLocalStorage("hide-sidebar", "false"); } - } + }; /** * Call this to set the correct CSS variable and setting. @@ -1861,7 +1859,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm * * @param {number} size - CSS px width of the sidebar. */ - function changeSidebarSize(size) { + const changeSidebarSize = function changeSidebarSize(size) { if (isSrcPage) { updateLocalStorage("src-sidebar-width", size.toString()); // [RUSTDOCIMPL] CSS variable fast path @@ -1877,7 +1875,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm sidebar.style.setProperty("--desktop-sidebar-width", size + "px"); resizer.style.setProperty("--desktop-sidebar-width", size + "px"); } - } + }; // Check if the sidebar is hidden. Since src pages and doc pages have // different settings, this function has to check that. @@ -1942,7 +1940,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm /** * @param {PointerEvent=} e */ - function stopResize(e) { + const stopResize = function stopResize(e) { if (currentPointerId === null) { return; } @@ -1959,12 +1957,12 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm resizer.releasePointerCapture(currentPointerId); currentPointerId = null; } - } + }; /** * @param {PointerEvent} e */ - function initResize(e) { + const initResize = function initResize(e) { if (currentPointerId !== null || e.altKey || e.ctrlKey || e.metaKey || e.button !== 0) { return; } @@ -1988,7 +1986,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm const pos = e.clientX - sidebar.offsetLeft - 3; document.documentElement.style.setProperty( "--resizing-sidebar-width", pos + "px"); desiredSidebarSize = null; - } + }; resizer.addEventListener("pointerdown", initResize, false); }());