aboutsummaryrefslogtreecommitdiff
path: root/static/script.js
blob: 639e7433eac77f5a5d389aef2472a0e9e4f900c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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_ex_kanji").html(examples[i].kanji);
    $("#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;
  }
  window.scrollTo(0, 0);
}