From 2a6619a5c0b907cb56c87d7473be032e80ae4ac1 Mon Sep 17 00:00:00 2001 From: Illia Harkusha Date: Sat, 24 Aug 2024 10:55:57 +0300 Subject: [PATCH 1/3] Back card side automatic swap for Anki Desktop pre- and post-v24.06 fix - See [the discussion comment](https://github.com/anki-geo/ultimate-geography/discussions/649#discussioncomment-10433459) for the details --- .../experimental_assets/_ug-interactive_map_init.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/media/experimental_assets/_ug-interactive_map_init.js b/src/media/experimental_assets/_ug-interactive_map_init.js index 32d48b53..026aa6cf 100644 --- a/src/media/experimental_assets/_ug-interactive_map_init.js +++ b/src/media/experimental_assets/_ug-interactive_map_init.js @@ -165,10 +165,20 @@ if (typeof AnkiDroidJS !== "undefined") { showAnswer(); } else { - commonElements.hiddenTextarea.dispatchEvent(new KeyboardEvent("keypress", {code: "Enter"})); + dispatchEnterEvent() } } + /** + * Trigger "Enter" key press event. Note that Anki < 24.06 + * uses `code` property and Anki >= 24.06 - `key` property + * to query pressed key, so both properties must be present + */ + function dispatchEnterEvent() { + let artificialEvent = new KeyboardEvent("keypress", {code: "Enter", key: "Enter"}); + commonElements.hiddenTextarea.dispatchEvent(artificialEvent); + } + /** * Retrieve region highlighting color for answer card side * depending on the configuration and whether the selected From 496ebae4735232009dc99e5ed49ae841fbaa727f Mon Sep 17 00:00:00 2001 From: Illia Harkusha Date: Sat, 24 Aug 2024 12:50:49 +0300 Subject: [PATCH 2/3] Initialization script documentation added - Specifically the intention of the introduced documentation is to keep a notice of the reasoning of IIFE usage --- src/media/experimental_assets/_ug-interactive_map_init.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/media/experimental_assets/_ug-interactive_map_init.js b/src/media/experimental_assets/_ug-interactive_map_init.js index 026aa6cf..7b79533a 100644 --- a/src/media/experimental_assets/_ug-interactive_map_init.js +++ b/src/media/experimental_assets/_ug-interactive_map_init.js @@ -1,3 +1,8 @@ +/** + * Interactive map initialization logic declaration. + * Note that due to Anki Desktop web view being persistent + * for card reviews IIFE is used to separate the namespaces + */ (function () { const mapConfig = getMapConfig(); const commonConfig = mapConfig.commonConfig; From e0b0f47e4bb5938a75bb4fc738f670ea4e5e7b0c Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Sat, 24 Aug 2024 11:55:50 +0200 Subject: [PATCH 3/3] Update src/media/experimental_assets/_ug-interactive_map_init.js --- src/media/experimental_assets/_ug-interactive_map_init.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/media/experimental_assets/_ug-interactive_map_init.js b/src/media/experimental_assets/_ug-interactive_map_init.js index 7b79533a..0cf8f320 100644 --- a/src/media/experimental_assets/_ug-interactive_map_init.js +++ b/src/media/experimental_assets/_ug-interactive_map_init.js @@ -175,8 +175,8 @@ } /** - * Trigger "Enter" key press event. Note that Anki < 24.06 - * uses `code` property and Anki >= 24.06 - `key` property + * Trigger "Enter" key press event. Note that Anki < 24.06 + * uses `code` property and Anki >= 24.06 - `key` property * to query pressed key, so both properties must be present */ function dispatchEnterEvent() {