summaryrefslogtreecommitdiff
path: root/modules/unicode/index.html
blob: 407d6b589f234eaf23eb3ec5120b6e9abfe35be1 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!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 > div > span {
	display: inline-block;
}
.table > div > span.codepoint {
	width: 6em;
	font-weight: bold;
}
.table > div > span.symbol {
	width: 1.5em;
}
.table > div > span.space-spacer {
	width: 1em;
}
.table {
	max-height: 300px;
	overflow-y: scroll;
}
.invisible {
	display: none;
}
#notfound_container {
	margin-top: 15px;
}
code {
	background-color: #eee;
	padding: 3px;
	border-radius: 5px;
}

@media (prefers-color-scheme: dark) {
	body {
		color: #eee;
		background-color: #181818;
	}
	.table > div:nth-child(even) {
		background-color: #1b1b1b;
	}
	.table > div:nth-child(odd) {
		background-color: #262626;
	}
	input[type="text"] {
		background-color: #444;
		color: #fff;
	}
	code {
		background-color: #252525;
	}
}
</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;
	}

	if ("history" in window && "replaceState" in history) {
		history.replaceState(null, "", "#" + input);
	} else {
		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 index_container = document.getElementById("index_container");
	if (json.indices.length > 0) {
		index_container.classList.remove("invisible");
		setTableRows("indices", json.indices);
		if (json.indices.length > 1) {
			document.getElementById("indices_concatenated_container").classList.remove("invisible");
			elem = document.getElementById("indices_concatenated");
			elem.innerHTML = "";
			var str = "";
			for (var i = 0; i < json.indices.length; i++)
				str += String.fromCodePoint(parseInt(json.indices[i][0], 16));
			elem.appendChild(document.createTextNode(str));
		} else {
			document.getElementById("indices_concatenated_container").classList.add("invisible");
		}
	} else if (!index_container.classList.contains("invisible")) {
		index_container.classList.add("invisible");
	}

	setTableRows("codepoints", json.codepoints);
	setTableRows("search", json.search);

	if (json.notfound.length > 0) {
		document.getElementById("notfound_container").classList.remove("invisible");
		document.getElementById("notfound").innerText = json.notfound;
	} else {
		document.getElementById("notfound_container").classList.add("invisible");
		document.getElementById("notfound").innerText = "";
	}
}

function setTableRows(key, rows) {
	document.getElementById(key + "_num").innerHTML = "(" + rows.length + ")";

	var elem = document.getElementById(key);
	elem.innerHTML = "";
	for (var j = 0; j < rows.length; j++) {
		elem.appendChild(makeCodepointDiv(rows[j]));
	}
}

function makeCodepointDiv(row) {
	var div = document.createElement("div");
	populateCodepoint(div, row);
	return div;
}

function populateCodepoint(div, row) {
	var span = document.createElement("span");
	span.classList.add("codepoint");
	span.appendChild(document.createTextNode("U+" + row[0]));
	div.appendChild(span);

	span = document.createElement("span");
	span.classList.add("space-spacer");
	span.appendChild(document.createTextNode(" "));
	div.appendChild(span);

	span = document.createElement("span");
	span.classList.add("symbol");
	span.appendChild(document.createTextNode(String.fromCodePoint(parseInt(row[0], 16))));
	div.appendChild(span);

	span = document.createElement("span");
	span.classList.add("space-spacer");
	span.appendChild(document.createTextNode(" "));
	div.appendChild(span);

	span = document.createElement("span");
	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>

	<!-- <code id="json"></code><br> -->

	<div id="notfound_container" class="invisible">
		These were not found, perhaps the server needs to be update its unicode table? <code id="notfound"></code>
	</div>

	<div id="index_container" class="invisible">
		<h3>Numeric codepoints <span id="indices_num"></span></h3>
		<div id="indices" class="table"></div>
		<br>
		<div id="indices_concatenated_container">
			Concatenated: &#x27e8; <span id="indices_concatenated"></span> &#x27e9;
		</div>
	</div>

	<h3>Codepoints <span id="codepoints_num"></span></h3>
	<div id="codepoints" class="table"></div>

	<h3>Found in descriptions <span id="search_num"></span></h3>
	<div id="search" class="table"></div>
</body>
</html>