search-wp.js
3.36 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
loadTermData = function (currentBodyViewId, languageName, languageID) {
console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
var termNoJsonPath = '~/../content/data/json/da/body-views/' + currentBodyViewId + '/da_dat_tm_sg_' + currentBodyViewId + '.json';
var TermNumberData;
var AJAX_req = new XMLHttpRequest();
AJAX_req.open("GET", termNoJsonPath, true);
AJAX_req.setRequestHeader("Content-type", "application/json");
AJAX_req.onreadystatechange = function () {
if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
TermNumberData = JSON.parse(AJAX_req.responseText);
console.log("data returned: " + TermNumberData);
loadTermTextData(TermNumberData, languageName, languageID);
}
}
AJAX_req.send();
}
loadTermTextData = function (TermNumberData, languageName, languageID) {
var languageFileName;
if(languageName == "English (Undergraduate)")
{
languageFileName = "English_Undergraduate";
}
else if (languageName == "Japanese (Kanji)") {
languageFileName = "Japanese_Kanji";
}
else if (languageName == "Japanese (Yomi)")
{
languageFileName = "Japanese_yomi";
}
else
{
languageFileName = languageName;
}
var termTextJsonPath = '~/../content/data/json/da/vocab/' + languageFileName + '/cm_dat_vocabterm_' + languageID + '.json';
var VocabTermData = '';
var AJAX_req = new XMLHttpRequest();
AJAX_req.open("GET", termTextJsonPath, true);
AJAX_req.setRequestHeader("Content-type", "application/json");
AJAX_req.onreadystatechange = function () {
if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
console.log('AJAX_req.readyState= ' + AJAX_req.readyState + ' and AJAX_req.status =' + AJAX_req.status);
VocabTermData = JSON.parse(AJAX_req.responseText);
var vocabTermTxt = [];
TermNumberData.TermData.Term.forEach(function (value1, key1) {
VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {
if (value1._ActualTermNumber === value2._ActualTermNumber) {
vocabTermTxt.push(
{
"_ActualTermNumber": value2._ActualTermNumber,
"_TermText": value2._TermText,
"_cdId": value2._cdId
}
);
}
})
})
self.postMessage({
'vocabTermTxt': vocabTermTxt,
'TermNumberData': TermNumberData,
'VocabTermData': VocabTermData,
'language': languageName
});
}
}
AJAX_req.send();
}
self.onmessage = function (e) {
console.log("search");
//console.log('search-wp onmessage time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
loadTermData(e.data.currentBodyViewId, e.data.languageName, e.data.languageID);
}