| | |
| | | ) |
| | | } |
| | | |
| | | document.addEventListener("nav", () => { |
| | | const links = [...document.getElementsByClassName("internal")] as HTMLLinkElement[] |
| | | const p = new DOMParser() |
| | | for (const link of links) { |
| | | link.addEventListener("mouseenter", async ({ clientX, clientY }) => { |
| | | async function mouseEnterHandler(this: HTMLLinkElement, { clientX, clientY }: { clientX: number, clientY: number }) { |
| | | const link = this |
| | | async function setPosition(popoverElement: HTMLElement) { |
| | | const { x, y } = await computePosition(link, popoverElement, { |
| | | middleware: [ |
| | |
| | | }) |
| | | } |
| | | |
| | | if (link.dataset.fetchedPopover === "true") { |
| | | // dont refetch if there's already a popover |
| | | if ([...link.children].some(child => child.classList.contains("popover"))) { |
| | | return setPosition(link.lastChild as HTMLElement) |
| | | } |
| | | |
| | |
| | | |
| | | setPosition(popoverElement) |
| | | link.appendChild(popoverElement) |
| | | link.dataset.fetchedPopover = "true" |
| | | |
| | | if (hash !== "") { |
| | | const heading = popoverInner.querySelector(hash) as HTMLElement | null |
| | |
| | | popoverInner.scroll({ top: heading.offsetTop - 12, behavior: 'instant' }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | document.addEventListener("nav", () => { |
| | | const links = [...document.getElementsByClassName("internal")] as HTMLLinkElement[] |
| | | for (const link of links) { |
| | | link.removeEventListener("mouseenter", mouseEnterHandler) |
| | | link.addEventListener("mouseenter", mouseEnterHandler) |
| | | } |
| | | }) |