Skip to content

Commit 1564f8d

Browse files
committed
Adapt to AnkiDroid JS, bug fix expose
1 parent a94d7bb commit 1564f8d

9 files changed

Lines changed: 525 additions & 213 deletions

File tree

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{
5656
"label": "Build templates",
5757
"type": "shell",
58-
"command": "Write-host Building templates... ; cp ./src/html/* ./bin | Out-Null",
58+
"command": "Write-host Building templates... ; cp ./src/html/*.css ./bin | Out-Null; Get-Content -Raw ./src/html/fc2.html | %{$_.Replace('/*--###CFG###--*/', $(Get-Content -Raw ./src/html/cfg_front.js))} | Out-File ./bin/fc2-front.html; Get-Content -Raw ./src/html/fc2.html | %{$_.Replace('/*--###CFG###--*/', $(Get-Content -Raw ./src/html/cfg_back.js))} | Out-File ./bin/fc2-back.html;",
5959
"options": {
6060
"cwd": "${workspaceFolder}"
6161
},
@@ -74,7 +74,7 @@
7474
{
7575
"label": "Build update",
7676
"type": "shell",
77-
"command": "Write-host Building update... ; rm -R -Force ./dist/*; rm -R -Force ./bin/__pycache__; Get-ChildItem -Path ./bin/*, ./README.md, ./LICENSE | Compress-Archive -Force -DestinationPath ./dist/update.zip; pandoc -t ${env:CODEPATH}/pandoc/anki-addon.lua --abbreviations=${env:CODEPATH}/pandoc/empty ./README.md -o ./dist/update.txt | Out-Null",
77+
"command": "Write-host Building update... ; rm -R -Force ./dist/*; rm -R -Force ./bin/__pycache__; Get-ChildItem -Path ./bin/*.html, ./bin/*.py, ./bin/*.css, ./README.md, ./LICENSE | Compress-Archive -Force -DestinationPath ./dist/update.zip; pandoc -t ${env:CODEPATH}/pandoc/anki-addon.lua --abbreviations=${env:CODEPATH}/pandoc/empty ./README.md -o ./dist/update.txt | Out-Null",
7878
"options": {
7979
"cwd": "${workspaceFolder}"
8080
},

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Reimplementation of [Flexible cloze](https://ankiweb.net/shared/info/1632356464)
66

77
**ALL CREDIT FOR INNOVATION GOES TO TRGANKI AND RISINGORANGE**
88

9-
![](https://github.com/TRIAEIOU/flexible-cloze-2/blob/main/Screenshots/front-and-back.png){height=500px}
9+
![](https://raw.githubusercontent.com/TRIAEIOU/flexible-cloze-2/main/Screenshots/front-and-back.png){height=500px}
1010

1111
## General
1212

13-
Configuration is made in the note template, configuration is made between `<!-- CONFIGURATION BEGIN`/`END -->` on the `Front`/`Back Template` respectively. Styling is made between `/*-- STYLE BEGIN`/`END --*/` of the `Styling` page. JS/CSS between `<!-- FUNCTIONALITY BEGIN`/`END -->` tags is the actual FC2 code, not for configuration (will be overwritten on next update). The update logic is dependent on the user keeping the `<!-- FC2/CONFIGURATION/FUNCTIONALITY BEGIN/END -->` (and equivalent in the `Styling` page) intact.
13+
Configuration is made in the note template, configuration is made between `/*-- CONFIGURATION BEGIN`/`END --*/` on the `Front`/`Back`/`Styling` template respectively. JS/CSS between `/*-- FUNCTIONALITY BEGIN`/`END --*/` tags is the actual FC2 code, not for configuration (will be overwritten on next update). The update logic is dependent on the user keeping the `/*-- CONFIGURATION/FUNCTIONALITY BEGIN/END --*/` intact.
1414

1515
- Clicking an active cloze on the front side will cycle it between hint (if there is one) and show.
1616
- Clicking an inactive cloze on the front side will cycle it between hide and show (no hint).
@@ -33,7 +33,7 @@ font-size: 15px; font-weight: bold; padding: 5px; border-bottom: 1px solid white
3333
- Active cloze: Cloze(s) with the current ordinal, i.e. the cloze(s) that should be answered. To change styling of these change or override `.cloze` class in `Styling` of the card template.
3434
- Inactive cloze: Cloze(s) that are not the current ordinal, i.e. the cloze(s) that should not be answered. To change styling of these change or override `.cloze-inactive` class in `Styling` of the card template.
3535
- Exposed cloze: Cloze(s) that when inactive (see above) will always be in "shown" state. Mark a cloze as exposed in the editor by making the first character an exclamation mark (e.g. `{{c1::!This will always be displayed when the cloze ordinal is not 1}}`).
36-
- Configurable expose character(s), default is `!`
36+
- Configurable expose character, default is `!`
3737
- Configurable position of the expose position to allow use with {{type:cloze:Text}}:
3838
- pre: **!**{{c1::content}}
3939
- begin (default): {{c1::**!**content}}
@@ -76,7 +76,7 @@ var config = {
7676
prompt: '[...]' // Prompt when no hint
7777
hint: '[%h]', // %h is replaced with hint text
7878
expose: {
79-
chars: '!', // Char(s) to mark exposed cloze
79+
char: '!', // Char to mark exposed cloze
8080
pos: 'begin', // Char pos: `pre`, `begin`, `end` or `post`
8181
reverse: false // If true exposed clozes are hidden, others shown
8282
},
@@ -111,7 +111,7 @@ span.cloze {color: blue; font-weight: bold;}
111111

112112
## Main difference from the earlier mentioned add-ons
113113

114-
There is effectively no add-on, it's all JavaScript (and HTML/CSS) and runs 100% "client side" (the only python is the update logic). The logic requires an Anki version based on the 2.15.56 back end (i.e. Anki desktop 2.15.56, AnkiDroid 2.XYZ or AnkiMobile 2.XYZ).
114+
There is effectively no add-on, it's all JavaScript (and HTML/CSS) and runs 100% "client side" (the only python is the update logic). The logic requires an Anki version based on the 2.15.56 back end (i.e. Anki desktop 2.15.56, AnkiDroid 2.16alpha93 with `Use new backend` enabled or AnkiMobile 2.XYZ).
115115

116116
- Included is my note styling and configuration (the way it functions and which fields are present are more or less a complete rip-off from RisingOrange). However, you can edit the note type however you want if you know a little HTML and CSS.
117117
- This allows for keeping related content on the same note facilitating note creation (no need to search through the deck to see if you already added a card with similar content). It can also help when reviewing as you can look at the other related clozes if you need to check something (e.g. "Well if it wasn't that, what was it?"). This is how I design my notes, hence the layout.
@@ -129,3 +129,4 @@ There is effectively no add-on, it's all JavaScript (and HTML/CSS) and runs 100%
129129
## Changelog
130130

131131
- 2023-01-23: Fix update logic bugs.
132+
- 2023-02-07: Adapt JS to AnkiDroid behaviour, fix [expose bug](https://github.com/TRIAEIOU/flexible-cloze-2/issues/4).

src/html/cfg_back.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var config = {
2+
prompt: '', // Prompt when no hint
3+
hint: '[%h]', // %h is replaced with hint text
4+
expose: {
5+
char: '!', // Char to mark exposed cloze
6+
pos: 'begin', // Char pos: `pre`, `begin`, `end` or `post`
7+
reverse: false // If true exposed clozes are hidden, others shown
8+
},
9+
scroll: { // Valid values: `none`, `min`, `center` or `context`
10+
initial: 'center', // Scoll on initial show
11+
click: 'min', // Scroll on cloze click
12+
iterate: 'min' // Scroll on iteration
13+
},
14+
iteration: {
15+
top: false, // Always start iteration from top
16+
loop: true, // Restart from top/bottom from end
17+
hide: false // Hide cloze iterated away from
18+
},
19+
shortcuts: {
20+
next: 'j', // Iterate to next cloze
21+
previous: 'h', // Iterate to previous cloze
22+
toggle_all: 'k' // Toggle all clozes and fields
23+
},
24+
show: { // `false` means initially collapsed/hidden
25+
inactive: false, // Inactive clozes
26+
additional: true, // Additional fields (Note, Mnemonics etc.)
27+
info: true // Information field
28+
}
29+
}
30+
/*-- CONFIGURATION END --*/
31+
32+
/*-- FUNCTIONALITY BEGIN --*/
33+
config.specific = null
34+
var container
35+
if (!container) container = document.querySelector('#fc2-title').parentElement
36+
container.classList.remove('front')
37+
container.classList.add('back')

src/html/cfg_front.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var config = {
2+
prompt: '', // Prompt when no hint
3+
hint: '%h', // %h is replaced with hint text
4+
expose: {
5+
char: '!', // Char to mark exposed cloze
6+
pos: 'begin', // Char pos: `pre`, `begin`, `end` or `post`
7+
reverse: false // If true exposed clozes are hidden, others shown
8+
},
9+
scroll: { // Valid values: `none`, `min`, `center` or `context`
10+
initial: 'section-context', // Scoll on initial show
11+
click: 'min', // Scroll on cloze click
12+
iterate: 'min' // Scroll on iteration
13+
},
14+
iteration: {
15+
top: false, // Always start iteration from top
16+
loop: true, // Restart from top/bottom from end
17+
hide: true // Hide cloze iterated away from
18+
},
19+
shortcuts: {
20+
next: 'j', // Iterate to next cloze
21+
previous: 'h', // Iterate to previous cloze
22+
toggle_all: 'k' // Toggle all clozes and fields
23+
},
24+
show: { // `false` means initially collapsed/hidden
25+
inactive: false, // Inactive clozes
26+
additional: false, // Additional fields (Note, Mnemonics etc.)
27+
info: false // Information field
28+
}
29+
}
30+
/*-- CONFIGURATION END --*/
31+
32+
/*-- FUNCTIONALITY BEGIN --*/
33+
config.specific = function() {
34+
// Side specific: hide active clozes
35+
this.content.querySelectorAll('.cloze').forEach(cloze => {
36+
this.hide(cloze)
37+
})
38+
}
39+
var container
40+
if (!container) container = document.querySelector('#fc2-title').parentElement
41+
container.classList.remove('back')
42+
container.classList.add('front')

src/html/fc2-back.html

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/html/fc2.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/*-- FC2 BEGIN --*/
2-
31
/*-- FUNCTIONALITY BEGIN --*/
42
.card
53
{ position: fixed !important; top: 0; bottom: 0; left: 0; right: 0; display: flex; }
@@ -145,8 +143,6 @@ font-size: 15px; font-weight: bold; padding: 5px; border-bottom: 1px solid white
145143
{ background-color: #A64CA6; content: "Mark"; }
146144
/*-- CONFIGURATION END --*/
147145

148-
/*-- FC2 END --*/
149-
150146

151147
/* MISCELLANEOUS STYLING, HAS NOTHING TO DO WITH FLEXIBLE CLOZE ============== */
152148
/* Highlight other text runs */

0 commit comments

Comments
 (0)