Rev 228 | Go to most recent revision | 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", |
||
16 | "ng": "\uF8DC", |
||
17 | "o": "\uF8DD", |
||
18 | "p": "\uF8DE", |
||
19 | "q": "\uF8DF", |
||
20 | "Q": "\uF8E0", |
||
21 | "r": "\uF8E1", |
||
227 | PointedEar | 22 | "S": "\uF8E2", |
234 | PointedEar | 23 | "t": "\uF8E3", |
24 | "tlh": "\uF8E4", |
||
25 | "u": "\uF8E5", |
||
26 | "v": "\uF8E6", |
||
27 | "w": "\uF8E7", |
||
28 | "y": "\uF8E8", |
||
227 | PointedEar | 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 | |||
234 | PointedEar | 71 | function pIqaDize (s) |
72 | { |
||
73 | return s.replace( |
||
74 | rxKlingon, |
||
75 | function (s) { |
||
76 | return jsx.object.getProperty(klingon_map, s.replace(/\s+/g, " "), s); |
||
77 | }); |
||
78 | } |
||
227 | PointedEar | 79 | |
234 | PointedEar | 80 | var LANG_KLINGON_PIQAD = "tlh-pIqaD"; |
81 | |||
227 | PointedEar | 82 | function pIqaD (button) |
83 | { |
||
84 | klingon_texts = jsx.dom.xpath.evaluate( |
||
228 | PointedEar | 85 | './/*[@class = "text" and (@lang = "' + LANG_KLINGON |
86 | + '" or parent::*[@lang = "' + LANG_KLINGON + '"])]', |
||
227 | PointedEar | 87 | document.body); |
88 | |||
89 | if (!klingon_texts) |
||
90 | { |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | for (var i = 0, len = klingon_texts.length; i < len; ++i) |
||
95 | { |
||
96 | var text = klingon_texts[i]; |
||
97 | |||
98 | if (!text.hasAttribute("data-html")) |
||
99 | { |
||
100 | text.setAttribute("data-html", text.innerHTML); |
||
101 | |||
102 | if (!text.title) |
||
103 | { |
||
104 | text.title = text.textContent; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | var text_nodes = jsx.dom.xpath.evaluate( |
||
109 | './/text()[parent::*[not(@lang) or (@lang = "' + LANG_KLINGON + '")]]', |
||
110 | text); |
||
111 | |||
112 | for (var j = 0, len2 = text_nodes.length; j < len2; ++j) |
||
113 | { |
||
114 | var text_node = text_nodes[j]; |
||
115 | |||
234 | PointedEar | 116 | text_node.nodeValue = pIqaDize(text_node.nodeValue); |
227 | PointedEar | 117 | } |
118 | |||
234 | PointedEar | 119 | if (text.lang == LANG_KLINGON) |
120 | { |
||
121 | text.lang = LANG_KLINGON_PIQAD; |
||
122 | } |
||
123 | else if (text.parentNode.lang == LANG_KLINGON) |
||
124 | { |
||
125 | text.parentNode.lang = LANG_KLINGON_PIQAD; |
||
126 | } |
||
227 | PointedEar | 127 | } |
128 | |||
234 | PointedEar | 129 | if (button) |
227 | PointedEar | 130 | { |
234 | PointedEar | 131 | button.firstChild.lang = LANG_KLINGON; |
227 | PointedEar | 132 | } |
234 | PointedEar | 133 | |
134 | var html = document.documentElement; |
||
135 | html.setAttribute("data-lang", html.lang); |
||
136 | html.lang = LANG_KLINGON_PIQAD; |
||
227 | PointedEar | 137 | } |
138 | |||
139 | function klingonLatinScript (button) |
||
140 | { |
||
141 | for (var i = 0, len = klingon_texts.length; i < len; ++i) |
||
142 | { |
||
143 | var text = klingon_texts[i]; |
||
144 | |||
145 | text.innerHTML = text.getAttribute('data-html'); |
||
234 | PointedEar | 146 | text.removeAttribute("data-html"); |
147 | |||
148 | if (text.lang == LANG_KLINGON_PIQAD) |
||
149 | { |
||
150 | text.lang = LANG_KLINGON; |
||
151 | } |
||
152 | else if (text.parentNode.lang == LANG_KLINGON_PIQAD) |
||
153 | { |
||
154 | text.parentNode.lang = LANG_KLINGON; |
||
155 | } |
||
227 | PointedEar | 156 | } |
157 | |||
234 | PointedEar | 158 | if (button) |
228 | PointedEar | 159 | { |
234 | PointedEar | 160 | button.firstChild.lang = LANG_KLINGON_PIQAD; |
228 | PointedEar | 161 | } |
234 | PointedEar | 162 | |
163 | var html = document.documentElement; |
||
164 | html.lang = html.getAttribute("data-lang"); |
||
165 | html.removeAttribute("data-lang"); |
||
227 | PointedEar | 166 | } |