Subversion Repositories LCARS

Rev

Rev 234 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 PointedEar 1
var klingon_texts = null;
2
 
3
var klingon_map = {
234 PointedEar 4
  "a": "\uF8D0",
5
  "b": "\uF8D1",
6
  "ch": "\uF8D2",
227 PointedEar 7
  "D": "\uF8D3",
234 PointedEar 8
  "e": "\uF8D4",
9
  "gh": "\uF8D5",
227 PointedEar 10
  "H": "\uF8D6",
11
  "I": "\uF8D7",
234 PointedEar 12
  "j": "\uF8D8",
13
  "l": "\uF8D9",
14
  "m": "\uF8DA",
15
  "n": "\uF8DB",
235 PointedEar 16
 
17
  /* prevents mistranscription of "n-gh" as "ng-h" (trailing garbage) */
18
  "ngh": "\uF8DB\uF8D5",
19
 
234 PointedEar 20
  "ng": "\uF8DC",
21
  "o": "\uF8DD",
22
  "p": "\uF8DE",
23
  "q": "\uF8DF",
24
  "Q": "\uF8E0",
25
  "r": "\uF8E1",
227 PointedEar 26
  "S": "\uF8E2",
234 PointedEar 27
  "t": "\uF8E3",
28
  "tlh": "\uF8E4",
29
  "u": "\uF8E5",
30
  "v": "\uF8E6",
31
  "w": "\uF8E7",
32
  "y": "\uF8E8",
227 PointedEar 33
  "'": "\uF8E9",
34
  "0": "\uF8F0",
35
  "1": "\uF8F1",
36
  "2": "\uF8F2",
37
  "3": "\uF8F3",
38
  "4": "\uF8F4",
39
  "5": "\uF8F5",
40
  "6": "\uF8F6",
41
  "7": "\uF8F7",
42
  "8": "\uF8F8",
43
  "9": "\uF8F9",
44
  ",": "\uF8FD",
45
  ".": "\uF8FE",
46
 
47
  /* mummification glyph, symbol of the empire */
48
  "Δ": "\uF8FF"
49
};
50
 
51
var rxKlingon = jsx.object.getKeys(klingon_map);
52
rxKlingon.sort(function (a, b) { return b.length - a.length; });
53
rxKlingon = new RegExp(
54
  rxKlingon.filter(function (e) { return e.length > 1; }).join("|")
55
    + "|[" + rxKlingon.filter(function (e) { return e.length === 1; }). join("") + "]",
56
  "ig");
57
 
234 PointedEar 58
function pIqaDize (s)
59
{
60
  return s.replace(
61
    rxKlingon,
62
    function (s) {
63
      return jsx.object.getProperty(klingon_map, s.replace(/\s+/g, " "), s);
64
    });
65
}
227 PointedEar 66
 
234 PointedEar 67
var LANG_KLINGON_PIQAD = "tlh-pIqaD";
68
 
227 PointedEar 69
function pIqaD (button)
70
{
71
  klingon_texts = jsx.dom.xpath.evaluate(
228 PointedEar 72
    './/*[@class = "text" and (@lang = "' + LANG_KLINGON
73
      + '" or parent::*[@lang = "' + LANG_KLINGON + '"])]',
227 PointedEar 74
    document.body);
75
 
76
  if (!klingon_texts)
77
  {
78
    return;
79
  }
80
 
235 PointedEar 81
  if (document.documentElement.lang == LANG_KLINGON)
82
  {
83
    var title = document.getElementsByTagName("title")[0];
84
    title.setAttribute("data-text", document.title);
85
    document.title = pIqaDize(document.title);
86
  }
87
 
227 PointedEar 88
  for (var i = 0, len = klingon_texts.length; i < len; ++i)
89
  {
90
    var text = klingon_texts[i];
91
 
92
    if (!text.hasAttribute("data-html"))
93
    {
94
      text.setAttribute("data-html", text.innerHTML);
95
 
96
      if (!text.title)
97
      {
98
        text.title = text.textContent;
99
      }
100
    }
101
 
102
    var text_nodes = jsx.dom.xpath.evaluate(
103
      './/text()[parent::*[not(@lang) or (@lang = "' + LANG_KLINGON + '")]]',
104
      text);
105
 
106
    for (var j = 0, len2 = text_nodes.length; j < len2; ++j)
107
    {
108
      var text_node = text_nodes[j];
109
 
234 PointedEar 110
      text_node.nodeValue = pIqaDize(text_node.nodeValue);
227 PointedEar 111
    }
112
 
234 PointedEar 113
    if (text.lang == LANG_KLINGON)
114
    {
115
      text.lang = LANG_KLINGON_PIQAD;
116
    }
235 PointedEar 117
    else if (text.parentNode && text.parentNode.lang == LANG_KLINGON)
234 PointedEar 118
    {
119
      text.parentNode.lang = LANG_KLINGON_PIQAD;
120
    }
227 PointedEar 121
  }
122
 
234 PointedEar 123
  if (button)
227 PointedEar 124
  {
234 PointedEar 125
    button.firstChild.lang = LANG_KLINGON;
227 PointedEar 126
  }
234 PointedEar 127
 
128
  var html = document.documentElement;
235 PointedEar 129
  if (html.lang == LANG_KLINGON)
130
  {
131
    html.setAttribute("data-lang", html.lang);
132
    html.lang = LANG_KLINGON_PIQAD;
133
  }
227 PointedEar 134
}
135
 
136
function klingonLatinScript (button)
137
{
235 PointedEar 138
  var title = document.getElementsByTagName("title")[0];
139
  if (document.documentElement.lang == LANG_KLINGON_PIQAD)
140
  {
141
    document.title = title.getAttribute("data-text");
142
    title.removeAttribute("data-text")
143
  }
144
 
227 PointedEar 145
  for (var i = 0, len = klingon_texts.length; i < len; ++i)
146
  {
147
    var text = klingon_texts[i];
148
 
149
    text.innerHTML = text.getAttribute('data-html');
234 PointedEar 150
    text.removeAttribute("data-html");
151
 
152
    if (text.lang == LANG_KLINGON_PIQAD)
153
    {
154
      text.lang = LANG_KLINGON;
155
    }
235 PointedEar 156
    else if (text.parentNode && text.parentNode.lang == LANG_KLINGON_PIQAD)
234 PointedEar 157
    {
158
      text.parentNode.lang = LANG_KLINGON;
159
    }
227 PointedEar 160
  }
161
 
234 PointedEar 162
  if (button)
228 PointedEar 163
  {
234 PointedEar 164
    button.firstChild.lang = LANG_KLINGON_PIQAD;
228 PointedEar 165
  }
234 PointedEar 166
 
167
  var html = document.documentElement;
235 PointedEar 168
  if (html.lang == LANG_KLINGON_PIQAD)
169
  {
170
    html.lang = html.getAttribute("data-lang");
171
    html.removeAttribute("data-lang");
172
  }
227 PointedEar 173
}