tr8n 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/Gemfile.lock +3 -1
  2. data/app/assets/javascripts/tr8n/tr8n-compiled.js +336 -0
  3. data/app/assets/stylesheets/tr8n/admin.css.scss +23 -0
  4. data/app/assets/stylesheets/tr8n/components.css.scss +23 -0
  5. data/app/assets/stylesheets/tr8n/keyboard_1_49.css +271 -0
  6. data/app/assets/stylesheets/tr8n/layout.css.scss +23 -0
  7. data/app/assets/stylesheets/tr8n/tr8n.css.scss +1 -1
  8. data/app/controllers/tr8n/api/v1/base_controller.rb +6 -0
  9. data/app/controllers/tr8n/api/v1/language_controller.rb +7 -10
  10. data/app/controllers/tr8n/api/v1/translation_controller.rb +0 -1
  11. data/app/javascript/compile.rb +37 -0
  12. data/app/javascript/compile.sh +1 -0
  13. data/app/javascript/compressors/google/COPYING +202 -0
  14. data/app/javascript/compressors/google/README +292 -0
  15. data/app/javascript/compressors/google/compiler.jar +0 -0
  16. data/app/javascript/config.yml +66 -0
  17. data/app/javascript/src/base.js +35 -0
  18. data/app/javascript/src/effects.js +67 -0
  19. data/app/javascript/src/ext/inflector.js +309 -0
  20. data/app/{assets/javascripts/tr8n → javascript/src/ext}/jsDraw2D.js +0 -0
  21. data/app/{assets/javascripts/tr8n → javascript/src/ext}/keyboard_1_36.js +0 -0
  22. data/app/{assets/javascripts/tr8n → javascript/src/ext}/keyboard_1_44.js +0 -0
  23. data/app/javascript/src/ext/keyboard_1_49.js +1796 -0
  24. data/app/javascript/src/ext/md5.js +209 -0
  25. data/app/{assets/javascripts/tr8n → javascript/src/ext}/shortcut.js +0 -0
  26. data/app/javascript/src/init.js +47 -0
  27. data/app/javascript/src/language.js +38 -0
  28. data/app/javascript/src/logger.js +203 -0
  29. data/app/{assets/javascripts/tr8n/tr8n_prototype_effects.js → javascript/src/prototype/effects.js} +5 -5
  30. data/app/javascript/src/proxy.js +254 -0
  31. data/app/javascript/src/rules/date_rule.js +37 -0
  32. data/app/javascript/src/rules/gender_list_rule.js +37 -0
  33. data/app/javascript/src/rules/gender_rule.js +87 -0
  34. data/app/javascript/src/rules/language_rule.js +55 -0
  35. data/app/javascript/src/rules/list_rule.js +37 -0
  36. data/app/javascript/src/rules/numeric_rule.js +95 -0
  37. data/app/javascript/src/tml/label.js +60 -0
  38. data/app/javascript/src/tml/token.js +107 -0
  39. data/app/javascript/src/tokens/data_token.js +45 -0
  40. data/app/javascript/src/tokens/decoration_token.js +82 -0
  41. data/app/javascript/src/tokens/token.js +121 -0
  42. data/app/javascript/src/tokens/transform_token.js +106 -0
  43. data/app/javascript/src/translation_key.js +183 -0
  44. data/app/javascript/src/ui/language_case_manager.js +155 -0
  45. data/app/javascript/src/ui/language_selector.js +126 -0
  46. data/app/javascript/src/ui/lightbox.js +72 -0
  47. data/app/javascript/src/ui/translator.js +257 -0
  48. data/app/javascript/src/utils.js +286 -0
  49. data/app/models/tr8n/language_case.rb +27 -16
  50. data/app/models/tr8n/language_case_rule.rb +24 -7
  51. data/app/models/tr8n/translation_key.rb +23 -21
  52. data/app/views/tr8n/common/_scripts.html.erb +8 -10
  53. data/app/views/tr8n/language_cases/_manager_header.html.erb +3 -3
  54. data/app/views/tr8n/language_cases/manager.html.erb +2 -2
  55. data/app/views/tr8n/translations/_original_phrase.html.erb +1 -1
  56. data/lib/tr8n/extensions/action_view_extension.rb +8 -1
  57. data/lib/tr8n/keyboard_mapping.rb +101 -0
  58. data/lib/tr8n/token.rb +1 -2
  59. data/lib/tr8n/version.rb +1 -1
  60. data/spec/models/tr8n/gender_rule_spec.rb +6 -6
  61. data/spec/models/tr8n/language_case_rule_spec.rb +219 -1
  62. data/spec/models/tr8n/language_case_spec.rb +51 -1
  63. data/spec/models/tr8n/translation_key_spec.rb +256 -0
  64. data/tr8n.gemspec +2 -1
  65. metadata +129 -47
  66. data/app/assets/javascripts/tr8n/tr8n.js +0 -905
  67. data/app/assets/javascripts/tr8n/tr8n_client_sdk.js +0 -1472
