search-wp.js
3.54 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
93
94
95
96
97
98
99
100
101
102
103
104
loadTermData = function (currentBodyViewId, languageArray) {
console.log('search-wp, loadTermData, time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
console.log('languageArray: ' + languageArray.length);
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, languageArray);
// loadTermTextData(languageArray);
}
}
AJAX_req.send();
}
loadTermTextData = function (TermNumberData, arr) {
console.log(arr.length);
var DataArray = [];
var a;
for (var j = 0; j <= arr.length - 1; j++) {
//1.
var a = arr[j].language;
var termTextJsonPath = '~/../content/data/json/da/vocab/' + arr[j].language + '/cm_dat_vocabterm_' + arr[j].id + '.json';
console.log(termTextJsonPath);
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) {
VocabTermData = JSON.parse(AJAX_req.responseText);
console.log("data returned FOR VocabTermData: " + VocabTermData);
var vocabTermTxt = [];
TermNumberData.TermData.Term.forEach(function (value1, key1) {
console.log("data returned FOR VocabTermData1: " + VocabTermData.VocabTerms);
VocabTermData.VocabTerms.Term.forEach(function (value2, key2) {
if (value1._ActualTermNumber === value2._ActualTermNumber) {
vocabTermTxt.push(
{
"_ActualTermNumber": value2._ActualTermNumber,
"_TermText": value2._TermText,
"_cdId": value2._cdId
}
);
}
})
})
DataArray.push({ "language": a, "VocabTermData": VocabTermData, "vocabTermTxt": vocabTermTxt });
self.postMessage({
'vocabTermTxt': vocabTermTxt,
'TermNumberData': TermNumberData,
'VocabTermData': VocabTermData,
'DataArray': DataArray
});
}
}
}
AJAX_req.send();
// var termTextJsonPath = '~/../content/data/json/da/vocab/english/cm_dat_vocabterm_1.json';
// readTextFile(termTextJsonPath, function (text) {
}
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.languageArray);
// loadTermData(e.data.languageArray);
}