Change JS translation to replace existing output when a new translation is done.

This commit is contained in:
bjorn
2008-08-15 10:53:59 +00:00
parent 8719bb9530
commit c32be3e827
2 changed files with 15 additions and 5 deletions

View File

@@ -14,7 +14,10 @@
var input = document.getElementById('inputText').value;
var fromLang = document.getElementById('fromLang').value;
var toLang = document.getElementById('toLang').value;
addTranslation('output', grammar.translate(input, fromLang, toLang));
var output = document.getElementById('output');
var translation = grammar.translate(input, fromLang, toLang);
removeChildren(output);
output.appendChild(formatTranslation(translation));
}
function populateLangs () {

View File

@@ -1,7 +1,3 @@
function addTranslation (outputID, translation) {
document.getElementById(outputID).appendChild(formatTranslation(translation));
}
function formatTranslation (outputs) {
var dl1 = document.createElement("dl");
for (var fromLang in outputs) {
@@ -19,6 +15,8 @@ function formatTranslation (outputs) {
return dl1;
}
/* DOM utilities for specific tags */
function addDefinition (dl, t, d) {
var dt = document.createElement("dt");
dt.appendChild(t);
@@ -40,3 +38,12 @@ function addOption (select, value, content) {
option.appendChild(document.createTextNode(content));
select.appendChild(option);
}
/* General DOM utilities */
/* Removes all the children of a node */
function removeChildren(node) {
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
}