Subversion Repositories LCARS

Rev

Rev 234 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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