-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
45 lines (42 loc) · 1.37 KB
/
general.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
function searchForWords() {
let input;
input = document.getElementById("myInput");
findMatchingWords(input.value);
window.history.pushState({},'','?q=' + input.value);
}
function findMatchingWords(word) {
let filter, table, tr, english, icelandic, i, txtValue;
filter = word.toUpperCase();
table = document.getElementById("EN-IS-dictionary");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
english = tr[i].getElementsByTagName("td")[0];
icelandic = tr[i].getElementsByTagName("td")[1];
if (english) {
txtValue = english.textContent || english.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
if (icelandic) {
txtValue = icelandic.textContent || icelandic.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}
}
}
}
$(window).load(function() {
console.debug('onload');
//verify speechId is a query parameter at the end of the URL
if (window.location.href.indexOf("q=") > -1) {
var word = (window.location.href.match(/q=([^&]+)/))[1];
if (word) {
document.getElementById("myInput").value=word;
findMatchingWords(word);
}
}
});