-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
113 lines (106 loc) · 4.48 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<title>Globasa GREEND</title>
<meta name="viewport" content="width=device-width" />
<meta charset="utf-8" />
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="reset.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
<script src="jquery.csv.min.js"></script>
<script src="jquery.js"></script>
<script src="static_dict.js"></script>
<script src="search.js"></script>
</head>
<body>
<header id="header">
<div id="top-title">
GLOBASA GREEN DICTIONARY
</div>
<div id="search-bar">
<input type="text"
name="search-bar-input"
id="search-bar-input"
placeholder="| type a word here..." />
<div id="search-bar-button">
<span class="material-symbols-outlined">search</span>
</div>
</div>
</header>
<content id="contents">
</content>
<footer id="footer">
<div id="langsel-en" class="langsel selected_lang"> ENGLISH </div>
<div id="langsel-es" class="langsel"> SPANISH </div>
<div id="langsel-eo" class="langsel"> ESPERANTO </div>
<a class="green_link" rel="official site" href="https://globasa.net">globasa.net</a>
</footer>
<script>
// try to access remote dictionary from the official globasa site
var remote_dict_url = 'https://api.globasa.net/globasa-menalar-1.json';
$.getJSON(remote_dict_url, function (data) {
console.log("success requesting remote data");
}).done(function (data) {
dictionary = data; // replace local data with the remote data
console.log("success fetching remote data");
}).fail(function () {
console.log("error fetching remote data");
}).always(function () {
console.log("finished requesting remote data");
});
// init
var langsel = "eng";
function searchHandler() {
var line = $('#search-bar-input').val().toLowerCase();
var resultsA = smartSearch(line, dictionary);
$('#contents').empty(); // clear the output area
resultsA.sort(function (a, b) { // sort results by length
// ASC -> a.length - b.length
// DESC -> b.length - a.length
return b.length - a.length;
});
var resultsB = foreignSearch(line, dictionary, langsel);
resultsC = resultsA.concat(resultsB);// combine two lists
results = resultsC.filter(function (item, pos) {
return resultsC.indexOf(item) == pos;
}); // and remove duplicates
for (const entry of results) {
var entry_box = $("<div/>", {
class: 'entry'
});
var headword = $("<p/>", {
class: 'headword',
html: '(' + partOfSpeechLookup(entry, dictionary) + ') ' + entry
});
var definition = $("<p/>", {
class: 'definition',
html: translationLookup(entry, dictionary, langsel)
});
headword.appendTo(entry_box);
definition.appendTo(headword);
entry_box.appendTo("#contents");
}
}
// events
$('#search-bar').on
('keypress', function (e) { if (e.key == "Enter") searchHandler(); });
$('#search-bar-button').on('click', searchHandler);
$("#langsel-en").on("click", function (event) {
$(".selected_lang").removeClass("selected_lang");
$(this).addClass("selected_lang");
langsel = "eng";
});
$("#langsel-es").on("click", function (event) {
$(".selected_lang").removeClass("selected_lang");
$(this).addClass("selected_lang");
langsel = "spa";
});
$("#langsel-eo").on("click", function (event) {
$(".selected_lang").removeClass("selected_lang");
$(this).addClass("selected_lang");
langsel = "epo";
});
</script>
</body>
</html>