Subversion Repositories LCARS

Rev

Rev 228 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 PointedEar 1
var klingon_texts = null;
2
 
3
var klingon_map = {
4
  "A": "\uF8D0",
5
  "B": "\uF8D1",
6
  "CH": "\uF8D2",
7
  "D": "\uF8D3",
8
  "E": "\uF8D4",
9
  "GH": "\uF8D5",
10
  "H": "\uF8D6",
11
  "I": "\uF8D7",
12
  "J": "\uF8D8",
13
  "L": "\uF8D9",
14
  "M": "\uF8DA",
15
  "N": "\uF8DB",
16
  "NG": "\uF8DC",
17
  "O": "\uF8DD",
18
  "P": "\uF8DE",
19
  "Q": "\uF8DF",
20
  "QH": "\uF8E0",
21
  "R": "\uF8E1",
22
  "S": "\uF8E2",
23
  "T": "\uF8E3",
24
  "TLH": "\uF8E4",
25
  "U": "\uF8E5",
26
  "V": "\uF8E6",
27
  "W": "\uF8E7",
28
  "Y": "\uF8E8",
29
  "'": "\uF8E9",
30
  "0": "\uF8F0",
31
  "1": "\uF8F1",
32
  "2": "\uF8F2",
33
  "3": "\uF8F3",
34
  "4": "\uF8F4",
35
  "5": "\uF8F5",
36
  "6": "\uF8F6",
37
  "7": "\uF8F7",
38
  "8": "\uF8F8",
39
  "9": "\uF8F9",
40
  ",": "\uF8FD",
41
  ".": "\uF8FE",
42
 
43
  /* mummification glyph, symbol of the empire */
44
  "Δ": "\uF8FF"
45
};
46
 
47
var rxKlingon = jsx.object.getKeys(klingon_map);
48
rxKlingon.sort(function (a, b) { return b.length - a.length; });
49
rxKlingon = new RegExp(
50
  rxKlingon.filter(function (e) { return e.length > 1; }).join("|")
51
    + "|[" + rxKlingon.filter(function (e) { return e.length === 1; }). join("") + "]",
52
  "ig");
53
 
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
var media_caption;
72
 
73
function pIqaD (button)
74
{
75
  klingon_texts = jsx.dom.xpath.evaluate(
76
    './/*[@lang = "' + LANG_KLINGON + '"]'
77
      + '//*[(not(@lang) or (@lang = "' + LANG_KLINGON + '"))'
78
      + ' and (@class = "text")]',
79
    document.body);
80
 
81
  if (!klingon_texts)
82
  {
83
    return;
84
  }
85
 
86
  var previous_parent = null;
87
 
88
  for (var i = 0, len = klingon_texts.length; i < len; ++i)
89
  {
90
    var text = klingon_texts[i];
91
 
92
    text.style.fontFamily = "'pIqaD', 'Constructium', 'Code2000'";
93
    text.style.fontSize = "90%";
94
 
95
    if (!text.hasAttribute("data-html"))
96
    {
97
      text.setAttribute("data-html", text.innerHTML);
98
 
99
      if (!text.title)
100
      {
101
        text.title = text.textContent;
102
      }
103
    }
104
 
105
    var text_nodes = jsx.dom.xpath.evaluate(
106
      './/text()[parent::*[not(@lang) or (@lang = "' + LANG_KLINGON + '")]]',
107
      text);
108
 
109
    for (var j = 0, len2 = text_nodes.length; j < len2; ++j)
110
    {
111
      var text_node = text_nodes[j];
112
 
113
      if (text_node.parentNode.lang != LANG_KLINGON)
114
      {
115
        text_node.nodeValue = text_node.nodeValue.toUpperCase().replace(
116
          rxKlingon,
117
          function (s) {
118
            return jsx.object.getProperty(klingon_map, s.replace(/\s+/g, " "), s);
119
          });
120
      }
121
    }
122
 
123
    text.parentNode.lang = "tlh-pIqaD";
124
  }
125
 
126
  if (button)
127
  {
128
    media_caption = button.firstChild.textContent;
129
    button.firstChild.textContent = "Latin";
130
  }
131
}
132
 
133
function klingonLatinScript (button)
134
{
135
  for (var i = 0, len = klingon_texts.length; i < len; ++i)
136
  {
137
    var text = klingon_texts[i];
138
 
139
    text.style.fontFamily = "";
140
    text.style.fontSize = "";
141
    text.innerHTML = text.getAttribute('data-html');
142
    text.parentNode.lang = "tlh-Latn";
143
  }
144
 
145
  button.firstChild.textContent = media_caption;
146
}