Skip to content

Commit 1b4b78d

Browse files
committed
Take advantage of querySelector overload
1 parent 01509e0 commit 1b4b78d

File tree

1 file changed

+13
-15
lines changed
  • src/librustdoc/html/static/js

1 file changed

+13
-15
lines changed

src/librustdoc/html/static/js/main.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -1790,14 +1790,12 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
17901790
*/
17911791
let pendingSidebarResizingFrame = false;
17921792

1793-
/** @type {HTMLElement} */
1794-
// @ts-expect-error
1793+
/** @type {HTMLElement|null} */
17951794
const resizer = document.querySelector(".sidebar-resizer");
1796-
/** @type {HTMLElement} */
1797-
// @ts-expect-error
1795+
/** @type {HTMLElement|null} */
17981796
const sidebar = document.querySelector(".sidebar");
17991797
// If this page has no sidebar at all, bail out.
1800-
if (!(resizer instanceof HTMLElement) || !(sidebar instanceof HTMLElement)) {
1798+
if (!resizer || !sidebar) {
18011799
return;
18021800
}
18031801

@@ -1813,7 +1811,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18131811
// from settings.js, which uses a separate function. It's done here because
18141812
// the minimum sidebar size is rather uncomfortable, and it must pass
18151813
// through that size when using the shrink-to-nothing gesture.
1816-
function hideSidebar() {
1814+
const hideSidebar = function hideSidebar() {
18171815
if (isSrcPage) {
18181816
window.rustdocCloseSourceSidebar();
18191817
updateLocalStorage("src-sidebar-width", null);
@@ -1838,30 +1836,30 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18381836
sidebar.style.removeProperty("--desktop-sidebar-width");
18391837
resizer.style.removeProperty("--desktop-sidebar-width");
18401838
}
1841-
}
1839+
};
18421840

18431841
// Call this function to show the sidebar from the resize handle.
18441842
// On docs pages, this can only happen if the user has grabbed the resize
18451843
// handle, shrunk the sidebar down to nothing, and then pulls back into
18461844
// the visible range without releasing it. You can, however, grab the
18471845
// resize handle on a source page with the sidebar closed, because it
18481846
// remains visible all the time on there.
1849-
function showSidebar() {
1847+
const showSidebar = function showSidebar() {
18501848
if (isSrcPage) {
18511849
window.rustdocShowSourceSidebar();
18521850
} else {
18531851
removeClass(document.documentElement, "hide-sidebar");
18541852
updateLocalStorage("hide-sidebar", "false");
18551853
}
1856-
}
1854+
};
18571855

18581856
/**
18591857
* Call this to set the correct CSS variable and setting.
18601858
* This function doesn't enforce size constraints. Do that before calling it!
18611859
*
18621860
* @param {number} size - CSS px width of the sidebar.
18631861
*/
1864-
function changeSidebarSize(size) {
1862+
const changeSidebarSize = function changeSidebarSize(size) {
18651863
if (isSrcPage) {
18661864
updateLocalStorage("src-sidebar-width", size.toString());
18671865
// [RUSTDOCIMPL] CSS variable fast path
@@ -1877,7 +1875,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
18771875
sidebar.style.setProperty("--desktop-sidebar-width", size + "px");
18781876
resizer.style.setProperty("--desktop-sidebar-width", size + "px");
18791877
}
1880-
}
1878+
};
18811879

18821880
// Check if the sidebar is hidden. Since src pages and doc pages have
18831881
// different settings, this function has to check that.
@@ -1942,7 +1940,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
19421940
/**
19431941
* @param {PointerEvent=} e
19441942
*/
1945-
function stopResize(e) {
1943+
const stopResize = function stopResize(e) {
19461944
if (currentPointerId === null) {
19471945
return;
19481946
}
@@ -1959,12 +1957,12 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
19591957
resizer.releasePointerCapture(currentPointerId);
19601958
currentPointerId = null;
19611959
}
1962-
}
1960+
};
19631961

19641962
/**
19651963
* @param {PointerEvent} e
19661964
*/
1967-
function initResize(e) {
1965+
const initResize = function initResize(e) {
19681966
if (currentPointerId !== null || e.altKey || e.ctrlKey || e.metaKey || e.button !== 0) {
19691967
return;
19701968
}
@@ -1988,7 +1986,7 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
19881986
const pos = e.clientX - sidebar.offsetLeft - 3;
19891987
document.documentElement.style.setProperty( "--resizing-sidebar-width", pos + "px");
19901988
desiredSidebarSize = null;
1991-
}
1989+
};
19921990
resizer.addEventListener("pointerdown", initResize, false);
19931991
}());
19941992

0 commit comments

Comments
 (0)