mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
This PR adds the "hide all but one" occlusion mode. An example use case is a note containing a collection of pairs of selection, where each selection is the prompt for the other in its pair. For example, given a table like | small | big | |-------+-----| | a | A | | b | B | | c | C | in each card, five letters are occluded, and one is shown. The user is prompted to state the occluded symbol that is adjacent to the shown symbol.
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import "./image-occlusion-base.scss";
|
|
|
|
import { ModuleName, setupI18n } from "@tslib/i18n";
|
|
import { checkNightMode } from "@tslib/nightmode";
|
|
import { get } from "svelte/store";
|
|
|
|
import { addOrUpdateNote } from "./add-or-update-note.svelte";
|
|
import ImageOcclusionPage from "./ImageOcclusionPage.svelte";
|
|
import type { IOMode } from "./lib";
|
|
import { occlusionMode } from "./store";
|
|
|
|
globalThis.anki = globalThis.anki || {};
|
|
|
|
const i18n = setupI18n({
|
|
modules: [
|
|
ModuleName.IMPORTING,
|
|
ModuleName.DECKS,
|
|
ModuleName.EDITING,
|
|
ModuleName.NOTETYPES,
|
|
ModuleName.ACTIONS,
|
|
ModuleName.BROWSING,
|
|
ModuleName.UNDO,
|
|
],
|
|
});
|
|
|
|
export async function setupImageOcclusion(mode: IOMode, target = document.body): Promise<ImageOcclusionPage> {
|
|
checkNightMode();
|
|
await i18n;
|
|
|
|
async function addNote(): Promise<void> {
|
|
addOrUpdateNote(mode, get(occlusionMode));
|
|
}
|
|
|
|
// for adding note from mobile devices
|
|
globalThis.anki.imageOcclusion = {
|
|
mode,
|
|
addNote,
|
|
};
|
|
|
|
return new ImageOcclusionPage({
|
|
target: target,
|
|
props: {
|
|
mode,
|
|
},
|
|
});
|
|
}
|
|
|
|
if (window.location.hash.startsWith("#test-")) {
|
|
const imagePath = window.location.hash.replace("#test-", "");
|
|
setupImageOcclusion({ kind: "add", imagePath, notetypeId: 0 });
|
|
}
|
|
|
|
if (window.location.hash.startsWith("#testforedit-")) {
|
|
const noteId = parseInt(window.location.hash.replace("#testforedit-", ""));
|
|
setupImageOcclusion({ kind: "edit", noteId });
|
|
}
|