-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
126 lines (108 loc) · 3.92 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
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>粵語量詞查詢</title>
<link rel="stylesheet" type="text/css" href="css/picnic.min.css"/>
<link rel="stylesheet" type="text/css" href="css/yylc.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="yylc.js" type="text/javascript"></script>
<script type="text/javascript">
function mwsearch(term) {
searchlist(term, mw_list, "mw");
searchlist(term, coll_list, "mc");
searchlist(term, vm_list, "vm");
searchlist(term, vm_coll, "vc");
}
function searchlist(term, dataset, type) {
var output = document.getElementById(type + "output");
var outlines = new Array();
var htxt = htwo(type);
var headers = fmtheaders(type);
var hits = false;
outlines.push(htxt + headers);
if (term == "") {
output.innerHTML = "";
return;
}
for (var i = 0; i < dataset.length; i++) {
var re = new RegExp(term);
list = dataset[i];
mw = list.l;
mwpy = list.p;
gymw = list.g;
vn = '';
vnpy = '';
alt = '';
yf = '';
if (list.m) { vn = list.m }
if (list.n) { vnpy = list.n }
if (list.y) { yf = list.y }
len = Object.keys(list).length;
searchtext = getsrchtxt(list, len);
if (re.test(searchtext)) {
rows = fmtrows(type);
outlines.push(rows);
hits = true;
}
}
if (hits) {
output.innerHTML = outlines.join("\n") + "</table>";
window[type + "theaders"].style.display = "";
} else {
output.innerHTML = "";
}
}
function getsrchtxt(list, len) {
searchtext = "";
for (var n = 0; n < len; n++) {
searchtext += ' ' + Object.values(list)[n];
}
return searchtext;
}
function fmtheaders(type) {
header_cols = [];
if (type == 'mw' || type == 'vm') {
header_cols = ['粵語', '拼音', '國語', '用法'];
} else if (type == 'mc' || type == 'vc') {
header_cols = ['粵語', '拼音', '國語'];;
}
header_txt = '<table><tr id="' + type + 'theaders" style="display:none"><th>' + header_cols.join('</th><th>') + '</th></tr>';
return header_txt;
}
function fmtrows(type) {
row_txt = '';
if (type == 'mw' || type == 'vm') {
var yfout = (yf == '') ? '' : '用於' + yf;
row_txt = '<tr><td class="yue">' + mw + '</td><td class="pinyin"><em>' + mwpy + '</em></td><td class="gy">' + gymw + '</td><td class="yf">' + yfout + '</td></tr>';
} else if (type == 'mc') {
row_txt = '<tr><td class="yue">一' + mw + vn + '</td><td class="pinyin"><em>yat7 ' + mwpy + " " + vnpy + '</em></td><td class="gy">' + gymw + '</td></tr>';
} else if (type == 'vc') {
row_txt = '<tr><td class="yue">' + vn + '一' + mw + '</td><td class="pinyin"><em>' + vnpy + " yat7 " + mwpy + '</em></td><td class="gy">' + gymw + '</td></tr>';
}
return row_txt;
}
function htwo(type) {
htxt = '量詞';
if (type == "mc") {
htxt = '量詞搭配';
} else if (type == "vm") {
htxt = '動量詞';
} else if (type == "vc") {
htxt = '動量詞搭配';
}
out = '<h2>' + htxt + '</h2>\n';
return out;
}
</script>
</head>
<body onload="window.searchbar.focus();">
<nav><a href="https://github.com/dohliam/yylc-js">源碼</a></nav>
<h1>粵語量詞查詢</h1>
<input id="searchbar" name="q" type="text" class="search" accesskey="s" placeholder="輸入量詞、名詞、動詞、或粵語拼音" autocomplete="off" onkeyup="mwsearch(this.value)" tabindex=1>
<div id="mwoutput" tabindex=2> </div>
<div id="mcoutput" tabindex=3> </div>
<div id="vmoutput" tabindex=4> </div>
<div id="vcoutput" tabindex=5> </div>
</body>
</html>