mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Properly dispose of tooltip resources when unmounting
This commit is contained in:
parent
97692e4c28
commit
9a00ef5a81
1 changed files with 10 additions and 1 deletions
|
@ -3,19 +3,28 @@
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onDestroy } from "svelte";
|
||||||
import Tooltip from "bootstrap/js/dist/tooltip";
|
import Tooltip from "bootstrap/js/dist/tooltip";
|
||||||
|
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
|
let tooltipObject: Tooltip;
|
||||||
|
|
||||||
function createTooltip(element: HTMLElement): void {
|
function createTooltip(element: HTMLElement): void {
|
||||||
element.title = tooltip;
|
element.title = tooltip;
|
||||||
new Tooltip(element, {
|
tooltipObject = new Tooltip(element, {
|
||||||
placement: "bottom",
|
placement: "bottom",
|
||||||
html: true,
|
html: true,
|
||||||
offset: [0, 20],
|
offset: [0, 20],
|
||||||
delay: { show: 250, hide: 0 },
|
delay: { show: 250, hide: 0 },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (tooltipObject) {
|
||||||
|
tooltipObject.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<slot {createTooltip} />
|
<slot {createTooltip} />
|
||||||
|
|
Loading…
Reference in a new issue