mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 20:57:13 -05:00
Remove html writable
This commit is contained in:
parent
f68f5284a5
commit
ccdc391097
5 changed files with 29 additions and 49 deletions
|
|
@ -1270,7 +1270,7 @@ class SvelteReviewer(Reviewer):
|
||||||
else:
|
else:
|
||||||
maxTime = 0
|
maxTime = 0
|
||||||
self._remaining()
|
self._remaining()
|
||||||
self.bottom.web.eval("showQuestion(\"\",%d);" % (maxTime))
|
self.bottom.web.eval('showQuestion("",%d);' % (maxTime))
|
||||||
|
|
||||||
def _linkHandler(self, url: str) -> None:
|
def _linkHandler(self, url: str) -> None:
|
||||||
if url == "bottomReady":
|
if url == "bottomReady":
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<script>
|
<script>
|
||||||
import ReviewerBottomOuter from "./reviewer-bottom/ReviewerBottomOuter.svelte";
|
import ReviewerBottomOuter from "./reviewer-bottom/ReviewerBottomOuter.svelte";
|
||||||
import ReviewerOuter from "./reviewerOuter.svelte";
|
import Reviewer from "./reviewer.svelte";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<ReviewerOuter></ReviewerOuter>
|
<Reviewer></Reviewer>
|
||||||
<ReviewerBottomOuter></ReviewerBottomOuter>
|
<ReviewerBottomOuter></ReviewerBottomOuter>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { bridgeCommand } from "@tslib/bridgecommand";
|
import { setupReviewer } from "./reviewer";
|
||||||
import type { Writable } from "svelte/store";
|
|
||||||
import { isNightMode } from "../../html-filter/helpers";
|
|
||||||
|
|
||||||
export let html: Writable<string>;
|
|
||||||
export let cardClass: Writable<string>;
|
|
||||||
|
|
||||||
let iframe: HTMLIFrameElement;
|
let iframe: HTMLIFrameElement;
|
||||||
|
|
||||||
html.subscribe(($html) => {
|
$: ({ cardClass } = setupReviewer(iframe));
|
||||||
if (iframe?.contentDocument) {
|
|
||||||
iframe.contentDocument.body.innerHTML = $html;
|
|
||||||
iframe.contentDocument.head.innerHTML = document.head.innerHTML;
|
|
||||||
iframe.contentDocument.body.className = isNightMode()
|
|
||||||
? "nightMode card"
|
|
||||||
: "card";
|
|
||||||
iframe.contentDocument.querySelector("html")!.className = isNightMode()
|
|
||||||
? "night-mode"
|
|
||||||
: "";
|
|
||||||
//@ts-ignore
|
|
||||||
iframe.contentDocument.pycmd = bridgeCommand;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="qa" class={$cardClass}>
|
<div id="qa" class={$cardClass}>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,37 @@
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
import { isNightMode } from "../../html-filter/helpers";
|
||||||
import { preloadAnswerImages } from "../../reviewer/images";
|
import { preloadAnswerImages } from "../../reviewer/images";
|
||||||
|
|
||||||
export function setupReviewer() {
|
export function setupReviewer(iframe: HTMLIFrameElement) {
|
||||||
const html = writable("");
|
|
||||||
const cardClass = writable("");
|
const cardClass = writable("");
|
||||||
|
|
||||||
|
function updateHtml(htmlString) {
|
||||||
|
if (iframe?.contentDocument) {
|
||||||
|
const nightMode = isNightMode();
|
||||||
|
iframe.contentDocument.body.innerHTML = htmlString;
|
||||||
|
iframe.contentDocument.head.innerHTML = document.head.innerHTML;
|
||||||
|
iframe.contentDocument.body.className = nightMode
|
||||||
|
? "nightMode card"
|
||||||
|
: "card";
|
||||||
|
const root = iframe.contentDocument.querySelector("html")!;
|
||||||
|
root.className = nightMode
|
||||||
|
? "night-mode"
|
||||||
|
: "";
|
||||||
|
root.setAttribute("data-bs-theme", nightMode ? "dark" : "light");
|
||||||
|
// @ts-ignore
|
||||||
|
iframe.contentDocument.pycmd = bridgeCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showQuestion(q, a, cc) {
|
function showQuestion(q, a, cc) {
|
||||||
html.set(q);
|
updateHtml(q);
|
||||||
|
// html.set(q);
|
||||||
cardClass.set(cc);
|
cardClass.set(cc);
|
||||||
preloadAnswerImages(a);
|
preloadAnswerImages(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis._showAnswer = html.set;
|
globalThis._showAnswer = updateHtml;
|
||||||
globalThis._showQuestion = showQuestion;
|
globalThis._showQuestion = showQuestion;
|
||||||
|
|
||||||
return { html, cardClass };
|
return { cardClass };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<script lang="ts">
|
|
||||||
import { onMount } from "svelte";
|
|
||||||
import { setupReviewer } from "./reviewer";
|
|
||||||
import Reviewer from "./reviewer.svelte";
|
|
||||||
|
|
||||||
import "../../reviewer/reviewer.scss";
|
|
||||||
|
|
||||||
let reviewerInfo: null | ReturnType<typeof setupReviewer> = null;
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
reviewerInfo = setupReviewer();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if reviewerInfo}
|
|
||||||
<Reviewer {...reviewerInfo}></Reviewer>
|
|
||||||
{/if}
|
|
||||||
Loading…
Reference in a new issue