-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo-list.html
116 lines (111 loc) · 2.97 KB
/
demo-list.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
<!DOCTYPE html>
<html lang="ja">
<head>
<title>List Filtering Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script type="text/javascript" src='https://cdn.jsdelivr.net/npm/jsmigemo/dist/jsmigemo.js'></script>
</head>
<body style="padding-top: 4.5rem">
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container">
<input class="form-control w-100" type="text" placeholder="Migemo" id="queryInput" />
</div>
</nav>
<main role="main" class="container">
<ul class="list-group" id="todofuken">
</ul>
</main>
<script type="text/javascript">
var queryInputElement = document.getElementById("queryInput");
var sd = null;
var cd = null;
function loadDictionary() {
var req = new XMLHttpRequest();
req.open("get", "https://cdn.jsdelivr.net/npm/jsmigemo/migemo-compact-dict", true);
req.responseType = "arraybuffer";
req.onload = function () {
var ab = req.response;
cd = new jsmigemo.CompactDictionary(ab);
}
req.send(null);
}
var action = function () {
// list update
if (queryInputElement.value == "") {
var todofuken = document.getElementById("todofuken");
todofuken.innerHTML = "";
for (var i of list) {
todofuken.innerHTML += '<li class="list-group-item">' + i + '</li>';
}
} else {
var migemo = new jsmigemo.Migemo()
migemo.setDict(cd);
var reg = migemo.query(queryInputElement.value);
var regex = new RegExp(reg, 'g');
var todofuken = document.getElementById("todofuken");
todofuken.innerHTML = "";
for (var i of list) {
let r = regex.exec(i);
if (r != null) {
todofuken.innerHTML += '<li class="list-group-item">' + i.substr(0, r.index) + "<span style='background: pink'>" + i.substr(r.index, r[0].length) + "</span>" + i.substr(r.index + r[0].length) + '</li>';
}
}
}
}
queryInputElement.addEventListener("input", action);
loadDictionary();
//--------
var list = [
"北海道",
"青森県",
"岩手県",
"宮城県",
"秋田県",
"山形県",
"福島県",
"茨城県",
"栃木県",
"群馬県",
"埼玉県",
"千葉県",
"東京都",
"神奈川県",
"新潟県",
"富山県",
"石川県",
"福井県",
"山梨県",
"長野県",
"岐阜県",
"静岡県",
"愛知県",
"三重県",
"滋賀県",
"京都府",
"大阪府",
"兵庫県",
"奈良県",
"和歌山県",
"鳥取県",
"島根県",
"岡山県",
"広島県",
"山口県",
"徳島県",
"香川県",
"愛媛県",
"高知県",
"福岡県",
"佐賀県",
"長崎県",
"熊本県",
"大分県",
"宮崎県",
"鹿児島県",
"沖縄県"]
action.call();
</script>
</body>
</html>