Generalize accesing anki-mathjax from image in MathjaxHandle

This commit is contained in:
Henrik Giesel 2021-08-08 02:32:59 +02:00
parent b6bea18b22
commit c02973a85d

View file

@ -31,8 +31,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let updateSelection: () => void;
let title: string;
function getComponent(image: HTMLImageElement): HTMLElement {
return (image.closest("anki-mathjax")! as HTMLElement);
}
function onUpdate(event: CustomEvent) {
activeImage!.parentElement!.dataset.mathjax = event.detail.mathjax;
getComponent(activeImage!).dataset.mathjax = event.detail.mathjax;
setTimeout(() => {
updateSelection();
title = activeImage!.title;
@ -63,7 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<DropdownMenu>
<MathjaxHandleEditor
initialValue={activeImage.parentElement?.dataset.mathjax ?? ""}
initialValue={getComponent(activeImage).dataset.mathjax ?? ""}
on:update={(event) => {
onUpdate(event);
setTimeout(dropdownObject.update);