Skip to content

Commit

Permalink
fix: fix dblclick fail to open footnote when footnote not in active dom
Browse files Browse the repository at this point in the history
fix #8
  • Loading branch information
aidenlx committed Jun 9, 2021
1 parent 91c3739 commit 4931509
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
13 changes: 3 additions & 10 deletions src/modules/renderChild.ts
Expand Up @@ -114,16 +114,9 @@ export function createPopover(
});

refEl.addEventListener("dblclick", (evt) => {
const id = refEl.dataset.footnoteLink;
if (showButtom && id) {
const li = document.getElementById(id);
if (!li) {
console.error("element not found: %s", id);
return;
}
li.scrollIntoView();
li.addClass("is-flashing");
setTimeout(() => li.removeClass("is-flashing"), 1e3);
const child = refEl.firstElementChild;
if (child instanceof HTMLAnchorElement && showButtom) {
child.click();
}
});

Expand Down
13 changes: 7 additions & 6 deletions src/processor.ts
Expand Up @@ -70,13 +70,14 @@ export const PopoverHandler: MarkdownPostProcessor = function (
// >
const sup = v as HTMLElement;

const { id: refId, innerText: srcText } = sup;
const { id: refId } = sup;
const { sourcePath } = ctx;
sup.dataset.footnoteLink = (sup.firstElementChild as HTMLAnchorElement).href
.split("#")
.pop();
sup.empty();
sup.innerText = srcText;
const child = sup.firstElementChild
if (child instanceof HTMLAnchorElement) {
sup.appendText(child.innerText);
child.innerText = "";
}
else console.error("first child not anchor");
sup.setAttr("aria-describedby", refId.replace(/^fnref-/, "pp-"));

if (infoList.has(refId)) {
Expand Down

0 comments on commit 4931509

Please sign in to comment.