summaryrefslogtreecommitdiff
path: root/src/server/translator.js
blob: 73c3dd5e2dcf2de678decbed3c5a37e4f297829d (plain)
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
function formatTranslation (outputs) {
  var dl1 = document.createElement("dl");
  for (var i in outputs) {
    var o = outputs[i];
    addDefinition(dl1, document.createTextNode(o.to), document.createTextNode(o.text));
  }

  return dl1;
}

function formatCompletions (compls) {
  var ul = document.createElement("ul");
  for (var i in compls) {
    var c = compls[i];
    addItem(ul, document.createTextNode(c.text));
  }
  return ul;
}

/* DOM utilities for specific tags */

function addDefinition (dl, t, d) {
    var dt = document.createElement("dt");
    dt.appendChild(t);
    dl.appendChild(dt);
    var dd = document.createElement("dd");
    dd.appendChild(d);
    dl.appendChild(dd);
}

function addItem (ul, i) {
    var li = document.createElement("li");
    li.appendChild(i);
    ul.appendChild(li);
}

function addOption (select, value, content) {
  var option = document.createElement("option");
  option.value = value;
  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);
  }
}