diff options
Diffstat (limited to 'static/script.js')
-rw-r--r-- | static/script.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000..72fcb1c --- /dev/null +++ b/static/script.js @@ -0,0 +1,48 @@ + +let initialized = false; +let current = null; +let revealed = false; +let examples = []; + +function add_example(example) { + console.log("add example"); + examples.push(example); + + if (!initialized) { + display_example(0); + + $(document).keydown(function (e) { + if (e.keyCode === 32) { + spacebar(); + } + }) + initialized = true; + } +} + +function display_example(i) { + if (i < examples.length) { + $("#gen_ex_cnt").text(`Example ${i}`); + $("#gen_ex_display").html(examples[i].furi); + $("#gen_ex_en").html(examples[i].en); + $("#gen_ex_words").html(examples[i].vocab); + $("#gen_section").addClass("gen_hidden"); + current = i; + revealed = false; + } else { + $("#gen_ex_display").text("done"); + $("#gen_ex_en").html(`<a onclick="display_example(0);">redo</a>`); + $("#gen_ex_words").text(""); + } +} + +function spacebar() { + if (revealed) { + console.log("Next item"); + display_example(current + 1); + } else { + console.log("Revealing item"); + $("#gen_section").removeClass("gen_hidden"); + revealed = true; + } +} |