mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 06:24:22 +02:00
fix(popover): clear popovers more aggressively, use href as id
Some checks failed
Build and Test / build-and-test (ubuntu-latest) (push) Has been skipped
Build and Test / publish-tag (push) Has been skipped
Build and Test / build-and-test (macos-latest) (push) Has been cancelled
Build and Test / build-and-test (windows-latest) (push) Has been cancelled
Some checks failed
Build and Test / build-and-test (ubuntu-latest) (push) Has been skipped
Build and Test / publish-tag (push) Has been skipped
Build and Test / build-and-test (macos-latest) (push) Has been cancelled
Build and Test / build-and-test (windows-latest) (push) Has been cancelled
This commit is contained in:
parent
091cc1b05e
commit
bfd72347cf
@ -1,7 +1,6 @@
|
|||||||
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
import { computePosition, flip, inline, shift } from "@floating-ui/dom"
|
||||||
import { normalizeRelativeURLs } from "../../util/path"
|
import { normalizeRelativeURLs } from "../../util/path"
|
||||||
import { fetchCanonical } from "./util"
|
import { fetchCanonical } from "./util"
|
||||||
import { randomIdNonSecure } from "../../util/random"
|
|
||||||
|
|
||||||
const p = new DOMParser()
|
const p = new DOMParser()
|
||||||
|
|
||||||
@ -25,6 +24,7 @@ async function mouseEnterHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showPopover(popoverElement: HTMLElement) {
|
function showPopover(popoverElement: HTMLElement) {
|
||||||
|
clearActivePopover()
|
||||||
popoverElement.classList.add("active-popover")
|
popoverElement.classList.add("active-popover")
|
||||||
setPosition(popoverElement as HTMLElement)
|
setPosition(popoverElement as HTMLElement)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ async function mouseEnterHandler(
|
|||||||
const hash = decodeURIComponent(targetUrl.hash)
|
const hash = decodeURIComponent(targetUrl.hash)
|
||||||
targetUrl.hash = ""
|
targetUrl.hash = ""
|
||||||
targetUrl.search = ""
|
targetUrl.search = ""
|
||||||
const popoverId = `popover-${link.dataset.slug ?? randomIdNonSecure()}`
|
const popoverId = `popover-${link.pathname}`
|
||||||
const prevPopoverElement = document.getElementById(popoverId)
|
const prevPopoverElement = document.getElementById(popoverId)
|
||||||
const hasAlreadyBeenFetched = () => !!document.getElementById(popoverId)
|
const hasAlreadyBeenFetched = () => !!document.getElementById(popoverId)
|
||||||
|
|
||||||
@ -117,10 +117,10 @@ function clearActivePopover() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
const links = [...document.getElementsByClassName("internal")] as HTMLAnchorElement[]
|
const links = [...document.querySelectorAll("a.internal")] as HTMLAnchorElement[]
|
||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
link.addEventListener("mouseleave", clearActivePopover)
|
|
||||||
link.addEventListener("mouseenter", mouseEnterHandler)
|
link.addEventListener("mouseenter", mouseEnterHandler)
|
||||||
|
link.addEventListener("mouseleave", clearActivePopover)
|
||||||
window.addCleanup(() => {
|
window.addCleanup(() => {
|
||||||
link.removeEventListener("mouseenter", mouseEnterHandler)
|
link.removeEventListener("mouseenter", mouseEnterHandler)
|
||||||
link.removeEventListener("mouseleave", clearActivePopover)
|
link.removeEventListener("mouseleave", clearActivePopover)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user