Transliteration
by nikita_turing
HTML
<div id="div_lit">
<p>Texteingabe</p>
<textarea id="inp_txt" onkeyup="/*oJS.strNormalize(this)*/" style="height:10em;width:100%" id="in">л</textarea>
<p>Ausgabe:</p>
<textarea style="height:10em;width:100%" id="out"></textarea>
</div>
<div id="rules">
<rule>
<from>а</from>
<to>a</to>
</rule>
<rule>
<from>А</from>
<to>A</to>
</rule>
<rule>
<from>б</from>
<to>b</to>
</rule>
<rule>
<from>Б</from>
<to>B</to>
</rule>
<rule>
<from>в</from>
<to>v</to>
</rule>
<rule>
<from>В</from>
<to>V</to>
</rule>
<rule>
<from>г</from>
<to>g</to>
</rule>
<rule>
<from>Г</from>
<to>G</to>
</rule>
<rule>
<from>д</from>
<to>d</to>
</rule>
<rule>
<from>Д</from>
<to>D</to>
</rule>
<rule>
<from>е</from>
<to>e</to>
</rule>
<rule>
<from>Е</from>
<to>E</to>
</rule>
<rule>
<from>ё</from>
<to>ë</to>
</rule>
<rule>
<from>Ё</from>
<to>Ë</to>
</rule>
<rule>
<from>ж</from>
<to>ž</to>
</rule>
<rule>
<from>Ж</from>
<to>Ž</to>
</rule>
<rule>
<from>з</from>
<to>z</to>
</rule>
<rule>
<from>З</from>
<to>Z</to>
</rule>
<rule>
<from>и</from>
<to>i</to>
</rule>
<rule>
<from>И</from>
<to>I</to>
</rule>
<rule>
<from>і</from>
<to>i</to>
</rule>
<rule>
<from>І</from>
<to>I</to>
...
CSS
textarea {
background: lightblue;
border: none;
border-radius: 10px;
}
p {
font-size: 2em;
}
#div_lit {
margin: 5% 10%;
}
rule {
display:none
}
JavaScript
/* Javascript functions */
function xchar(achar) {
var codeHex = achar.charCodeAt(0).toString(16).toUpperCase();
while (codeHex.length < 4) {
codeHex = "0" + codeHex;
}
return "&#x" + codeHex + ";";
}
function entityForSymbolInContainer(selector) {
var code = $(selector).text().charCodeAt(0);
var codeHex = code.toString(16).toUpperCase();
while (codeHex.length < 4) {
codeHex = "0" + codeHex;
}
return "&#x" + codeHex + ";";
}
function new_char(achar) {
var found = $('#rules').children('rule').has('from').find(":contains(" + achar + ")").siblings("to");
console.log($('#rules').children('rule').has('from').find(":contains(" + achar + ")").parent().html() + '--->' + $('#rules').children('rule').has('from').find(":contains(" + achar + ")").siblings("to").text());
if (found.length > 0) {
/* console.log("found '"+achar+"("+xchar(achar)+"/"+ $('#rules').find((":contains(" + achar + ")")).text()+")"+"' in tabelle as'"+entityForSymbolInContainer(found)+"'"); */
return found.text()
} else {
return achar
}
}
$('#inp_txt').keyup(function (event) {
var inhalt = $('#inp_txt').val();
var output = '';
for (var i = 0; i < inhalt.length; i++) {
var s_char = inhalt.charAt(i);
output += new_char(s_char);
}
$('#out').val(output);
}).keydown(function (event) {
if (event.which == 13) {
event.preventDefault();
}
});
/*
function JSfunc() {
this.strTranslit = function (el) {
new_el = document.getElementById('out');
A = new Array();
A["Ё"] = "YO";
A["Й"] = "I";
A["Ц"] = "TS";
A["У"] = "U";
A["К"] = "K";
A["Е"] = "E";
A["Н"] = "N";
A["Г"] = "G";
A["Ш"] = "SH";
A["Щ"] = "SCH";
A["З"] = "Z";
A["Х"] = "H";
A["Ъ"] = "'";
A["ё"] = "yo";
A["й"] = "i";
A["ц"] = "ts";
...