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
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = 'tr8n'
17
17
 
18
18
  s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,local,spec,features}/*`.split("\n")
19
+ s.test_files = `git ls-files -- {test,local,spec,features,app/javascript}/*`.split("\n")
20
20
  s.extra_rdoc_files = ['README.rdoc']
21
21
  s.require_paths = ['lib']
22
22
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency 'kaminari', ['>= 0']
28
28
  s.add_dependency 'sass', ['>= 0']
29
29
  s.add_dependency 'coffee-script', ['>= 0']
30
+ s.add_development_dependency 'fssm', ['>= 0']
30
31
  s.add_development_dependency 'pry', ['>= 0']
31
32
  s.add_development_dependency 'bundler', ['>= 1.0.0']
32
33
  s.add_development_dependency 'sqlite3', ['>= 0']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr8n
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-30 00:00:00.000000000Z
12
+ date: 2012-04-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70221453981420 !ruby/object:Gem::Requirement
16
+ requirement: &70337878416480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70221453981420
24
+ version_requirements: *70337878416480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: will_filter
27
- requirement: &70221453978980 !ruby/object:Gem::Requirement
27
+ requirement: &70337878412140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70221453978980
35
+ version_requirements: *70337878412140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: kaminari
38
- requirement: &70221453977600 !ruby/object:Gem::Requirement
38
+ requirement: &70337878408320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70221453977600
46
+ version_requirements: *70337878408320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sass
49
- requirement: &70221453975980 !ruby/object:Gem::Requirement
49
+ requirement: &70337878401000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70221453975980
57
+ version_requirements: *70337878401000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: coffee-script
60
- requirement: &70221453974720 !ruby/object:Gem::Requirement
60
+ requirement: &70337878395980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,21 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70221453974720
68
+ version_requirements: *70337878395980
69
+ - !ruby/object:Gem::Dependency
70
+ name: fssm
71
+ requirement: &70337878393920 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70337878393920
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: pry
71
- requirement: &70221453973560 !ruby/object:Gem::Requirement
82
+ requirement: &70337878391400 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70221453973560
90
+ version_requirements: *70337878391400
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: bundler
82
- requirement: &70221453945020 !ruby/object:Gem::Requirement
93
+ requirement: &70337878389580 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: 1.0.0
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70221453945020
101
+ version_requirements: *70337878389580
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: sqlite3
93
- requirement: &70221453944020 !ruby/object:Gem::Requirement
104
+ requirement: &70337878387860 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70221453944020
112
+ version_requirements: *70337878387860
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: rspec
104
- requirement: &70221453943200 !ruby/object:Gem::Requirement
115
+ requirement: &70337878385780 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70221453943200
123
+ version_requirements: *70337878385780
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: rspec-rails
115
- requirement: &70221453941400 !ruby/object:Gem::Requirement
126
+ requirement: &70337878384260 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ! '>='
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: 2.1.0
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70221453941400
134
+ version_requirements: *70337878384260
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: factory_girl
126
- requirement: &70221453940140 !ruby/object:Gem::Requirement
137
+ requirement: &70337878382360 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *70221453940140
145
+ version_requirements: *70337878382360
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: spork
137
- requirement: &70221453937980 !ruby/object:Gem::Requirement
148
+ requirement: &70337878380220 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,10 +153,10 @@ dependencies:
142
153
  version: '0'
143
154
  type: :development
144
155
  prerelease: false
145
- version_requirements: *70221453937980
156
+ version_requirements: *70337878380220
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: watchr
148
- requirement: &70221453931040 !ruby/object:Gem::Requirement
159
+ requirement: &70337878376900 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - ! '>='
@@ -153,10 +164,10 @@ dependencies:
153
164
  version: '0'
154
165
  type: :development
155
166
  prerelease: false
156
- version_requirements: *70221453931040
167
+ version_requirements: *70337878376900
157
168
  - !ruby/object:Gem::Dependency
158
169
  name: rr
159
- requirement: &70221453929520 !ruby/object:Gem::Requirement
170
+ requirement: &70337878369000 !ruby/object:Gem::Requirement
160
171
  none: false
161
172
  requirements:
162
173
  - - ! '>='
@@ -164,10 +175,10 @@ dependencies:
164
175
  version: '0'
165
176
  type: :development
166
177
  prerelease: false
167
- version_requirements: *70221453929520
178
+ version_requirements: *70337878369000
168
179
  - !ruby/object:Gem::Dependency
169
180
  name: steak
170
- requirement: &70221453928200 !ruby/object:Gem::Requirement
181
+ requirement: &70337878360940 !ruby/object:Gem::Requirement
171
182
  none: false
172
183
  requirements:
173
184
  - - ! '>='
@@ -175,10 +186,10 @@ dependencies:
175
186
  version: '0'
176
187
  type: :development
177
188
  prerelease: false
178
- version_requirements: *70221453928200
189
+ version_requirements: *70337878360940
179
190
  - !ruby/object:Gem::Dependency
180
191
  name: capybara
181
- requirement: &70221453926300 !ruby/object:Gem::Requirement
192
+ requirement: &70337878356320 !ruby/object:Gem::Requirement
182
193
  none: false
183
194
  requirements:
184
195
  - - ! '>='
@@ -186,10 +197,10 @@ dependencies:
186
197
  version: '0'
187
198
  type: :development
188
199
  prerelease: false
189
- version_requirements: *70221453926300
200
+ version_requirements: *70337878356320
190
201
  - !ruby/object:Gem::Dependency
191
202
  name: database_cleaner
192
- requirement: &70221453925200 !ruby/object:Gem::Requirement
203
+ requirement: &70337895099260 !ruby/object:Gem::Requirement
193
204
  none: false
194
205
  requirements:
195
206
  - - ! '>='
@@ -197,10 +208,10 @@ dependencies:
197
208
  version: '0'
198
209
  type: :development
199
210
  prerelease: false
200
- version_requirements: *70221453925200
211
+ version_requirements: *70337895099260
201
212
  - !ruby/object:Gem::Dependency
202
213
  name: memcache-client
203
- requirement: &70221453916500 !ruby/object:Gem::Requirement
214
+ requirement: &70337895098780 !ruby/object:Gem::Requirement
204
215
  none: false
205
216
  requirements:
206
217
  - - ! '>='
@@ -208,7 +219,7 @@ dependencies:
208
219
  version: 1.8.5
209
220
  type: :development
210
221
  prerelease: false
211
- version_requirements: *70221453916500
222
+ version_requirements: *70337895098780
212
223
  description: Crowd-sourced translation and localization engine for Rails.
213
224
  email:
214
225
  - michael@tr8n.net
@@ -592,17 +603,12 @@ files:
592
603
  - app/assets/images/tr8n/warning.png
593
604
  - app/assets/images/tr8n/wizard.png
594
605
  - app/assets/javascripts/tr8n/application.js
595
- - app/assets/javascripts/tr8n/jsDraw2D.js
596
- - app/assets/javascripts/tr8n/keyboard_1_36.js
597
- - app/assets/javascripts/tr8n/keyboard_1_44.js
598
- - app/assets/javascripts/tr8n/shortcut.js
599
- - app/assets/javascripts/tr8n/tr8n.js
600
- - app/assets/javascripts/tr8n/tr8n_client_sdk.js
601
- - app/assets/javascripts/tr8n/tr8n_prototype_effects.js
606
+ - app/assets/javascripts/tr8n/tr8n-compiled.js
602
607
  - app/assets/stylesheets/tr8n/admin.css.scss
603
608
  - app/assets/stylesheets/tr8n/components.css.scss
604
609
  - app/assets/stylesheets/tr8n/keyboard_1_36.css
605
610
  - app/assets/stylesheets/tr8n/keyboard_1_44.css
611
+ - app/assets/stylesheets/tr8n/keyboard_1_49.css
606
612
  - app/assets/stylesheets/tr8n/layout.css.scss
607
613
  - app/assets/stylesheets/tr8n/tr8n.css.scss
608
614
  - app/controllers/tr8n/admin/base_controller.rb
@@ -633,6 +639,44 @@ files:
633
639
  - app/helpers/tr8n/admin/base_helper.rb
634
640
  - app/helpers/tr8n/base_helper.rb
635
641
  - app/helpers/tr8n/dashboard_helper.rb
642
+ - app/javascript/compile.rb
643
+ - app/javascript/compile.sh
644
+ - app/javascript/compressors/google/COPYING
645
+ - app/javascript/compressors/google/README
646
+ - app/javascript/compressors/google/compiler.jar
647
+ - app/javascript/config.yml
648
+ - app/javascript/src/base.js
649
+ - app/javascript/src/effects.js
650
+ - app/javascript/src/ext/inflector.js
651
+ - app/javascript/src/ext/jsDraw2D.js
652
+ - app/javascript/src/ext/keyboard_1_36.js
653
+ - app/javascript/src/ext/keyboard_1_44.js
654
+ - app/javascript/src/ext/keyboard_1_49.js
655
+ - app/javascript/src/ext/md5.js
656
+ - app/javascript/src/ext/shortcut.js
657
+ - app/javascript/src/init.js
658
+ - app/javascript/src/language.js
659
+ - app/javascript/src/logger.js
660
+ - app/javascript/src/prototype/effects.js
661
+ - app/javascript/src/proxy.js
662
+ - app/javascript/src/rules/date_rule.js
663
+ - app/javascript/src/rules/gender_list_rule.js
664
+ - app/javascript/src/rules/gender_rule.js
665
+ - app/javascript/src/rules/language_rule.js
666
+ - app/javascript/src/rules/list_rule.js
667
+ - app/javascript/src/rules/numeric_rule.js
668
+ - app/javascript/src/tml/label.js
669
+ - app/javascript/src/tml/token.js
670
+ - app/javascript/src/tokens/data_token.js
671
+ - app/javascript/src/tokens/decoration_token.js
672
+ - app/javascript/src/tokens/token.js
673
+ - app/javascript/src/tokens/transform_token.js
674
+ - app/javascript/src/translation_key.js
675
+ - app/javascript/src/ui/language_case_manager.js
676
+ - app/javascript/src/ui/language_selector.js
677
+ - app/javascript/src/ui/lightbox.js
678
+ - app/javascript/src/ui/translator.js
679
+ - app/javascript/src/utils.js
636
680
  - app/models/tr8n/base_filter.rb
637
681
  - app/models/tr8n/daily_language_metric.rb
638
682
  - app/models/tr8n/date_rule.rb
@@ -1085,7 +1129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1085
1129
  version: '0'
1086
1130
  segments:
1087
1131
  - 0
1088
- hash: -402244242122555476
1132
+ hash: -1941493027539955602
1089
1133
  required_rubygems_version: !ruby/object:Gem::Requirement
1090
1134
  none: false
1091
1135
  requirements:
@@ -1094,7 +1138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1094
1138
  version: '0'
1095
1139
  segments:
1096
1140
  - 0
1097
- hash: -402244242122555476
1141
+ hash: -1941493027539955602
1098
1142
  requirements: []
1099
1143
  rubyforge_project: tr8n
1100
1144
  rubygems_version: 1.8.10
@@ -1102,6 +1146,44 @@ signing_key:
1102
1146
  specification_version: 3
1103
1147
  summary: Crowd-sourced translation engine for Rails.
1104
1148
  test_files:
1149
+ - app/javascript/compile.rb
1150
+ - app/javascript/compile.sh
1151
+ - app/javascript/compressors/google/COPYING
1152
+ - app/javascript/compressors/google/README
1153
+ - app/javascript/compressors/google/compiler.jar
1154
+ - app/javascript/config.yml
1155
+ - app/javascript/src/base.js
1156
+ - app/javascript/src/effects.js
1157
+ - app/javascript/src/ext/inflector.js
1158
+ - app/javascript/src/ext/jsDraw2D.js
1159
+ - app/javascript/src/ext/keyboard_1_36.js
1160
+ - app/javascript/src/ext/keyboard_1_44.js
1161
+ - app/javascript/src/ext/keyboard_1_49.js
1162
+ - app/javascript/src/ext/md5.js
1163
+ - app/javascript/src/ext/shortcut.js
1164
+ - app/javascript/src/init.js
1165
+ - app/javascript/src/language.js
1166
+ - app/javascript/src/logger.js
1167
+ - app/javascript/src/prototype/effects.js
1168
+ - app/javascript/src/proxy.js
1169
+ - app/javascript/src/rules/date_rule.js
1170
+ - app/javascript/src/rules/gender_list_rule.js
1171
+ - app/javascript/src/rules/gender_rule.js
1172
+ - app/javascript/src/rules/language_rule.js
1173
+ - app/javascript/src/rules/list_rule.js
1174
+ - app/javascript/src/rules/numeric_rule.js
1175
+ - app/javascript/src/tml/label.js
1176
+ - app/javascript/src/tml/token.js
1177
+ - app/javascript/src/tokens/data_token.js
1178
+ - app/javascript/src/tokens/decoration_token.js
1179
+ - app/javascript/src/tokens/token.js
1180
+ - app/javascript/src/tokens/transform_token.js
1181
+ - app/javascript/src/translation_key.js
1182
+ - app/javascript/src/ui/language_case_manager.js
1183
+ - app/javascript/src/ui/language_selector.js
1184
+ - app/javascript/src/ui/lightbox.js
1185
+ - app/javascript/src/ui/translator.js
1186
+ - app/javascript/src/utils.js
1105
1187
  - local/tr8n_server/Rakefile
1106
1188
  - local/tr8n_server/app/assets/javascripts/application.js
1107
1189
  - local/tr8n_server/app/assets/stylesheets/admin.css.scss
@@ -1,905 +0,0 @@
1
- /****************************************************************************
2
- Copyright (c) 2010-2011 Michael Berkovich, Ian McDaniel
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
- /****************************************************************************
25
- **** Tr8n Generic Helper Functions
26
- ****************************************************************************/
27
-
28
- document.createElement('tr8n');
29
-
30
- var Tr8n = Tr8n || {
31
- element:function(element_id) {
32
- if (typeof element_id == 'string') return document.getElementById(element_id);
33
- return element_id;
34
- },
35
- value:function(element_id) {
36
- return Tr8n.element(element_id).value;
37
- }
38
- };
39
-
40
- /****************************************************************************
41
- **** Tr8n Effects Helper Functions - Can be overloaded by JS frameworks
42
- ****************************************************************************/
43
-
44
- Tr8n.Effects = {
45
- toggle: function(element_id) {
46
- if (Tr8n.element(element_id).style.display == "none")
47
- Tr8n.element(element_id).show();
48
- else
49
- Tr8n.element(element_id).hide();
50
- },
51
- hide: function(element_id) {
52
- Tr8n.element(element_id).style.display = "none";
53
- },
54
- show: function(element_id) {
55
- var style = (Tr8n.element(element_id).tagName == "SPAN") ? "inline" : "block";
56
- Tr8n.element(element_id).style.display = style;
57
- },
58
- blindUp: function(element_id) {
59
- Tr8n.Effects.hide(element_id);
60
- },
61
- blindDown: function(element_id) {
62
- Tr8n.Effects.show(element_id);
63
- },
64
- appear: function(element_id) {
65
- Tr8n.Effects.show(element_id);
66
- },
67
- fade: function(element_id) {
68
- Tr8n.Effects.hide(element_id);
69
- },
70
- submit: function(element_id) {
71
- Tr8n.element(element_id).submit();
72
- },
73
- focus: function(element_id) {
74
- Tr8n.element(element_id).focus();
75
- },
76
- scrollTo: function(element_id) {
77
- var theElement = Tr8n.element(element_id);
78
- var selectedPosX = 0;
79
- var selectedPosY = 0;
80
- while(theElement != null){
81
- selectedPosX += theElement.offsetLeft;
82
- selectedPosY += theElement.offsetTop;
83
- theElement = theElement.offsetParent;
84
- }
85
- window.scrollTo(selectedPosX,selectedPosY);
86
- }
87
- }
88
-
89
- /****************************************************************************
90
- **** Tr8n Translator
91
- ****************************************************************************/
92
-
93
- Tr8n.Translator = function(options) {
94
- var self = this;
95
- this.options = options;
96
- this.translation_key_id = null;
97
- this.suggestion_tokens = null;
98
-
99
- this.container = document.createElement('div');
100
- this.container.className = 'tr8n_translator';
101
- this.container.id = 'tr8n_translator';
102
- this.container.style.display = "none";
103
-
104
- document.body.appendChild(this.container);
105
-
106
-
107
- var event_type = Tr8n.Utils.isOpera() ? 'click' : 'contextmenu';
108
-
109
- Tr8n.Utils.addEvent(document, event_type, function(e) {
110
- if (Tr8n.Utils.isOpera() && !e.ctrlKey) return;
111
-
112
- var translatable_node = Tr8n.Utils.findElement(e, ".tr8n_translatable");
113
- var link_node = Tr8n.Utils.findElement(e, "a");
114
-
115
- if (translatable_node == null) return;
116
-
117
- if (link_node) {
118
- var temp_href = link_node.href;
119
- link_node.href='javascript:void(0);';
120
- setTimeout(function() {link_node.href = temp_href;}, 500);
121
- }
122
-
123
- if (e.stop) e.stop();
124
- if (e.preventDefault) e.preventDefault();
125
- if (e.stopPropagation) e.stopPropagation();
126
-
127
- self.show(translatable_node);
128
- return false;
129
- });
130
- }
131
-
132
- Tr8n.Translator.prototype = {
133
- hide: function() {
134
- this.container.style.display = "none";
135
- Tr8n.Utils.showFlash();
136
- },
137
-
138
- show: function(translatable_node) {
139
- var self = this;
140
- if (tr8nLanguageSelector) tr8nLanguageSelector.hide();
141
- if (tr8nLightbox) tr8nLightbox.hide();
142
- if (tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
143
- Tr8n.Utils.hideFlash();
144
-
145
- var html = "";
146
- var splash_screen = Tr8n.element('tr8n_splash_screen');
147
-
148
- if (splash_screen) {
149
- html += splash_screen.innerHTML;
150
- } else {
151
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
152
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
153
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
154
- html += "</div>"
155
- }
156
- this.container.innerHTML = html;
157
- this.container.style.display = "block";
158
-
159
- var stem = {v:"top", h:"left",width:10, height:12};
160
- var stem_type = "top_left";
161
- var target_dimensions = {width:translatable_node.offsetWidth, height:translatable_node.offsetHeight};
162
- var target_position = Tr8n.Utils.cumulativeOffset(translatable_node);
163
- var container_position = {
164
- left: (target_position[0] + 'px'),
165
- top : (target_position[1] + target_dimensions.height + stem.height + 'px')
166
- }
167
-
168
- var stem_offset = target_dimensions.width/2;
169
- var scroll_buffer = 100;
170
- var scroll_height = target_position[1] - scroll_buffer;
171
-
172
- if (window.innerWidth < target_position[0] + target_dimensions.width + window.innerWidth/2) {
173
- container_position.left = target_position[0] + target_dimensions.width - this.container.offsetWidth + "px";
174
- stem_offset = target_dimensions.width/2;
175
- stem.h = "right";
176
- }
177
-
178
- window.scrollTo(target_position[0], scroll_height);
179
- this.container.style.left = container_position.left;
180
- this.container.style.top = container_position.top;
181
- this.translation_key_id = translatable_node.getAttribute('translation_key_id');
182
-
183
- window.setTimeout(function() {
184
- Tr8n.Utils.update('tr8n_translator', '/tr8n/language/translator', {
185
- evalScripts: true,
186
- parameters: {
187
- translation_key_id: self.translation_key_id,
188
- stem_type: stem.v + "_" + stem.h,
189
- stem_offset: stem_offset
190
- }
191
- });
192
- }, 500);
193
- },
194
-
195
- reportTranslation: function(key, translation_id) {
196
- var msg = "Reporting this translation will remove it from this list and the translator will be put on a watch list. \n\nAre you sure you want to report this translation?";
197
- if (!confirm(msg)) return;
198
- this.voteOnTranslation(key, translation_id, -1000);
199
- },
200
-
201
- voteOnTranslation: function(key, translation_id, vote) {
202
- Tr8n.Effects.hide('tr8n_votes_for_' + translation_id);
203
- Tr8n.Effects.show('tr8n_spinner_for_' + translation_id);
204
-
205
- // the long version updates and reorders translations - used in translator and phrase list
206
- // the short version only updates the total results - used everywhere else
207
- if (Tr8n.element('tr8n_translator_votes_for_' + key)) {
208
- Tr8n.Utils.update('tr8n_translator_votes_for_' + key, '/tr8n/translations/vote', {
209
- parameters: {
210
- translation_id: translation_id,
211
- vote: vote
212
- },
213
- method: 'post'
214
- });
215
- } else {
216
- Tr8n.Utils.update('tr8n_votes_for_' + translation_id, '/tr8n/translations/vote', {
217
- parameters: {
218
- translation_id: translation_id,
219
- vote: vote,
220
- short_version: true
221
- },
222
- method: 'post',
223
- onComplete: function() {
224
- Tr8n.Effects.hide('tr8n_spinner_for_' + translation_id);
225
- Tr8n.Effects.show('tr8n_votes_for_' + translation_id);
226
- }
227
- });
228
- }
229
- },
230
-
231
- insertDecorationToken: function (token, txtarea_id) {
232
- txtarea_id = txtarea_id || 'tr8n_translator_translation_label';
233
- Tr8n.Utils.wrapText(txtarea_id, "[" + token + ": ", "]");
234
- },
235
-
236
- insertToken: function (token, txtarea_id) {
237
- txtarea_id = txtarea_id || 'tr8n_translator_translation_label';
238
- Tr8n.Utils.insertAtCaret(txtarea_id, "{" + token + "}");
239
- },
240
-
241
- switchTranslatorMode: function(translation_key_id, mode, source_url) {
242
- Tr8n.Utils.update('tr8n_translator_container', '/tr8n/language/translator', {
243
- parameters: {translation_key_id: translation_key_id, mode: mode, source_url: source_url},
244
- evalScripts: true
245
- });
246
- },
247
-
248
- submitTranslation: function() {
249
- Tr8n.Effects.hide('tr8n_translator_translation_container');
250
- Tr8n.Effects.hide('tr8n_translator_buttons_container');
251
- Tr8n.Effects.show('tr8n_translator_spinner');
252
- Tr8n.Effects.submit('tr8n_translator_form');
253
- },
254
-
255
- submitViewingUserDependency: function() {
256
- Tr8n.element('tr8n_translator_translation_has_dependencies').value = "true";
257
- this.submitTranslation();
258
- },
259
-
260
- submitDependencies: function() {
261
- Tr8n.Effects.hide('tr8n_translator_buttons_container');
262
- Tr8n.Effects.hide('tr8n_translator_dependencies_container');
263
- Tr8n.Effects.show('tr8n_translator_spinner');
264
- Tr8n.element('tr8n_translator_form').action = '/tr8n/translations/permutate';
265
- Tr8n.Effects.submit('tr8n_translator_form');
266
- },
267
-
268
- translate: function(label, callback, opts) {
269
- opts = opts || {}
270
- Tr8n.Utils.ajax('/tr8n/language/translate', {
271
- method: 'post',
272
- parameters: {
273
- label: label,
274
- description: opts.description,
275
- tokens: opts.tokens,
276
- options: opts.options,
277
- language: opts.language
278
- },
279
- onSuccess: function(r) {
280
- if(callback) callback(r.responseText);
281
- }
282
- });
283
- },
284
-
285
- translateBatch: function(phrases, callback) {
286
- Tr8n.Utils.ajax('/tr8n/language/translate', {
287
- method: 'post',
288
- parameters: {phrases: phrases},
289
- onSuccess: function(r) {
290
- if (callback) callback(r.responseText);
291
- }
292
- });
293
- },
294
-
295
- processSuggestedTranslation: function(response) {
296
- if (response == null ||response.data == null || response.data.translations==null || response.data.translations.length == 0)
297
- return;
298
- var suggestion = response.data.translations[0].translatedText;
299
- if (this.suggestion_tokens) {
300
- var tokens = this.suggestion_tokens.split(",");
301
- this.suggestion_tokens = null;
302
- for (var i=0; i<tokens.length; i++) {
303
- suggestion = Tr8n.Utils.replaceAll(suggestion, "(" + i + ")", tokens[i]);
304
- }
305
- }
306
- Tr8n.element("tr8n_translation_suggestion_" + this.translation_key_id).innerHTML = suggestion;
307
- Tr8n.element("tr8n_google_suggestion_container_" + this.translation_key_id).style.display = "block";
308
- var suggestion_section = Tr8n.element('tr8n_google_suggestion_section');
309
- if (suggestion_section) suggestion_section.style.display = "block";
310
- },
311
-
312
- suggestTranslation: function(translation_key_id, original, tokens, from_lang, to_lang) {
313
- if (Tr8n.google_api_key == null) return;
314
-
315
- this.suggestion_tokens = tokens;
316
- this.translation_key_id = translation_key_id;
317
- var new_script = document.createElement('script');
318
- new_script.type = 'text/javascript';
319
- var source_text = escape(original);
320
- var api_source = 'https://www.googleapis.com/language/translate/v2?key=' + Tr8n.google_api_key;
321
- var source = api_source + '&source=' + from_lang + '&target=' + to_lang + '&callback=tr8nTranslator.processSuggestedTranslation&q=' + source_text;
322
- new_script.src = source;
323
- document.getElementsByTagName('head')[0].appendChild(new_script);
324
- }
325
-
326
- }
327
-
328
- /****************************************************************************
329
- **** Tr8n Language Case Manager
330
- ****************************************************************************/
331
-
332
- Tr8n.LanguageCaseManager = function(options) {
333
- var self = this;
334
- this.options = options;
335
- this.case_key = null;
336
-
337
- this.container = document.createElement('div');
338
- this.container.className = 'tr8n_language_case_manager';
339
- this.container.id = 'tr8n_language_case_manager';
340
- this.container.style.display = "none";
341
-
342
- document.body.appendChild(this.container)
343
-
344
- var event_type = Tr8n.Utils.isOpera() ? 'click' : 'contextmenu';
345
-
346
- Tr8n.Utils.addEvent(document, event_type, function(e) {
347
- if (Tr8n.Utils.isOpera() && !e.ctrlKey) return;
348
-
349
- var case_node = Tr8n.Utils.findElement(e, ".tr8n_language_case");
350
- var link_node = Tr8n.Utils.findElement(e, "a");
351
-
352
- if (case_node == null) return;
353
-
354
- if (link_node) {
355
- var temp_href = link_node.href;
356
- link_node.href='javascript:void(0);';
357
- setTimeout(function() {link_node.href = temp_href;}, 500);
358
- }
359
-
360
- if (e.stop) e.stop();
361
- if (e.preventDefault) e.preventDefault();
362
- if (e.stopPropagation) e.stopPropagation();
363
-
364
- self.show(case_node);
365
- });
366
- }
367
-
368
- Tr8n.LanguageCaseManager.prototype = {
369
- hide: function() {
370
- this.container.style.display = "none";
371
- Tr8n.Utils.showFlash();
372
- },
373
-
374
- show: function(case_node) {
375
- var self = this;
376
- if (tr8nLanguageSelector) tr8nLanguageSelector.hide();
377
- if (tr8nLightbox) tr8nLightbox.hide();
378
- if (tr8nTranslator) tr8nTranslator.hide();
379
- Tr8n.Utils.hideFlash();
380
-
381
- var html = "";
382
- var splash_screen = Tr8n.element('tr8n_splash_screen');
383
-
384
- if (splash_screen) {
385
- html += splash_screen.innerHTML;
386
- } else {
387
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
388
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
389
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
390
- html += "</div>"
391
- }
392
- this.container.innerHTML = html;
393
- this.container.style.display = "block";
394
-
395
- var stem = {v:"top", h:"left",width:10, height:12};
396
- var stem_type = "top_left";
397
- var target_dimensions = {width:case_node.offsetWidth, height:case_node.offsetHeight};
398
- var target_position = Tr8n.Utils.cumulativeOffset(case_node);
399
- var container_position = {
400
- left: (target_position[0] + 'px'),
401
- top : (target_position[1] + target_dimensions.height + stem.height + 'px')
402
- }
403
-
404
- var stem_offset = target_dimensions.width/2;
405
- var scroll_buffer = 100;
406
- var scroll_height = target_position[1] - scroll_buffer;
407
-
408
- if (window.innerWidth < target_position[0] + target_dimensions.width + window.innerWidth/2) {
409
- container_position.left = target_position[0] + target_dimensions.width - this.container.offsetWidth + "px";
410
- stem_offset = target_dimensions.width/2;
411
- stem.h = "right";
412
- }
413
-
414
- window.scrollTo(target_position[0], scroll_height);
415
- this.container.style.left = container_position.left;
416
- this.container.style.top = container_position.top;
417
- this.case_id = case_node.getAttribute('case_id');
418
- this.rule_id = case_node.getAttribute('rule_id');
419
- this.case_key = case_node.getAttribute('case_key');
420
-
421
- window.setTimeout(function() {
422
- Tr8n.Utils.update('tr8n_language_case_manager', '/tr8n/language_cases/manager', {
423
- evalScripts: true,
424
- parameters: {
425
- case_id: self.case_id,
426
- rule_id: self.rule_id,
427
- case_key: self.case_key,
428
- stem_type: stem.v + "_" + stem.h,
429
- stem_offset: stem_offset
430
- }
431
- });
432
- }, 500);
433
- },
434
-
435
- switchToCaseMapMode: function() {
436
- Tr8n.Effects.hide('tr8n_language_case_container');
437
- Tr8n.Effects.show('tr8n_language_case_exception_container');
438
- },
439
-
440
- switchCaseMapMode: function(mode) {
441
- var self = this;
442
- Tr8n.Utils.update('tr8n_language_cases_form', '/tr8n/language_cases/switch_manager_mode', {
443
- evalScripts: true,
444
- parameters: {mode: mode, case_key: self.case_key}
445
- });
446
- },
447
-
448
- reportCaseMap: function(map_id) {
449
- var msg = "Reporting these values will remove them from the system and the translator will be put on a watch list. \n\nAre you sure you want to report these values?";
450
- if (!confirm(msg)) return;
451
-
452
- Tr8n.element("tr8n_language_case_form").action = "/tr8n/language_cases/report_value_map";
453
- Tr8n.Effects.hide('tr8n_language_case_exception_container');
454
- Tr8n.Effects.show('tr8n_language_case_report_spinner');
455
- Tr8n.Effects.submit('tr8n_language_case_form');
456
- },
457
-
458
- submitCaseMap: function() {
459
- Tr8n.Effects.hide('tr8n_language_case_exception_container');
460
- Tr8n.Effects.show('tr8n_language_case_submit_spinner');
461
- Tr8n.Effects.submit('tr8n_language_case_form');
462
- }
463
- }
464
-
465
-
466
- /****************************************************************************
467
- **** Tr8n Language Selector
468
- ****************************************************************************/
469
-
470
- Tr8n.LanguageSelector = function(options) {
471
- this.options = options || {};
472
- this.keyboardMode = false;
473
- this.loaded = false;
474
-
475
- this.container = document.createElement('div');
476
- this.container.className = 'tr8n_language_selector';
477
- this.container.id = 'tr8n_language_selector';
478
- this.container.style.display = "none";
479
-
480
- document.body.appendChild(this.container);
481
- }
482
-
483
- Tr8n.LanguageSelector.prototype = {
484
-
485
- toggle: function() {
486
- if (this.container.style.display == "none") {
487
- this.show();
488
- } else {
489
- this.hide();
490
- }
491
- },
492
-
493
- hide: function() {
494
- this.container.style.display = "none";
495
- Tr8n.Utils.showFlash();
496
- },
497
-
498
- show: function() {
499
- var self = this;
500
- if (tr8nTranslator) tr8nTranslator.hide();
501
- if (tr8nLightbox) tr8nLightbox.hide();
502
- if (tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
503
- Tr8n.Utils.hideFlash();
504
-
505
- var splash_screen = Tr8n.element('tr8n_splash_screen');
506
-
507
- if (!this.loaded) {
508
- var html = "";
509
- if (splash_screen) {
510
- html += splash_screen.innerHTML;
511
- } else {
512
- html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
513
- html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
514
- html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
515
- html += "</div>";
516
- }
517
- this.container.innerHTML = html;
518
- }
519
- this.container.style.display = "block";
520
-
521
- var trigger = Tr8n.element('tr8n_language_selector_trigger');
522
- var trigger_position = Tr8n.Utils.cumulativeOffset(trigger);
523
- var container_position = {
524
- left: trigger_position[0] + trigger.offsetWidth - this.container.offsetWidth + 'px',
525
- top: trigger_position[1] + trigger.offsetHeight + 4 + 'px'
526
- }
527
-
528
- // if (trigger_position[0] < window.innerWidth/2 ) {
529
- // this.container.offsetLeft = trigger_position[0] + 'px';
530
- // }
531
-
532
- this.container.style.left = container_position.left;
533
- this.container.style.top = container_position.top;
534
-
535
- if (!this.loaded) {
536
- window.setTimeout(function() {
537
- Tr8n.Utils.update('tr8n_language_selector', '/tr8n/language/select', {
538
- evalScripts: true
539
- })
540
- }, 100);
541
- }
542
-
543
- this.loaded = true;
544
- },
545
-
546
- removeLanguage: function(language_id) {
547
- Tr8n.Utils.update('tr8n_language_lists', '/tr8n/language/lists', {
548
- parameters: {language_action: "remove", language_id: language_id},
549
- method: 'post'
550
- });
551
- },
552
-
553
- enableInlineTranslations: function() {
554
- window.location = "/tr8n/language/switch?language_action=enable_inline_mode&source_url=" + location;
555
- },
556
-
557
- disableInlineTranslations: function() {
558
- window.location = "/tr8n/language/switch?language_action=disable_inline_mode&source_url=" + location;
559
- },
560
-
561
- showDashboard: function() {
562
- window.location = "/tr8n/dashboard";
563
- },
564
-
565
- manageLanguage: function() {
566
- window.location = "/tr8n/language";
567
- },
568
-
569
- toggleInlineTranslations: function() {
570
- window.location = "/tr8n/language/switch?language_action=toggle_inline_mode&source_url=" + location;
571
- }
572
- }
573
-
574
-
575
-
576
- /****************************************************************************
577
- **** Tr8n Lightbox
578
- ****************************************************************************/
579
-
580
- Tr8n.Lightbox = function() {
581
- this.container = document.createElement('div');
582
- this.container.className = 'tr8n_lightbox';
583
- this.container.id = 'tr8n_lightbox';
584
- this.container.style.display = "none";
585
-
586
- this.overlay = document.createElement('div');
587
- this.overlay.className = 'tr8n_lightbox_overlay';
588
- this.overlay.id = 'tr8n_lightbox_overlay';
589
- this.overlay.style.display = "none";
590
-
591
- document.body.appendChild(this.container);
592
- document.body.appendChild(this.overlay);
593
- }
594
-
595
-
596
- Tr8n.Lightbox.prototype = {
597
-
598
- hide: function() {
599
- this.container.style.display = "none";
600
- this.overlay.style.display = "none";
601
- Tr8n.Utils.showFlash();
602
- },
603
-
604
- show: function(url, opts) {
605
- var self = this;
606
- opts = opts || {};
607
- if(tr8nTranslator) tr8nTranslator.hide();
608
- if(tr8nLanguageSelector) tr8nLanguageSelector.hide();
609
- if(tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
610
- Tr8n.Utils.hideFlash();
611
-
612
- this.container.innerHTML = "<div class='inner'><div class='bd'><img src='/assets/tr8n/spinner.gif' style='vertical-align:middle'> Loading...</div></div>";
613
-
614
- this.overlay.style.display = "block";
615
-
616
- opts["width"] = opts["width"] || 700;
617
- opts["height"] = opts["height"] || 520;
618
-
619
- this.container.style.width = opts["width"] + 'px';
620
- this.container.style.height = opts["height"] + 'px';
621
- this.container.style.marginLeft = -opts["width"]/2 + 'px';
622
- this.container.style.marginTop = -opts["height"]/2 + 'px';
623
- this.container.style.display = "block";
624
-
625
- Tr8n.Utils.update('tr8n_lightbox', url, {
626
- evalScripts: true
627
- });
628
- }
629
- }
630
-
631
- /****************************************************************************
632
- **** Tr8n Utils
633
- ****************************************************************************/
634
-
635
- Tr8n.Utils = {
636
-
637
- hideFlash: function() {
638
- // alert("Hiding");
639
- var embeds = document.getElementsByTagName('embed');
640
- for(i = 0; i < embeds.length; i++) {
641
- embeds[i].style.visibility = 'hidden';
642
- }
643
- },
644
-
645
- showFlash: function() {
646
- // alert("Showing");
647
- var embeds = document.getElementsByTagName('embed');
648
- for(i = 0; i < embeds.length; i++) {
649
- embeds[i].style.visibility = 'visible';
650
- }
651
- },
652
-
653
- isOpera: function() {
654
-     return /Opera/.test(navigator.userAgent);
655
-   },
656
-
657
- addEvent: function(elm, evType, fn, useCapture) {
658
- useCapture = useCapture || false;
659
- if (elm.addEventListener) {
660
- elm.addEventListener(evType, fn, useCapture);
661
- return true;
662
- } else if (elm.attachEvent) {
663
- var r = elm.attachEvent('on' + evType, fn);
664
- return r;
665
- } else {
666
- elm['on' + evType] = fn;
667
- }
668
- },
669
-
670
- toQueryParams: function (obj) {
671
- if (typeof obj == 'undefined' || obj == null) return "";
672
- if (typeof obj == 'string') return obj;
673
-
674
- var qs = [];
675
- for(p in obj) {
676
- qs.push(p + "=" + encodeURIComponent(obj[p]))
677
- }
678
- return qs.join("&")
679
- },
680
-
681
- serializeForm: function(form) {
682
- var els = Tr8n.element(form).elements;
683
- var form_obj = {}
684
- for(i=0; i < els.length; i++) {
685
- if (els[i].type == 'checkbox' && !els[i].checked) continue;
686
- form_obj[els[i].name] = els[i].value;
687
- }
688
- return form_obj;
689
- },
690
-
691
- replaceAll: function(label, key, value) {
692
- while (label.indexOf(key) != -1) {
693
- label = label.replace(key, value);
694
- }
695
- return label;
696
- },
697
-
698
- getRequest: function() {
699
- var factories = [
700
- function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
701
- function() { return new XMLHttpRequest(); },
702
- function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
703
- ];
704
- for(var i = 0; i < factories.length; i++) {
705
- try {
706
- var request = factories[i]();
707
- if (request != null) return request;
708
- } catch(e) {continue;}
709
- }
710
- },
711
-
712
- ajax: function(url, options) {
713
- options = options || {};
714
- options.parameters = Tr8n.Utils.toQueryParams(options.parameters);
715
- options.method = options.method || 'get';
716
-
717
- var self=this;
718
- if (options.method == 'get' && options.parameters != '') {
719
- url = url + (url.indexOf('?') == -1 ? '?' : '&') + options.parameters;
720
- }
721
-
722
- var request = this.getRequest();
723
-
724
- request.onreadystatechange = function() {
725
- if(request.readyState == 4) {
726
- if (request.status == 200) {
727
- if(options.onSuccess) options.onSuccess(request);
728
- if(options.onComplete) options.onComplete(request);
729
- if(options.evalScripts) self.evalScripts(request.responseText);
730
- } else {
731
- if(options.onFailure) options.onFailure(request)
732
- if(options.onComplete) options.onComplete(request)
733
- }
734
- }
735
- }
736
-
737
- request.open(options.method, url, true);
738
- request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
739
- request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
740
- request.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
741
- request.send(options.parameters);
742
- },
743
-
744
- update: function(element_id, url, options) {
745
- options.onSuccess = function(response) {
746
- Tr8n.element(element_id).innerHTML = response.responseText;
747
- };
748
- Tr8n.Utils.ajax(url, options);
749
- },
750
-
751
- evalScripts: function(html){
752
- var script_re = '<script[^>]*>([\\S\\s]*?)<\/script>';
753
- var matchAll = new RegExp(script_re, 'img');
754
- var matchOne = new RegExp(script_re, 'im');
755
- var matches = html.match(matchAll) || [];
756
- for(var i=0,l=matches.length;i<l;i++){
757
- var script = (matches[i].match(matchOne) || ['', ''])[1];
758
- // console.info(script)
759
- // alert(script);
760
- eval(script);
761
- }
762
- },
763
-
764
- hasClassName:function(el, cls){
765
- var exp = new RegExp("(^|\\s)"+cls+"($|\\s)");
766
- return (el.className && exp.test(el.className))?true:false;
767
- },
768
-
769
- findElement: function (e,selector,el) {
770
- var event = e || window.event;
771
- var target = el || event.target || event.srcElement;
772
- if(target == document.body) return null;
773
- var condition = (selector.match(/^\./)) ? this.hasClassName(target,selector.replace(/^\./,'')) : (target.tagName.toLowerCase() == selector.toLowerCase());
774
- if(condition) {
775
- return target;
776
- } else {
777
- return this.findElement(e,selector,target.parentNode);
778
- }
779
- },
780
-
781
- cumulativeOffset: function(element) {
782
- var valueT = 0, valueL = 0;
783
- do {
784
- valueT += element.offsetTop || 0;
785
- valueL += element.offsetLeft || 0;
786
- element = element.offsetParent;
787
- } while (element);
788
- return [valueL, valueT];
789
- },
790
-
791
- wrapText: function (obj_id, beginTag, endTag) {
792
- var obj = document.getElementById(obj_id);
793
-
794
- if (typeof obj.selectionStart == 'number') {
795
- // Mozilla, Opera, and other browsers
796
- var start = obj.selectionStart;
797
- var end = obj.selectionEnd;
798
- obj.value = obj.value.substring(0, start) + beginTag + obj.value.substring(start, end) + endTag + obj.value.substring(end, obj.value.length);
799
-
800
- } else if(document.selection) {
801
- // Internet Explorer
802
- obj.focus();
803
- var range = document.selection.createRange();
804
- if(range.parentElement() != obj)
805
- return false;
806
-
807
- if(typeof range.text == 'string')
808
- document.selection.createRange().text = beginTag + range.text + endTag;
809
- } else
810
- obj.value += beginTag + " " + endTag;
811
-
812
- return true;
813
- },
814
-
815
- insertAtCaret: function (areaId, text) {
816
- var txtarea = document.getElementById(areaId);
817
- var scrollPos = txtarea.scrollTop;
818
- var strPos = 0;
819
- var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) );
820
-
821
- if (br == "ie") {
822
- txtarea.focus();
823
- var range = document.selection.createRange();
824
- range.moveStart ('character', -txtarea.value.length);
825
- strPos = range.text.length;
826
- } else if (br == "ff")
827
- strPos = txtarea.selectionStart;
828
-
829
- var front = (txtarea.value).substring(0, strPos);
830
- var back = (txtarea.value).substring(strPos, txtarea.value.length);
831
- txtarea.value=front+text+back;
832
-
833
- strPos = strPos + text.length;
834
- if (br == "ie") {
835
- txtarea.focus();
836
- var range = document.selection.createRange();
837
- range.moveStart ('character', -txtarea.value.length);
838
- range.moveStart ('character', strPos);
839
- range.moveEnd ('character', 0); range.select();
840
- } else if (br == "ff") {
841
- txtarea.selectionStart = strPos;
842
- txtarea.selectionEnd = strPos;
843
- txtarea.focus();
844
- }
845
- txtarea.scrollTop = scrollPos;
846
- },
847
-
848
- toggleKeyboards: function() {
849
- if(!VKI_attach) return;
850
- if (!this.keyboardMode) {
851
- this.keyboardMode = true;
852
-
853
- var elements = document.getElementsByTagName("input");
854
- for(i=0; i<elements.length; i++) {
855
- if (elements[i].type == "text") VKI_attach(elements[i]);
856
- }
857
- elements = document.getElementsByTagName("textarea");
858
- for(i=0; i<elements.length; i++) {
859
- VKI_attach(elements[i]);
860
- }
861
- } else {
862
- window.location.reload();
863
- }
864
- },
865
-
866
- displayShortcuts: function() {
867
- if (tr8nLightbox)
868
- tr8nLightbox.show('/tr8n/help/lb_shortcuts', {width:400, height:480});
869
- },
870
-
871
- displayStatistics: function() {
872
- if (tr8nLightbox)
873
- tr8nLightbox.show('/tr8n/help/lb_stats', {width:420, height:400});
874
- }
875
-
876
- }
877
-
878
- /****************************************************************************
879
- **** Tr8n Initialization
880
- ****************************************************************************/
881
-
882
- var tr8nTranslator = null;
883
- var tr8nLanguageSelector = null;
884
- var tr8nLightbox = null;
885
- var tr8nLanguageCaseManager = null;
886
-
887
- function initializeTr8n() {
888
- var setup = function() {
889
- tr8nTranslator = new Tr8n.Translator();
890
- tr8nLanguageSelector = new Tr8n.LanguageSelector();
891
- tr8nLightbox = new Tr8n.Lightbox();
892
- tr8nLanguageCaseManager = new Tr8n.LanguageCaseManager();
893
-
894
- Tr8n.Utils.addEvent(document, "keyup", function(event) {
895
- if (event.keyCode == 27) { // Capture Esc key
896
- tr8nTranslator.hide();
897
- tr8nLanguageSelector.hide();
898
- tr8nLightbox.hide();
899
- tr8nLanguageCaseManager.hide();
900
- }
901
- });
902
- }
903
-
904
- Tr8n.Utils.addEvent(window, 'load', setup);
905
- }