forked from bencrowder/unicode-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
142 lines (123 loc) · 4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Unicode Inspector</title>
<!-- Based on https://gist.github.com/addyosmani/d1f3ca715ac902788c2d -->
<style type="text/css" media="screen">
body { padding: 0; margin: 0; }
* { -moz-box-sizing: border-box; box-sizing: border-box; }
textarea { font: 2rem/1.5 monospace; width: 100%; margin: 0px; padding: 4rem; border: none; height: calc(100% - 300px); position: absolute; top: 0; left: 0; right: 0; }
textarea:focus { outline: none; }
#output { font: 1.2rem/1.5 monospace; width: 100%; height: 300px; margin: 0px auto; padding: 2rem 4rem; color: #fff; background: #20384b; position: absolute; bottom: 0; overflow-y: scroll; }
#output > span { background: #38556b; padding: 4px 8px 4px 0; display: inline-block; border-radius: 3px; margin-bottom: 3px; line-height: 1em; }
#output > span span { background: #0d2231; margin-right: 8px; padding: 4px 8px; border-radius: 3px 0 0 3px; line-height: 1em; }
/* Media queries */
@media screen and (max-width: 400px) {
textarea { font-size: 1.4rem; line-height: 1.5em; padding: 2rem; height: calc(100% - 350px); }
#output { padding: 1rem 2rem; font-size: 1.1rem; height: 350px; }
}
</style>
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="punycode.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("textarea").focus();
var preLen = 0;
$("textarea").on("input", function() {
function isHex(char) {
if ((char >= "0" && char <= "9") || (char >= "A" && char <= "F") || (char >= "a" && char <= "f")) {
return true;
} else {
return false;
}
}
function isUnicode(str, pos) {
if (pos < 6) {
return false;
}
if ((str[pos-6] === "U" || str[pos-6] === "u") && str[pos-5] === "+") {
for (var j = pos - 4; j < pos; j++) {
if (!isHex(str[j])) {
return false;
}
}
return true;
} else {
return false;
}
}
function decode(str) {
var codepoint = Number("0x" + str);
return String.fromCharCode(codepoint);
}
var input = $("textarea").val();
var len = input.length;
if (len === preLen + 1 || len === preLen + 6) {
var pos = $("textarea")[0].selectionStart;
if (isUnicode(input, pos)) {
char = decode(input.substr(pos - 4, 4))
input = input.substr(0, pos - 6) + char + input.substr(pos)
$("textarea").val(input);
$("textarea")[0].selectionStart = pos - 5;
$("textarea")[0].selectionEnd = pos - 5;
}
}
preLen = len;
var hexList = punycode.ucs2.decode(input);
var outputList = [];
for (var i=0; i<hexList.length; i++) {
// Zero-pad it
var hex = hexList[i].toString(16).toUpperCase();
for (var j=hex.length; j<4; j++) {
hex = '0' + hex;
}
// Add it
var html = "<span>";
var character = String.fromCharCode(hexList[i]);
newLine = false;
switch (character) {
case "\n":
character = '\\n';
newLine = true;
break;
case " ":
character = " ";
break;
}
html += "<span>" + character + "</span>";
html += "U+" + hex;
html += "</span>";
if (newLine) {
html += "<br/><br/>";
}
outputList.push(html);
}
$("#output").html(outputList.join(" "));
});
var placeHolder = "Hahau+263a";
var idx = 0;
function type() {
input = $("textarea").val();
input += placeHolder[idx];
$("textarea").val(input);
$("textarea").trigger("input");
idx++;
if (idx < placeHolder.length) {
setTimeout(type, 400)
}
}
setTimeout(type, 800);
});
</script>
<link rel="shortcut icon" href="favicon.png" />
</head>
<body>
<section id="page">
<textarea></textarea>
<div id="output">
</div>
</section>
</body>
</html>