blob: 106557590a37ceb766e47a5faf1d814c09d6ecdf (
plain)
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
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Unicode character lookup</title>
<style>
body {
font-size: 12pt;
font-family: sans-serif;
}
.table > div:nth-child(odd) {
background-color: #eee;
}
.table {
max-height: 300px;
overflow-y: scroll;
}
</style>
<script>
function do_lookup(override) {
var input;
if (override != null) {
if (override.length == 0) return;
input = override;
document.getElementById("input").value = override;
} else {
input = document.getElementById("input").value;
if (input.length == 0) return;
}
location.hash = input;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
handleResponse(JSON.parse(xhr.responseText));
} else {
alert("Request failed: " + xhr.responseText);
}
}
};
xhr.open("GET", "/unicode/lookup/" + encodeURIComponent(input));
xhr.responseType = "text";
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.send();
}
function handleResponse(json) {
var elem;
/* elem = document.getElementById("json");
elem.innerHTML = "";
elem.appendChild(document.createTextNode(JSON.stringify(json))); */
var keys = ["chars", "search"];
for (var i = 0; i < keys.length; i++) {
document.getElementById(keys[i] + "_num").innerHTML = "(" + json[keys[i]].length + ")";
elem = document.getElementById(keys[i]);
elem.innerHTML = "";
for (var j = 0; j < json[keys[i]].length; j++) {
var div = document.createElement("div");
div.classList.add("character");
populateCharacter(div, json[keys[i]][j]);
elem.appendChild(div);
}
}
}
function populateCharacter(div, row) {
var span = document.createElement("span");
span.setAttribute("style", "display: inline-block; width: 7em; font-weight: bold;");
span.appendChild(document.createTextNode("U+" + row[0]));
div.appendChild(span);
span = document.createElement("span");
span.setAttribute("style", "display: inline-block; width: 2em;");
span.appendChild(document.createTextNode(String.fromCodePoint(parseInt(row[0], 16))));
div.appendChild(span);
span = document.createElement("span");
span.setAttribute("style", "display: inline-block;");
span.appendChild(document.createTextNode(row[1]));
div.appendChild(span);
}
window.addEventListener("load", function() {
if (location.hash.length > 0) {
do_lookup(decodeURIComponent(location.hash.slice(1)));
}
document.getElementById("input").focus();
});
</script>
</head>
<body>
<h1>Unicode character lookup</h1>
<input type="text" id="input" placeholder="Character(s) to look up" onkeypress="if (event.keyCode == 10 || event.keyCode == 13) do_lookup()">
<input type="button" onclick="do_lookup()" value="Lookup">
<br>
<!-- <pre id="json"></pre><br> -->
<h3>Characters <span id="chars_num"></span></h3>
<div id="chars" class="table"></div>
<h3>Found in descriptions <span id="search_num"></span></h3>
<div id="search" class="table"></div>
</body>
</html>
|