-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.js
75 lines (68 loc) · 2.41 KB
/
gui.js
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
// this needs data.js and script.js
const langs = { neo: 'NEO.', en: 'ANG.', fr: 'FRA.', es: 'CAS.', it: 'ITA.', pt: 'POR.', ro: 'RUM.', ca: 'CAT.', slav: 'INTERSL.' };
var dict = prepareDictionary(rawDataCSV);
var index = {};
for (const langCode in langs) {
var langName = langs[langCode];
index[langCode] = prepareIndex(dict, langName);
}
function entryCardHTML(headword, gramclass, translationMap) {
var header = `
<div class="entry">
<span class="headword">${headword}</span>
<span class="grammatical-class">${gramclass}</span>
`;
var footer = '</div>';
var translationHTML = '';
for (const langCode in translationMap) {
if (translationMap[langCode] != null && translationMap[langCode] != '') {
translationHTML += '<br />';
translationHTML += `<span class="translation">${langCode}. ${translationMap[langCode]}</span>`;
}
}
return header + translationHTML + footer;
}
function nothingFoundHTML() {
return `
<div class="info">
¯\_(ツ)_/¯
</div>
`;
}
function searchHandler() {
// Stage 1 - get the word from inputs
var input = $('#search-input').val().toLowerCase();
// Stage 2 - look up numbers of entries in the index (TODO: language selection)
var indexArray = [];
for (const langCode in langs) {
indexArray = indexArray.concat(advancedIndexLookup(input, index[langCode], langs[langCode]));
}
indexArray = removeArrayDuplicates(indexArray);
if (indexArray.length == 0) {
$('#contents').html(nothingFoundHTML());
return;
}
// Stage 3 - get the translations for each number
var resultsHTML = [];
for (const i of indexArray) {
var entry = dict[i];
if (entry['cat. gram.'] == 'léttera')
continue;
var translations = {};
for (const langCode in langs) {
if (langCode == 'neo')
continue;
var langName = langs[langCode];
translations[langCode] = entry[langName];
}
var entryHTML = entryCardHTML(entry['NEO.'], entry['cat. gram.'], translations);
resultsHTML.push(entryHTML);
}
// Stage 4 - output into contents
$('#contents').html('');
for (const resultHTML of resultsHTML) {
$('#contents').append(resultHTML);
}
return;
}