-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
92 lines (91 loc) · 2.28 KB
/
Copy pathscript.js
File metadata and controls
92 lines (91 loc) · 2.28 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var language = "";
var section = "";
var item_history = new Array();
var history_limit = 10;
var history_index = 0;
var item = { id: 0, character: " ", pronunciation: " ", example: " " };
var item_revealed = false;
var config = [];
var sections = [];
function resetActive() {
item_history = [];
history_limit = 10;
history_index = 0;
item = { id: 0, character: " ", pronunciation: " ", example: " " };
item_revealed = false;
}
function retry() {
interrupt();
buildGUI(item, getActiveSection().type);
}
function next() {
interrupt();
if (history_index === 0) {
item_history.push(item);
item = getNotSoRandomListItem(getActiveList(), item_history, history_limit);
hideAnswer();
buildGUI(item, getActiveSection().type);
item_revealed = false;
} else {
history_index -= 1;
if (history_index > 0) {
var temp_item = item_history[item_history.length - history_index];
buildGUI(temp_item, getActiveSection().type);
} else {
if (!item_revealed) {
hideAnswer();
}
buildGUI(item, getActiveSection().type);
}
}
}
function previous() {
interrupt();
history_index += 1;
if (history_index > item_history.length) history_index = item_history.length;
if (history_index != 0) {
var temp_item = item_history[item_history.length - history_index];
revealAnswer();
buildGUI(temp_item, getActiveSection().type);
}
}
function reveal() {
item_revealed = true;
revealAnswer();
}
function init() {
load_asset(
"https://learn-lang.glitch.me/assets/config.JSON",
config,
function() {
buildSelect("language", config);
buildSelect("section", config[0].sections);
load_lang(config[0], sections);
}
);
}
function sectionChange() {
var e = document.getElementById("section");
section = e.options[e.selectedIndex].value;
console.log("change section -> " + section);
resetActive();
item = getRandomListItem(getActiveList());
hideAnswer();
buildGUI(item, getActiveSection().type);
}
function getActiveSection() {
for (var i = 0; i < sections.length; i++) {
if (sections[i].title === section) {
return sections[i];
}
}
}
function getActiveList() {
var temp_section = getActiveSection();
if (temp_section) {
return temp_section.list;
} else {
return [];
}
}
init();