forked from notwaldorf/emoji-translate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
32 lines (27 loc) · 889 Bytes
/
demo.js
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
$(document).on('emoji:ready', function () {
updateOutput();
document.getElementById('input').addEventListener('input', function() {
updateOutput();
});
});
function updateOutput() {
document.getElementById('output').innerHTML = '';
document.getElementById('output').appendChild(translateInputChunk());
}
function translateInputChunk() {
var text = document.getElementById('input').value;
var container = document.createElement('span');
var allLines = text.split('\n');
for (var line = 0; line < allLines.length; line++ ){
if (allLines[line] == '')
continue
var words = allLines[line].split(' ');
// Re-add the translated words.
for (var i = 0; i < words.length; i++ ) {
container.appendChild(translateWord(words[i]));
}
var newLine = document.createElement('br');
container.appendChild(newLine);
}
return container;
}