-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadLines.js
118 lines (102 loc) · 3.73 KB
/
loadLines.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
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
114
115
116
117
var data;
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};
function openTab(tab){
$('#go_' + tab).tab('show');
};
function openWord(evt, wordName) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("word_panel");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("word_tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the link that opened the tab
document.getElementById(wordName).style.display = "block";
evt.currentTarget.className += " active";
}
// Item formatting functions
function getTabTitle (item) {
return '<h3>' + item.chars + '<br><small>' + item.hw + '</small></h3>';
}
function listPub (item) {
if (item.publication.length == 0) return '';
var tmp = '';
for (var i = 0; i < item.publication.length; ++i) {
tmp = tmp + item.publication[i] + '<br>';
}
return '<p><b>Publications: </b><br>' + tmp + '</p>';
}
function listLink (item) {
if (item.seealso_ref.length == 0) return '';
var tmp = '';
for (var i = 0; i < item.seealso_ref.length; ++i) {
//data index should be wordid - 1, please verify
tmp = tmp + data[item.seealso_ref[i]-1].chars + '|';
}
return '<p><b>See Also: </b><br>' + tmp + '</p>';
}
function getTabContent (item) {
var tmp = '';
for (var i = 0; i < item.wordprop.length; ++ i) {
var curr = item.wordprop[i];
if (curr.ps != '') {
tmp = tmp + '<b>Part of Speech: </b><span class="ps">' + curr.ps + '</span><br>';
}
if (curr.apa != ''){
tmp = tmp + '<span class="apa">' + curr.apa + '</span><br>';
}
if (curr.en != ''){
tmp = tmp + '<span class="en">' + curr.en + '</span><br>';
}
if (curr.stch != ''){
tmp = tmp + '<span class="stch">' + curr.stch + '</span><br>';
}
if (curr.df != ''){
tmp = tmp + '<b>Definition: </b><span class="df">' + curr.df + '</span><br>';
}
if (curr.exchar != '') {
tmp = tmp + '<p><b>Example: </b><br><span class="exchar">' + curr.exchar + "</span><br>" + '<span class="exrom">' + curr.exrom + '</span><br>' + '<span class="exeng">' + curr.exeng + '</span></p>';
}
}
return getTabTitle(item) + tmp + listLink(item) + listPub(item);
}
function filterWordList (text) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all data, hide elements that do not contain 'text'
for (i = 0; i < data.length; i++) {
if ((data[i].chars + data[i].hw + data[i].hw.replace(/[1-6]\//g,"")).indexOf(text) != -1) {
document.getElementById('wt'+data[i].wordid).style.display = "block";
}
else {
document.getElementById('wt'+data[i].wordid).style.display = "none";
}
}
openTab('list');
}
function loadFile() {
$.get("elw.json", function(_data) {
data = _data;
for (var i = 0; i < data.length; ++i) {
var item = data[i];
//add tab
var tabstring = '<button id="wt'+item.wordid+'" class="word_tablinks" onclick="openWord(event, \'word' + item.wordid + '\')">' + getTabTitle (item) + '</button>';
//console.log(tabstring);
$('#wordlist').append(tabstring);
//add content
var contentstring = '<div id="word'+item.wordid+'" class="word_panel">'+ getTabContent(item) + '</div>';
//console.log(contentstring);
$('#list').append(contentstring);
}
}
);
}