Cao Mingjun
2024-07-08 4eeacb7fbf0059f47317d813a9077437c75ce2f6
Fix Non-English Anchor Popover Positioning Issue and Update Type Hint (#1252)

- [Major] Changed `hash` passed to `querySelector` to `decodeURIComponent(hash)` to fix the issue where non-English anchors were not correctly positioning the popover content to the corresponding title.
- [Minor] Updated the type hint from `HTMLLinkElement` to `HTMLAnchorElement` as the passed element is an `<a>` element, not a `<link>` element (reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement).
1 files modified
6 ■■■■ changed files
quartz/components/scripts/popover.inline.ts 6 ●●●● patch | view | raw | blame | history
quartz/components/scripts/popover.inline.ts
@@ -3,7 +3,7 @@
const p = new DOMParser()
async function mouseEnterHandler(
  this: HTMLLinkElement,
  this: HTMLAnchorElement,
  { clientX, clientY }: { clientX: number; clientY: number },
) {
  const link = this
@@ -33,7 +33,7 @@
  thisUrl.hash = ""
  thisUrl.search = ""
  const targetUrl = new URL(link.href)
  const hash = targetUrl.hash
  const hash = decodeURIComponent(targetUrl.hash)
  targetUrl.hash = ""
  targetUrl.search = ""
@@ -100,7 +100,7 @@
}
document.addEventListener("nav", () => {
  const links = [...document.getElementsByClassName("internal")] as HTMLLinkElement[]
  const links = [...document.getElementsByClassName("internal")] as HTMLAnchorElement[]
  for (const link of links) {
    link.addEventListener("mouseenter", mouseEnterHandler)
    window.addCleanup(() => link.removeEventListener("mouseenter", mouseEnterHandler))