-
Notifications
You must be signed in to change notification settings - Fork 0
/
translator.html
345 lines (297 loc) 路 10.9 KB
/
translator.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Earth Language-Erathian Translator v2.1</title>
<link rel="stylesheet" type="text/css" href="fonts/Erathian.css" />
<link rel="stylesheet" type="text/css" href="style/general.css" />
<style type="text/css" id="eraboxstyle"></style>
<script type="text/javascript">
function $(id) {
return document.getElementById(id);
}
function copyTo2ndBox(){
$("secondbox").value = $("firstbox").value;
}
function changeFont(){
function globalStyle(css){
var style = $("eraboxstyle");
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.innerHTML = css;
}
}
var fontsize = $("fontsize").value.replace(/[^0-9]/g,""),
fontweight = $("bold").checked ? "bold" : "normal",
fontstyle = $("italic").checked ? "italic" : "normal";
$("fontsize").value = fontsize;
globalStyle(".erathianbox{font-size:" + fontsize + "px;font-weight:" + fontweight + ";font-style:" + fontstyle + ";}");
}
function changeFontsize(delta){
var fontsize = $("fontsize").value * 1;
if (fontsize + delta > 0) {
$("fontsize").value = fontsize + delta;
}
changeFont();
}
function switchBox(){
var firstbox = $("firstbox"),
secondbox = $("secondbox"),
secondboxdiv = $("secondboxdiv");
if ($("showinoriginal").checked) {
secondboxdiv.style.display = "none";
firstbox.className = "erathianbox";
secondbox.className = "";
} else {
secondboxdiv.style.display = "block";
secondbox.className = "erathianbox";
firstbox.className = "";
}
}
function showHideimgresult(){
$("imgresult").style.display = $("showcode").checked ? "block" : "none";
}
function switchshowcodeCheckbox(){
var showcode = $("showcode");
showcode.checked = showcode.checked ? false : true;
showHideimgresult();
}
function convert(){
var site = "https://might-and-magic.github.io/erathian-font/png/",
txtTemp = $("firstbox").value,
txtTempHtml = txtTemp;
txtTempMarkdown = txtTemp;
txtTemp = txtTemp.replace(/[a-z]/g, "[img]" + site + "$&" + ".png[/img]");
txtTemp = txtTemp.replace(/[A-Z]/g, function(letter) {
return "[img]" + site + letter.toLowerCase() + "_upper.png[/img]";
});
txtTempHtml = txtTempHtml.replace(/ /g,"\f");
txtTempHtml = txtTempHtml.replace(/[a-z]/g, "<img title=\"" + "$&" + "\" alt=\"" + "$&" + "\" src=" + site + "$&" + ".png>");
txtTempHtml = txtTempHtml.replace(/[A-Z]/g, function(letter) {
return "<img title=\"" + letter + "\" alt=\"" + letter + "\" src=" + site + letter.toLowerCase() + "_upper.png>";
});
txtTempHtml = txtTempHtml.replace(/\f/g," ");
txtTempHtml = txtTempHtml.replace(/\n/g,"<br />");
txtTempMarkdown = txtTempMarkdown.replace(/[a-z]/g, "![" + "$&" + "](" + site + "$&" + ".png \"" + "$&" + "\")");
txtTempMarkdown = txtTempMarkdown.replace(/[A-Z]/g, function(letter) {
return "![" + letter + "](" + site + letter.toLowerCase() + "_upper.png \"" + letter + "\")";
});
txtTempMarkdown = txtTempMarkdown.replace(/\n/g," \n");
$("imgdemo").innerHTML = txtTempHtml;
$("imgresultubb").value = txtTemp;
$("imgresulthtml").value = txtTempHtml;
$("imgresultmarkdown").value = txtTempMarkdown;
}
function copyTa(id){
var el = $(id);
el.select();
document.execCommand("Copy");
}
function addEvent(obj, evt, fn){
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
} else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
function onTextChange(el, evt){
addEvent(el, "keyup", evt);
addEvent(el, "paste", function (){
window.setTimeout(evt, 0);
});
addEvent(el, "cut", function (){
window.setTimeout(evt, 0);
});
addEvent(el, "drop", function (){
window.setTimeout(evt, 0);
});
addEvent(el, "change", evt);
}
function resizeErathianBox(){
var firstbox = $("firstbox"),
secondbox = $("secondbox"),
firstboxInitHeight = 0,
erathianboxInitHeight = 0;
function getTaHeight(el){
function getStyle(el, styleProp) {
if (el.currentStyle) {
var computedStyle = el.currentStyle[styleProp];
} else if (window.getComputedStyle) {
var computedStyle = document.defaultView.getComputedStyle(el, null)[styleProp];
}
return computedStyle;
}
return el.offsetHeight - getStyle(el, "borderTopWidth").substring(0,1) - getStyle(el, "borderBottomWidth").substring(0,1) - getStyle(el, "paddingTop").substring(0,1) - getStyle(el, "paddingBottom").substring(0,1);
}
var hiddenTa = document.createElement("textarea");
hiddenTa.value = "";
hiddenTa.style.height = "";
hiddenTa.style.visibility = "hidden";
document.body.appendChild(hiddenTa);
firstboxInitHeight = getTaHeight(hiddenTa);
document.body.removeChild(hiddenTa);
hiddenTa = document.createElement("textarea");
hiddenTa.value = "";
hiddenTa.style.height = "";
hiddenTa.className = "erathianbox";
hiddenTa.style.visibility = "hidden";
document.body.appendChild(hiddenTa);
erathianboxInitHeight = getTaHeight(hiddenTa);
document.body.removeChild(hiddenTa);
function resize(el) {
function resizeTa(el, initHeight) {
function getTaScrollHeight(el){
var hiddenTa = el.cloneNode(false), scrollHeight;
hiddenTa.style.borderWidth = "0";
hiddenTa.style.height = "0";
hiddenTa.style.visibility = "hidden";
document.body.appendChild(hiddenTa);
hiddenTa.value = el.value;
scrollHeight = hiddenTa.scrollHeight;
document.body.removeChild(hiddenTa);
return scrollHeight;
}
el.style.height = Math.max(initHeight, getTaScrollHeight(el)) + "px";
}
if (el.className == "erathianbox" && $("autoresize").checked) {
el.style.overflow = "hidden";
resizeTa(el, erathianboxInitHeight);
} else if (el.className == "erathianbox") {
el.style.overflow = "auto";
el.style.height = erathianboxInitHeight + "px";
} else {
el.style.overflow = "auto";
el.style.height = firstboxInitHeight + "px";
}
}
resize(firstbox);
resize(secondbox);
}
function init(){
changeFont();
copyTo2ndBox();
switchBox();
resizeErathianBox();
convert();
showHideimgresult();
addEvent($("copyubb"), "click", function(){
copyTa("imgresultubb");
});
addEvent($("copyhtml"), "click", function(){
copyTa("imgresulthtml");
});
addEvent($("copymarkdown"), "click", function(){
copyTa("imgresultmarkdown");
});
onTextChange($("firstbox"), function(){
copyTo2ndBox();
convert();
resizeErathianBox();
});
onTextChange($("fontsize"), function(){
changeFont();
resizeErathianBox();
});
addEvent($("increase"), "click", function(){
changeFontsize(+1);
resizeErathianBox();
});
addEvent($("decrease"), "click", function(){
changeFontsize(-1);
resizeErathianBox();
});
addEvent($("bold"), "click", changeFont);
addEvent($("italic"), "click", changeFont);
addEvent($("autoresize"), "click", resizeErathianBox);
addEvent($("showinoriginal"), "click", function(){
switchBox();
resizeErathianBox();
});
addEvent($("showcode"), "click", showHideimgresult);
addEvent($("closeimgresult"), "click", switchshowcodeCheckbox);
}
addEvent(window, "load", init);
</script>
</head>
<body class="translator">
<div id="wrapper">
<div id="certificated"><span class="erathianfont">Certificated by Queen Catherine of Erathia</span><br />Certificated by Queen Catherine of Erathia</div>
<h1 id="title">Earth Language-Erathian Translator v2.1</h1>
<div id="firstboxdiv">
<div class="labeldiv"><label id="enter_lb" for="firstbox">Enter your Earth language text (Latin letters) here:</label></div>
<textarea id="firstbox">Welcome to Erathia</textarea>
</div>
<div id="secondboxdiv">
<div class="labeldiv"><label id="erathiantext_lb" for="secondbox">Erathian text:</label></div>
<textarea readonly="readonly" id="secondbox" class="erathianbox"></textarea>
</div>
<div id="controls" class="labeldiv">
<span class="controlsspan">
<label id="fontsize_lb" for="fontsize">Font size:</label>
<input type="text" class="text" id="fontsize" value="30" />
<label id="px" for="fontsize">
<span id="px">px</span>
<a id="increase" class="smallbutton">+</a>
<a id="decrease" class="smallbutton">-</a>
</label>
</span>
<span class="controlsspan">
<input type="checkbox" id="bold" /><label id="bold_lb" for="bold">Bold</label>
</span>
<span class="controlsspan">
<input type="checkbox" id="italic" /><label id="italic_lb" for="italic">Italic</label>
</span>
<span class="controlsspan">
<input type="checkbox" id="autoresize" checked="checked" /><label id="autoresize_lb" for="autoresize">Auto resize</label>
</span>
<span class="controlsspan">
<input type="checkbox" id="showinoriginal" /><label id="showinoriginal_lb" for="showinoriginal">Show in the original box</label>
</span>
<span class="controlsspan">
<input type="checkbox" id="showcode" /><label id="showcode_lb" for="showcode">Show UBB & HTML & Markdown code</label>
</span>
</div>
<div id="imgresult" style="display:none;">
<h4 id="imgresulttitle"><span id="erathianusingimg">Add Erathian using embedded images to your forum or webpage</span><a id="closeimgresult" class="smallbutton">脳</a></h4>
<div class="labeldiv">
<label id="ubbcodelable" for="imgresultubb">UBB Code:</label>
<a id="copyubb" class="button">Copy</a>
</div>
<textarea id="imgresultubb"></textarea>
<div class="labeldiv">
<label id="htmlcodelable" for="imgresulthtml">HTML Code:</label>
<a id="copyhtml" class="button">Copy</a>
</div>
<textarea id="imgresulthtml"></textarea>
<div class="labeldiv">
<label id="htmlcodelable" for="imgresultmarkdown">Markdown Code:</label>
<a id="copymarkdown" class="button">Copy</a>
</div>
<textarea id="imgresultmarkdown"></textarea>
<div class="labeldiv"><label id="imgdemo_lb">Demo:</label></div>
<div id="imgdemo">
1
</div>
</div>
<div id="note">
<h4>Options description:</h4>
<ul>
<li><b>Font size, Bold, Italic:</b> Choose the size (in pixels) and bold/italic styles of the Erathian characters</li>
<li><b>Auto resize:</b> Automatically resize the Erathian text box</li>
<li><b>Show in the original box:</b> Display Erathian text directly in the original text box and hide the second box</li>
<li><b>Show UBB & HTML & Markdown code:</b> Show UBB, HTML, Markdown code and their demo. You can then copy and paste the <i>UBB Code</i> into your topic of a web forum which supports <a href="http:https://en.wikipedia.org/wiki/BBCode">UBB/BBCode</a>, or the <i>HTML Code</i> into your HTML webpage, or the <i>Markdown code</i> into your GitHub .md file, to insert Erathian letters as embedded images whose style and size are not adjustable. You may also use Erathian font directly on your webpage, so that you can customize the font size, weight and other css styles, please read <a href="index.html#webfont">this</a></li>
</ul>
</div>
<div id="navbar">
<a href="index.html">Home Page (Introduction)</a> |
<a href="translator.html">Earth Language-Erathian Translator</a> |
<a href="erathian.user.js">Erathian UserScript</a>
</div>
<div id="copyrightbar">
Erathian font © 3DO/NWC, Ubi, Tom CHEN (<a href="index.html#copyright">details</a>)
</div>
</div>
</body>
</html>