Let it const

This commit is contained in:
Emile Bangma 2025-04-04 23:53:53 +00:00 committed by GitHub
parent 3ef20bfb58
commit 7c46da37a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,7 +34,7 @@ async function mouseEnterHandler(
thisUrl.hash = "" thisUrl.hash = ""
thisUrl.search = "" thisUrl.search = ""
const targetUrl = new URL(link.href) const targetUrl = new URL(link.href)
let hash = decodeURIComponent(targetUrl.hash) const hash = decodeURIComponent(targetUrl.hash)
targetUrl.hash = "" targetUrl.hash = ""
targetUrl.search = "" targetUrl.search = ""
@ -87,8 +87,6 @@ async function mouseEnterHandler(
const targetID = `popover-${el.id}` const targetID = `popover-${el.id}`
el.id = targetID el.id = targetID
}) })
const targetLink = hash.startsWith("#popover") ? hash : `#popover-${hash.slice(1)}`
hash = targetLink
const elts = [...html.getElementsByClassName("popover-hint")] const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return if (elts.length === 0) return
@ -99,7 +97,8 @@ async function mouseEnterHandler(
link.appendChild(popoverElement) link.appendChild(popoverElement)
if (hash !== "") { if (hash !== "") {
const heading = popoverInner.querySelector(hash) as HTMLElement | null const targetAnchor = hash.startsWith("#popover") ? hash : `#popover-${hash.slice(1)}`
const heading = popoverInner.querySelector(targetAnchor) as HTMLElement | null
if (heading) { if (heading) {
// leave ~12px of buffer when scrolling to a heading // leave ~12px of buffer when scrolling to a heading
popoverInner.scroll({ top: heading.offsetTop - 12, behavior: "instant" }) popoverInner.scroll({ top: heading.offsetTop - 12, behavior: "instant" })