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,106 @@
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.TransformToken = function(label, token, options) {
25
+ this.label = label;
26
+ this.full_name = token;
27
+ this.options = options;
28
+ }
29
+
30
+ Tr8n.Proxy.TransformToken.prototype = new Tr8n.Proxy.Token();
31
+
32
+ Tr8n.Proxy.TransformToken.parse = function(label, options) {
33
+ var tokens = label.match(/(\{[^_][\w]+(:[\w]+)?\s*\|\|?[^{^}]+\})/g);
34
+ if (!tokens) return [];
35
+
36
+ var objects = [];
37
+ var uniq = {};
38
+ for(i=0; i<tokens.length; i++) {
39
+ if (uniq[tokens[i]]) continue;
40
+ options['proxy'].debug("Registering transform token: " + tokens[i]);
41
+ objects.push(new Tr8n.Proxy.TransformToken(label, tokens[i], options));
42
+ uniq[tokens[i]] = true;
43
+ }
44
+ return objects;
45
+ }
46
+
47
+ Tr8n.Proxy.TransformToken.prototype.getName = function() {
48
+ if (!this.name) {
49
+ this.name = Tr8n.Utils.trim(this.getDeclaredName().split('|')[0].split(':')[0]);
50
+ }
51
+ return this.name;
52
+ }
53
+
54
+ Tr8n.Proxy.TransformToken.prototype.getPipedParams = function() {
55
+ if (!this.piped_params) {
56
+ var temp = this.getDeclaredName().split('|');
57
+ temp = temp[temp.length - 1].split(",");
58
+ this.piped_params = [];
59
+ for (i=0; i<temp.length; i++) {
60
+ this.piped_params.push(Tr8n.Utils.trim(temp[i]));
61
+ }
62
+ }
63
+ return this.piped_params;
64
+ }
65
+
66
+ Tr8n.Proxy.TransformToken.prototype.substitute = function(label, token_values) {
67
+ var object = token_values[this.getName()];
68
+ if (object == null) {
69
+ this.getLogger().error("Value for token: " + this.getFullName() + " was not provided");
70
+ return label;
71
+ }
72
+
73
+ var token_object = this.getTokenObject(object);
74
+ this.getLogger().debug("Registered " + this.getPipedParams().length + " piped params");
75
+
76
+ var lang_rule_name = this.getLanguageRule();
77
+
78
+ if (!lang_rule_name) {
79
+ this.getLogger().error("Rule type cannot be determined for the transform token: " + this.getFullName());
80
+ return label;
81
+ } else {
82
+ this.getLogger().debug("Transform token uses rule: " + lang_rule_name);
83
+ }
84
+
85
+ var transform_value = eval(lang_rule_name).transform(token_object, this.getPipedParams());
86
+ this.getLogger().debug("Registered transform value: " + transform_value);
87
+
88
+ // for double pipes - show the actual value as well
89
+ if (this.isAllowedInTranslation()) {
90
+ var token_value = this.getTokenValue(object);
91
+ transform_value = token_value + " " + transform_value;
92
+ }
93
+
94
+ return Tr8n.Utils.replaceAll(label, this.getFullName(), transform_value);
95
+ }
96
+
97
+ Tr8n.Proxy.TransformToken.prototype.getPipedSeparator = function() {
98
+ if (!this.piped_separator) {
99
+ this.piped_separator = (this.getFullName().indexOf("||") != -1 ? "||" : "|");
100
+ }
101
+ return this.piped_separator;
102
+ }
103
+
104
+ Tr8n.Proxy.TransformToken.prototype.isAllowedInTranslation = function(){
105
+ return this.getPipedSeparator() == "||";
106
+ }
@@ -0,0 +1,183 @@
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.TranslationKey = function(label, description, options) {
25
+ this.label = label;
26
+ this.description = description;
27
+ this.options = options;
28
+ this.generateKey();
29
+ }
30
+
31
+ Tr8n.Proxy.TranslationKey.prototype = {
32
+ getProxy: function() {
33
+ return this.options['proxy'];
34
+ },
35
+ getLogger: function() {
36
+ return this.getProxy().logger;
37
+ },
38
+ findFirstAcceptableTranslation: function(translations, token_values) {
39
+ // check for a single translation case - no context rules
40
+ if (translations['label']!=null) {
41
+ this.getLogger().debug('Found a single translation: ' + translations['label']);
42
+ return translations;
43
+ }
44
+
45
+ translations = translations['labels'];
46
+ if (!translations) {
47
+ this.getLogger().error("Translations are in a weird form...");
48
+ return null;
49
+ }
50
+
51
+ this.getLogger().debug('Found translations: ' + translations.length);
52
+ for (var i=0; i<translations.length; i++) {
53
+ this.getLogger().debug("Checking context rules for:" + translations[i]['label']);
54
+
55
+ if (!translations[i]['context']) {
56
+ this.getLogger().debug("Translation has no context, using it by default");
57
+ return translations[i];
58
+ }
59
+ var valid_context = true;
60
+
61
+ for (var token in translations[i]['context']) {
62
+ if (!valid_context) continue;
63
+ var token_context = translations[i]['context'][token];
64
+ var rule_name = this.getProxy().getLanguageRuleForType(token_context['type']);
65
+ this.getLogger().debug("Evaluating rule: " + rule_name);
66
+ var options = {'proxy': this.getProxy()};
67
+ var rule = eval("new " + rule_name + "()");
68
+ rule.definition = token_context;
69
+ rule.options = options;
70
+ valid_context = valid_context && rule.evaluate(token, token_values);
71
+ }
72
+
73
+ if (valid_context) {
74
+ this.getLogger().debug("Found valid translation: " + translations[i].label);
75
+ return translations[i];
76
+ } else {
77
+ this.getLogger().debug("The rules were not matched for: " + translations[i].label);
78
+ }
79
+ }
80
+
81
+ this.getLogger().debug('No acceptable ranslations found');
82
+ return null;
83
+ },
84
+
85
+ translate: function(language, token_values, options) {
86
+ if (!this.label) {
87
+ this.getLogger().error('Label must always be provided for the translate method');
88
+ return '';
89
+ }
90
+
91
+ var translations = this.getProxy().getTranslations();
92
+ var translation_key = translations[this.key];
93
+
94
+ if (translation_key) {
95
+ this.getLogger().debug("Found translations, evaluating rules...");
96
+
97
+ this.id = translation_key.id;
98
+ this.original = translation_key.original;
99
+ var translation = this.findFirstAcceptableTranslation(translation_key, token_values);
100
+
101
+ if (translation) {
102
+ this.getLogger().debug("Found a valid match: " + translation.label);
103
+ return this.substituteTokens(translation['label'], token_values, options);
104
+ } else {
105
+ this.getLogger().debug("No valid match found, using default language");
106
+ return this.substituteTokens(this.label, token_values, options);
107
+ }
108
+
109
+ } else {
110
+ this.getLogger().debug("Translation not found, using default language");
111
+ }
112
+
113
+ this.getProxy().registerMissingTranslationKey(this, token_values, options);
114
+ this.getLogger().debug('No translation found. Using default...');
115
+ return this.substituteTokens(this.label, token_values, options);
116
+ },
117
+
118
+ generateKey: function() {
119
+ this.key = this.label + ";;;";
120
+ if (this.description) this.key = this.key + this.description;
121
+
122
+ this.getLogger().debug('Preparing label signature: ' + this.key);
123
+ this.key = MD5(this.key);
124
+ this.getLogger().debug('Label signature: ' + this.key);
125
+ },
126
+
127
+ registerDataTokens: function(label) {
128
+ this.data_tokens = [];
129
+ this.data_tokens = this.data_tokens.concat(Tr8n.Proxy.DataToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
130
+ this.data_tokens = this.data_tokens.concat(Tr8n.Proxy.TransformToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
131
+ },
132
+
133
+ registerDecorationTokens: function(label) {
134
+ this.decoration_tokens = [];
135
+ this.decoration_tokens = this.decoration_tokens.concat(Tr8n.Proxy.DecorationToken.parse(label, {'key': this, 'proxy':this.getProxy()}));
136
+ },
137
+
138
+ substituteTokens: function(label, token_values, options) {
139
+ this.registerDataTokens(label);
140
+ if (!this.data_tokens) return this.decorateLabel(label, options);
141
+ for (var i = 0; i < this.data_tokens.length; i++) {
142
+ label = this.data_tokens[i].substitute(label, token_values || {});
143
+ }
144
+
145
+ this.registerDecorationTokens(label);
146
+ if (!this.decoration_tokens) return label;
147
+ for (var i = 0; i < this.decoration_tokens.length; i++) {
148
+ label = this.decoration_tokens[i].substitute(label, token_values || {});
149
+ }
150
+
151
+ return this.decorateLabel(label, options);
152
+ },
153
+
154
+ decorateLabel: function(label, options){
155
+ options = options || {};
156
+ if (options['skip_decorations'])
157
+ return label;
158
+
159
+ html = [];
160
+ html.push("<tr8n ");
161
+
162
+ if (this.id)
163
+ html.push(" translation_key_id='" + this.id + "' ");
164
+
165
+ if (this.key)
166
+ html.push(" id='" + this.key + "' ");
167
+
168
+ var klasses = ['tr8n_translatable'];
169
+
170
+ if (this.original)
171
+ klasses.push('tr8n_not_translated');
172
+ else
173
+ klasses.push('tr8n_translated');
174
+
175
+ if (this.getProxy().inline_translations_enabled && this.id)
176
+ html.push(" class='" + klasses.join(' ') + "'");
177
+
178
+ html.push(">");
179
+ html.push(label);
180
+ html.push("</tr8n>");
181
+ return html.join("");
182
+ }
183
+ }
@@ -0,0 +1,155 @@
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.LanguageCaseManager = function(options) {
25
+ var self = this;
26
+ this.options = options;
27
+ this.case_key = null;
28
+
29
+ this.container = document.createElement('div');
30
+ this.container.className = 'tr8n_language_case_manager';
31
+ this.container.id = 'tr8n_language_case_manager';
32
+ this.container.style.display = "none";
33
+
34
+ document.body.appendChild(this.container)
35
+
36
+ var event_type = Tr8n.Utils.isOpera() ? 'click' : 'contextmenu';
37
+
38
+ Tr8n.Utils.addEvent(document, event_type, function(e) {
39
+ if (Tr8n.Utils.isOpera() && !e.ctrlKey) return;
40
+
41
+ var case_node = Tr8n.Utils.findElement(e, ".tr8n_language_case");
42
+ var link_node = Tr8n.Utils.findElement(e, "a");
43
+
44
+ if (case_node == null) return;
45
+
46
+ if (link_node) {
47
+ var temp_href = link_node.href;
48
+ link_node.href='javascript:void(0);';
49
+ setTimeout(function() {link_node.href = temp_href;}, 500);
50
+ }
51
+
52
+ if (e.stop) e.stop();
53
+ if (e.preventDefault) e.preventDefault();
54
+ if (e.stopPropagation) e.stopPropagation();
55
+
56
+ self.show(case_node);
57
+ });
58
+ }
59
+
60
+ Tr8n.LanguageCaseManager.prototype = {
61
+ hide: function() {
62
+ this.container.style.display = "none";
63
+ Tr8n.Utils.showFlash();
64
+ },
65
+
66
+ show: function(case_node) {
67
+ var self = this;
68
+ if (tr8nLanguageSelector) tr8nLanguageSelector.hide();
69
+ if (tr8nLightbox) tr8nLightbox.hide();
70
+ if (tr8nTranslator) tr8nTranslator.hide();
71
+ Tr8n.Utils.hideFlash();
72
+
73
+ var html = "";
74
+ var splash_screen = Tr8n.element('tr8n_splash_screen');
75
+
76
+ if (splash_screen) {
77
+ html += splash_screen.innerHTML;
78
+ } else {
79
+ html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
80
+ html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
81
+ html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
82
+ html += "</div>"
83
+ }
84
+ this.container.innerHTML = html;
85
+ this.container.style.display = "block";
86
+
87
+ var stem = {v:"top", h:"left",width:10, height:12};
88
+ var stem_type = "top_left";
89
+ var target_dimensions = {width:case_node.offsetWidth, height:case_node.offsetHeight};
90
+ var target_position = Tr8n.Utils.cumulativeOffset(case_node);
91
+ var container_position = {
92
+ left: (target_position[0] + 'px'),
93
+ top : (target_position[1] + target_dimensions.height + stem.height + 'px')
94
+ }
95
+
96
+ var stem_offset = target_dimensions.width/2;
97
+ var scroll_buffer = 100;
98
+ var scroll_height = target_position[1] - scroll_buffer;
99
+
100
+ if (window.innerWidth < target_position[0] + target_dimensions.width + window.innerWidth/2) {
101
+ container_position.left = target_position[0] + target_dimensions.width - this.container.offsetWidth + "px";
102
+ stem_offset = target_dimensions.width/2;
103
+ stem.h = "right";
104
+ }
105
+
106
+ window.scrollTo(target_position[0], scroll_height);
107
+ this.container.style.left = container_position.left;
108
+ this.container.style.top = container_position.top;
109
+ this.case_id = case_node.getAttribute('case_id');
110
+ this.rule_id = case_node.getAttribute('rule_id');
111
+ this.case_key = case_node.getAttribute('case_key');
112
+
113
+ window.setTimeout(function() {
114
+ Tr8n.Utils.update('tr8n_language_case_manager', '/tr8n/language_cases/manager', {
115
+ evalScripts: true,
116
+ parameters: {
117
+ case_id: self.case_id,
118
+ rule_id: self.rule_id,
119
+ case_key: self.case_key,
120
+ stem_type: stem.v + "_" + stem.h,
121
+ stem_offset: stem_offset
122
+ }
123
+ });
124
+ }, 500);
125
+ },
126
+
127
+ switchToCaseMapMode: function() {
128
+ Tr8n.Effects.hide('tr8n_language_case_container');
129
+ Tr8n.Effects.show('tr8n_language_case_exception_container');
130
+ },
131
+
132
+ switchCaseMapMode: function(mode) {
133
+ var self = this;
134
+ Tr8n.Utils.update('tr8n_language_cases_form', '/tr8n/language_cases/switch_manager_mode', {
135
+ evalScripts: true,
136
+ parameters: {mode: mode, case_key: self.case_key}
137
+ });
138
+ },
139
+
140
+ reportCaseMap: function(map_id) {
141
+ 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?";
142
+ if (!confirm(msg)) return;
143
+
144
+ Tr8n.element("tr8n_language_case_form").action = "/tr8n/language_cases/report_value_map";
145
+ Tr8n.Effects.hide('tr8n_language_case_exception_container');
146
+ Tr8n.Effects.show('tr8n_language_case_report_spinner');
147
+ Tr8n.Effects.submit('tr8n_language_case_form');
148
+ },
149
+
150
+ submitCaseMap: function() {
151
+ Tr8n.Effects.hide('tr8n_language_case_exception_container');
152
+ Tr8n.Effects.show('tr8n_language_case_submit_spinner');
153
+ Tr8n.Effects.submit('tr8n_language_case_form');
154
+ }
155
+ }
@@ -0,0 +1,126 @@
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.LanguageSelector = function(options) {
25
+ this.options = options || {};
26
+ this.keyboardMode = false;
27
+ this.loaded = false;
28
+
29
+ this.container = document.createElement('div');
30
+ this.container.className = 'tr8n_language_selector';
31
+ this.container.id = 'tr8n_language_selector';
32
+ this.container.style.display = "none";
33
+
34
+ document.body.appendChild(this.container);
35
+ }
36
+
37
+ Tr8n.LanguageSelector.prototype = {
38
+
39
+ toggle: function() {
40
+ if (this.container.style.display == "none") {
41
+ this.show();
42
+ } else {
43
+ this.hide();
44
+ }
45
+ },
46
+
47
+ hide: function() {
48
+ this.container.style.display = "none";
49
+ Tr8n.Utils.showFlash();
50
+ },
51
+
52
+ show: function() {
53
+ var self = this;
54
+ if (tr8nTranslator) tr8nTranslator.hide();
55
+ if (tr8nLightbox) tr8nLightbox.hide();
56
+ if (tr8nLanguageCaseManager) tr8nLanguageCaseManager.hide();
57
+ Tr8n.Utils.hideFlash();
58
+
59
+ var splash_screen = Tr8n.element('tr8n_splash_screen');
60
+
61
+ if (!this.loaded) {
62
+ var html = "";
63
+ if (splash_screen) {
64
+ html += splash_screen.innerHTML;
65
+ } else {
66
+ html += "<div style='font-size:18px;text-align:center; margin:5px; padding:10px; background-color:black;'>";
67
+ html += " <img src='/assets/tr8n/tr8n_logo.jpg' style='width:280px; vertical-align:middle;'>";
68
+ html += " <img src='/assets/tr8n/loading3.gif' style='width:200px; height:20px; vertical-align:middle;'>";
69
+ html += "</div>";
70
+ }
71
+ this.container.innerHTML = html;
72
+ }
73
+ this.container.style.display = "block";
74
+
75
+ var trigger = Tr8n.element('tr8n_language_selector_trigger');
76
+ var trigger_position = Tr8n.Utils.cumulativeOffset(trigger);
77
+ var container_position = {
78
+ left: trigger_position[0] + trigger.offsetWidth - this.container.offsetWidth + 'px',
79
+ top: trigger_position[1] + trigger.offsetHeight + 4 + 'px'
80
+ }
81
+
82
+ // if (trigger_position[0] < window.innerWidth/2 ) {
83
+ // this.container.offsetLeft = trigger_position[0] + 'px';
84
+ // }
85
+
86
+ this.container.style.left = container_position.left;
87
+ this.container.style.top = container_position.top;
88
+
89
+ if (!this.loaded) {
90
+ window.setTimeout(function() {
91
+ Tr8n.Utils.update('tr8n_language_selector', '/tr8n/language/select', {
92
+ evalScripts: true
93
+ })
94
+ }, 100);
95
+ }
96
+
97
+ this.loaded = true;
98
+ },
99
+
100
+ removeLanguage: function(language_id) {
101
+ Tr8n.Utils.update('tr8n_language_lists', '/tr8n/language/lists', {
102
+ parameters: {language_action: "remove", language_id: language_id},
103
+ method: 'post'
104
+ });
105
+ },
106
+
107
+ enableInlineTranslations: function() {
108
+ window.location = "/tr8n/language/switch?language_action=enable_inline_mode&source_url=" + location;
109
+ },
110
+
111
+ disableInlineTranslations: function() {
112
+ window.location = "/tr8n/language/switch?language_action=disable_inline_mode&source_url=" + location;
113
+ },
114
+
115
+ showDashboard: function() {
116
+ window.location = "/tr8n/dashboard";
117
+ },
118
+
119
+ manageLanguage: function() {
120
+ window.location = "/tr8n/language";
121
+ },
122
+
123
+ toggleInlineTranslations: function() {
124
+ window.location = "/tr8n/language/switch?language_action=toggle_inline_mode&source_url=" + location;
125
+ }
126
+ }