@@ -0,0 +1,209 @@
1
+ /****************************************************************************
2
+ ***
3
+ *** MD5 (Message-Digest Algorithm)
4
+ *** http://www.webtoolkit.info/javascript-md5.html
5
+ ***
6
+ *** MD5 was developed by Professor Ronald L. Rivest in 1994.
7
+ *** Its 128 bit (16 byte) message digest makes it a faster implementation than SHA-1.
8
+ ****************************************************************************/
9
+
10
+ var MD5 = function (string) {
11
+
12
+ function RotateLeft(lValue, iShiftBits) {
13
+ return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
14
+ }
15
+
16
+ function AddUnsigned(lX,lY) {
17
+ var lX4,lY4,lX8,lY8,lResult;
18
+ lX8 = (lX & 0x80000000);
19
+ lY8 = (lY & 0x80000000);
20
+ lX4 = (lX & 0x40000000);
21
+ lY4 = (lY & 0x40000000);
22
+ lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
23
+ if (lX4 & lY4) {
24
+ return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
25
+ }
26
+ if (lX4 | lY4) {
27
+ if (lResult & 0x40000000) {
28
+ return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
29
+ } else {
30
+ return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
31
+ }
32
+ } else {
33
+ return (lResult ^ lX8 ^ lY8);
34
+ }
35
+ }
36
+
37
+ function F(x,y,z) { return (x & y) | ((~x) & z); }
38
+ function G(x,y,z) { return (x & z) | (y & (~z)); }
39
+ function H(x,y,z) { return (x ^ y ^ z); }
40
+ function I(x,y,z) { return (y ^ (x | (~z))); }
41
+
42
+ function FF(a,b,c,d,x,s,ac) {
43
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
44
+ return AddUnsigned(RotateLeft(a, s), b);
45
+ };
46
+
47
+ function GG(a,b,c,d,x,s,ac) {
48
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
49
+ return AddUnsigned(RotateLeft(a, s), b);
50
+ };
51
+
52
+ function HH(a,b,c,d,x,s,ac) {
53
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
54
+ return AddUnsigned(RotateLeft(a, s), b);
55
+ };
56
+
57
+ function II(a,b,c,d,x,s,ac) {
58
+ a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
59
+ return AddUnsigned(RotateLeft(a, s), b);
60
+ };
61
+
62
+ function ConvertToWordArray(string) {
63
+ var lWordCount;
64
+ var lMessageLength = string.length;
65
+ var lNumberOfWords_temp1=lMessageLength + 8;
66
+ var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
67
+ var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
68
+ var lWordArray=Array(lNumberOfWords-1);
69
+ var lBytePosition = 0;
70
+ var lByteCount = 0;
71
+ while ( lByteCount < lMessageLength ) {
72
+ lWordCount = (lByteCount-(lByteCount % 4))/4;
73
+ lBytePosition = (lByteCount % 4)*8;
74
+ lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
75
+ lByteCount++;
76
+ }
77
+ lWordCount = (lByteCount-(lByteCount % 4))/4;
78
+ lBytePosition = (lByteCount % 4)*8;
79
+ lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
80
+ lWordArray[lNumberOfWords-2] = lMessageLength<<3;
81
+ lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
82
+ return lWordArray;
83
+ };
84
+
85
+ function WordToHex(lValue) {
86
+ var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
87
+ for (lCount = 0;lCount<=3;lCount++) {
88
+ lByte = (lValue>>>(lCount*8)) & 255;
89
+ WordToHexValue_temp = "0" + lByte.toString(16);
90
+ WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
91
+ }
92
+ return WordToHexValue;
93
+ };
94
+
95
+ function Utf8Encode(string) {
96
+ string = string.replace(/\r\n/g,"\n");
97
+ var utftext = "";
98
+
99
+ for (var n = 0; n < string.length; n++) {
100
+
101
+ var c = string.charCodeAt(n);
102
+
103
+ if (c < 128) {
104
+ utftext += String.fromCharCode(c);
105
+ }
106
+ else if((c > 127) && (c < 2048)) {
107
+ utftext += String.fromCharCode((c >> 6) | 192);
108
+ utftext += String.fromCharCode((c & 63) | 128);
109
+ }
110
+ else {
111
+ utftext += String.fromCharCode((c >> 12) | 224);
112
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
113
+ utftext += String.fromCharCode((c & 63) | 128);
114
+ }
115
+
116
+ }
117
+
118
+ return utftext;
119
+ };
120
+
121
+ var x=Array();
122
+ var k,AA,BB,CC,DD,a,b,c,d;
123
+ var S11=7, S12=12, S13=17, S14=22;
124
+ var S21=5, S22=9 , S23=14, S24=20;
125
+ var S31=4, S32=11, S33=16, S34=23;
126
+ var S41=6, S42=10, S43=15, S44=21;
127
+
128
+ string = Utf8Encode(string);
129
+
130
+ x = ConvertToWordArray(string);
131
+
132
+ a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
133
+
134
+ for (k=0;k<x.length;k+=16) {
135
+ AA=a; BB=b; CC=c; DD=d;
136
+ a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
137
+ d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
138
+ c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
139
+ b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
140
+ a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
141
+ d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
142
+ c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
143
+ b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
144
+ a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
145
+ d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
146
+ c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
147
+ b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
148
+ a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
149
+ d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
150
+ c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
151
+ b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
152
+ a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
153
+ d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
154
+ c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
155
+ b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
156
+ a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
157
+ d=GG(d,a,b,c,x[k+10],S22,0x2441453);
158
+ c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
159
+ b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
160
+ a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
161
+ d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
162
+ c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
163
+ b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
164
+ a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
165
+ d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
166
+ c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
167
+ b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
168
+ a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
169
+ d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
170
+ c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
171
+ b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
172
+ a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
173
+ d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
174
+ c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
175
+ b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
176
+ a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
177
+ d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
178
+ c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
179
+ b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
180
+ a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
181
+ d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
182
+ c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
183
+ b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
184
+ a=II(a,b,c,d,x[k+0], S41,0xF4292244);
185
+ d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
186
+ c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
187
+ b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
188
+ a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
189
+ d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
190
+ c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
191
+ b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
192
+ a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
193
+ d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
194
+ c=II(c,d,a,b,x[k+6], S43,0xA3014314);
195
+ b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
196
+ a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
197
+ d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
198
+ c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
199
+ b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
200
+ a=AddUnsigned(a,AA);
201
+ b=AddUnsigned(b,BB);
202
+ c=AddUnsigned(c,CC);
203
+ d=AddUnsigned(d,DD);
204
+ }
205
+
206
+ var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
207
+
208
+ return temp.toLowerCase();
209
+ }
@@ -0,0 +1,47 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ ****************************************************************************/
23
+
24
+ var tr8nTranslator = null;
25
+ var tr8nLanguageSelector = null;
26
+ var tr8nLightbox = null;
27
+ var tr8nLanguageCaseManager = null;
28
+
29
+ function initializeTr8n() {
30
+ var setup = function() {
31
+ tr8nTranslator = new Tr8n.Translator();
32
+ tr8nLanguageSelector = new Tr8n.LanguageSelector();
33
+ tr8nLightbox = new Tr8n.Lightbox();
34
+ tr8nLanguageCaseManager = new Tr8n.LanguageCaseManager();
35
+
36
+ Tr8n.Utils.addEvent(document, "keyup", function(event) {
37
+ if (event.keyCode == 27) { // Capture Esc key
38
+ tr8nTranslator.hide();
39
+ tr8nLanguageSelector.hide();
40
+ tr8nLightbox.hide();
41
+ tr8nLanguageCaseManager.hide();
42
+ }
43
+ });
44
+ }
45
+
46
+ Tr8n.Utils.addEvent(window, 'load', setup);
47
+ }
@@ -0,0 +1,38 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ ****************************************************************************/
23
+
24
+ Tr8n.Proxy.Language = function(options) {
25
+ this.options = options;
26
+ }
27
+
28
+ Tr8n.Proxy.Language.prototype = {
29
+ getProxy: function() {
30
+ return this.options['proxy'];
31
+ },
32
+ getLogger: function() {
33
+ return this.getProxy().logger;
34
+ },
35
+ translate: function(label, description, tokens, options) {
36
+ return (new Tr8n.Proxy.TranslationKey(label, description, {'proxy': this.getProxy()}).translate(this, tokens, options));
37
+ }
38
+ }
@@ -0,0 +1,203 @@
1
+ /****************************************************************************
2
+ Copyright (c) 2010-2012 Michael Berkovich, Ian McDaniel, tr8n.net
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ ****************************************************************************/
23
+
24
+ Tr8n.Proxy.Logger = function(options) {
25
+ this.options = options;
26
+ this.object_keys = [];
27
+ }
28
+
29
+ Tr8n.Proxy.Logger.prototype = {
30
+ clear: function() {
31
+ if (!this.options['proxy'].logger_enabled) return;
32
+ if (!this.options['element_id']) return;
33
+ if (!Tr8n.element(this.options['element_id'])) return;
34
+ Tr8n.element(this.options['element_id']).innerHTML = "";
35
+ },
36
+ append: function(msg) {
37
+ if (!this.options['proxy'].logger_enabled) return;
38
+ if (!this.options['element_id']) return;
39
+ if (!Tr8n.element(this.options['element_id'])) return;
40
+
41
+ var str = msg + "<br>" + Tr8n.element(this.options['element_id']).innerHTML;
42
+ Tr8n.element(this.options['element_id']).innerHTML = str;
43
+ },
44
+ log: function(msg) {
45
+ if (!this.options['proxy'].logger_enabled) return;
46
+ var now = new Date();
47
+ var str = "<span style='color:#ccc;'>" + (now.toLocaleDateString() + " " + now.toLocaleTimeString()) + "</span>: " + msg;
48
+ this.append(str);
49
+ },
50
+ debug: function(msg) {
51
+ if (!this.options['proxy'].logger_enabled) return;
52
+ if (window.console && console.log) {
53
+ console.log(msg);
54
+ }
55
+ this.log("<span style='color:grey'>" + msg + "</span>");
56
+ },
57
+ error: function(msg) {
58
+ if (!this.options['proxy'].logger_enabled) return;
59
+ if (window.console && console.error) {
60
+ console.error(msg);
61
+ }
62
+ this.log("<span style='color:red'>" + msg + "</span>");
63
+ },
64
+ S4: function() {
65
+ return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
66
+ },
67
+ guid: function() {
68
+ return (this.S4()+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+this.S4()+this.S4());
69
+ },
70
+ escapeHTML: function(str) {
71
+ return( str.replace(/&/g,'&amp;').replace(/>/g,'&gt;').replace(/</g,'&lt;').replace(/"/g,'&quot;'));
72
+ },
73
+ showObject: function (obj_key, flag) {
74
+ if (flag) {
75
+ Tr8n.Effects.hide("no_object_" + obj_key);
76
+ Tr8n.Effects.show("object_" + obj_key);
77
+ Tr8n.element("expander_" + obj_key).innerHTML = "<img src='/assets/tr8n/minus_node.png'>";
78
+ } else {
79
+ Tr8n.Effects.hide("object_" + obj_key);
80
+ Tr8n.Effects.show("no_object_" + obj_key);
81
+ Tr8n.element("expander_" + obj_key).innerHTML = "<img src='/assets/tr8n/plus_node.png'>";
82
+ }
83
+ },
84
+ toggleNode: function(obj_key) {
85
+ this.showObject(obj_key, (Tr8n.element("object_" + obj_key).style.display == 'none'));
86
+ },
87
+ expandAllNodes: function() {
88
+ for (var i=0; i<this.object_keys.length; i++) {
89
+ this.showObject(this.object_keys[i], true);
90
+ }
91
+ },
92
+ collapseAllNodes: function() {
93
+ for (var i=0; i<this.object_keys.length; i++) {
94
+ this.showObject(this.object_keys[i], false);
95
+ }
96
+ },
97
+ logObject: function(data) {
98
+ this.object_keys = [];
99
+ html = []
100
+ html.push("<div style='float:right;padding-right:10px;'>");
101
+ html.push("<span style='padding:2px;' onClick=\"tr8nProxy.logger.expandAllNodes()\"><img src='/assets/tr8n/plus_node.png'></span>");
102
+ html.push("<span style='padding:2px;' onClick=\"tr8nProxy.logger.collapseAllNodes()\"><img src='/assets/tr8n/minus_node.png'></span>");
103
+ html.push("</div>");
104
+
105
+ var results = data;
106
+ if (typeof results == 'string') {
107
+ try {
108
+ results = eval("[" + results + "]")[0];
109
+ }
110
+ catch (err) {
111
+ this.push(results);
112
+ return;
113
+ }
114
+ }
115
+ if (typeof results == 'object') {
116
+ html.push(this.formatObject(results, 1));
117
+ } else {
118
+ html.push(results);
119
+ }
120
+ this.append(html.join(""));
121
+ },
122
+ formatObject: function(obj, level) {
123
+ if (obj == null) return "{<br>}";
124
+
125
+ var html = [];
126
+ var obj_key = this.guid();
127
+ html.push("<span class='tr8n_logger_expander' id='expander_" + obj_key + "' onClick=\"tr8nProxy.logger.toggleNode('" + obj_key + "')\"><img src='/assets/tr8n/minus_node.png'></span> <span style='display:none' id='no_object_" + obj_key + "'>{...}</span> <span id='object_" + obj_key + "'>{");
128
+ this.object_keys.push(obj_key);
129
+
130
+ var keys = Object.keys(obj).sort();
131
+
132
+ for (var i=0; i<keys.length; i++) {
133
+ key = keys[i];
134
+ if (this.isObject(obj[key])) {
135
+ if (this.isArray(obj[key])) {
136
+ html.push(this.createSpacer(level) + "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + this.formatArray(obj[key], level + 1) + ",");
137
+ } else {
138
+ html.push(this.createSpacer(level) + "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + this.formatObject(obj[key], level + 1) + ",");
139
+ }
140
+ } else {
141
+ html.push(this.createSpacer(level) + this.formatProperty(key, obj[key]) + ",");
142
+ }
143
+ }
144
+ html.push(this.createSpacer(level-1) + "}</span>");
145
+ return html.join("<br>");
146
+ },
147
+ formatArray: function(arr, level) {
148
+ if (arr == null) return "[<br>]";
149
+
150
+ var html = [];
151
+ var obj_key = this.guid();
152
+ html.push("<span class='tr8n_logger_expander' id='expander_" + obj_key + "' onClick=\"tr8nProxy.logger.toggleNode('" + obj_key + "')\"><img src='/assets/tr8n/minus_node.png'></span> <span style='display:none' id='no_object_" + obj_key + "'>[...]</span> <span id='object_" + obj_key + "'>[");
153
+ this.object_keys.push(obj_key);
154
+
155
+ for (var i=0; i<arr.length; i++) {
156
+ if (this.isObject(arr[i])) {
157
+ if (this.isArray(arr[i])) {
158
+ html.push(this.createSpacer(level) + this.formatArray(arr[i], level + 1) + ",");
159
+ } else {
160
+ html.push(this.createSpacer(level) + this.formatObject(arr[i], level + 1) + ",");
161
+ }
162
+ } else {
163
+ html.push(this.createSpacer(level) + this.formatProperty(null, arr[i]) + ",");
164
+ }
165
+ }
166
+ html.push(this.createSpacer(level-1) + "]</span>");
167
+ return html.join("<br>");
168
+ },
169
+ formatProperty: function(key, value) {
170
+ if (value == null) return "<span class='tr8n_logger_obj_key'>" + key + ":</span><span class='obj_value_null'>null</span>";
171
+
172
+ var cls = "tr8n_logger_obj_value_" + (typeof value);
173
+ var value_span = "";
174
+
175
+ if (this.isString(value))
176
+ value_span = "<span class='" + cls + "'>\"" + this.escapeHTML(value) + "\"</span>";
177
+ else
178
+ value_span = "<span class='" + cls + "'>" + value + "</span>";
179
+
180
+ if (key == null)
181
+ return value_span;
182
+
183
+ return "<span class='tr8n_logger_obj_key'>" + key + ":</span>" + value_span;
184
+ },
185
+ createSpacer: function(level) {
186
+ return "<img src='/assets/tr8n/pixel.gif' style='height:1px;width:" + (level * 20) + "px;'>";
187
+ },
188
+ isArray: function(obj) {
189
+ if (obj == null) return false;
190
+ return !(obj.constructor.toString().indexOf("Array") == -1);
191
+ },
192
+ isObject: function(obj) {
193
+ if (obj == null) return false;
194
+ return (typeof obj == 'object');
195
+ },
196
+ isString: function(obj) {
197
+ return (typeof obj == 'string');
198
+ },
199
+ isURL: function(str) {
200
+ str = "" + str;
201
+ return (str.indexOf("http://") != -1) || (str.indexOf("https://") != -1);
202
+ }
203
+ }