j1-template 2021.2.5 → 2021.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/_includes/themes/j1/modules/connectors/translators/google-translator.html +2 -1
- data/_layouts/default.html +0 -1
- data/assets/data/iso-639-language-codes-flags.json +224 -0
- data/assets/data/{translator_languages.json → iso-639-language-codes.json} +111 -142
- data/assets/data/translator.html +23 -19
- data/assets/themes/j1/adapter/js/translator.1.js +525 -0
- data/assets/themes/j1/adapter/js/translator.js +107 -168
- data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.css +27 -12
- data/assets/themes/j1/core/css/themes/bootstrap/bootstrap.min.css +1 -1
- data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.css +27 -12
- data/assets/themes/j1/core/css/themes/uno-dark/bootstrap.min.css +1 -1
- data/assets/themes/j1/core/css/themes/uno-light/bootstrap.css +59 -22
- data/assets/themes/j1/core/css/themes/uno-light/bootstrap.min.css +1 -1
- data/assets/themes/j1/modules/translator/js/translator.js +217 -242
- data/assets/themes/j1/modules/translator/js/translator.min.js +2 -2
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/Gemfile +1 -1
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/j1_config.yml +2 -22
- data/lib/starter_web/_data/modules/defaults/translator.yml +77 -64
- data/lib/starter_web/_data/modules/translator.yml +1 -0
- data/lib/starter_web/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/_plugins/lunr_index.rb +1 -1
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/400_asciidoc_extensions.adoc +3 -3
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +5 -4
- data/assets/data/msdropdown.json +0 -155
@@ -26,153 +26,50 @@
|
|
26
26
|
// -----------------------------------------------------------------------------
|
27
27
|
|
28
28
|
function Translator(props) {
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
// ---------------------------------------------------------------------------
|
31
|
+
// global vars
|
32
|
+
// ---------------------------------------------------------------------------
|
31
33
|
var self = this;
|
34
|
+
var logger = log4javascript.getLogger('j1.core.translator');
|
35
|
+
var pageURL = new liteURL(window.location.href);
|
36
|
+
var cookieSecure = (pageURL.protocol.includes('https')) ? true : false;
|
32
37
|
var detailedSettingsShown = false;
|
33
|
-
var url = new liteURL(window.location.href);
|
34
|
-
var cookieSecure = (url.protocol.includes('https')) ? true : false;
|
35
|
-
var logText;
|
36
|
-
var current_page;
|
37
|
-
var whitelisted;
|
38
|
-
var ddTranslationSourceLanguage;
|
39
38
|
var navigator_language;
|
40
39
|
var translation_language;
|
41
40
|
|
42
41
|
// ---------------------------------------------------------------------------
|
43
|
-
//
|
42
|
+
// default property settings
|
44
43
|
// ---------------------------------------------------------------------------
|
45
|
-
|
46
44
|
this.props = {
|
47
|
-
contentURL:
|
48
|
-
cookieName:
|
49
|
-
cookieConsentName:
|
50
|
-
cookieStorageDays:
|
51
|
-
cookieSameSite:
|
52
|
-
cookieSecure:
|
53
|
-
translationEnabled:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
// supported languages by Google Translate
|
68
|
-
this.googleTranslatorLanguages = {
|
69
|
-
'af': { 'name': 'Afrikaans' },
|
70
|
-
'sq': { 'name': 'Albanian' },
|
71
|
-
'ar': { 'name': 'Arabic' },
|
72
|
-
'hy': { 'name': 'Armenian' },
|
73
|
-
'az': { 'name': 'Azerbaijani' },
|
74
|
-
'eu': { 'name': 'Basque' },
|
75
|
-
'be': { 'name': 'Belarusian' },
|
76
|
-
'bn': { 'name': 'Bengali' },
|
77
|
-
'bg': { 'name': 'Bulgarian' },
|
78
|
-
'ca': { 'name': 'Catalan' },
|
79
|
-
'zh-CN': { 'name': 'Chinese (Simplified)' },
|
80
|
-
'zh-TW': { 'name': 'Chinese (Traditional)' },
|
81
|
-
'hr': { 'name': 'Croatian' },
|
82
|
-
'cs': { 'name': 'Czech' },
|
83
|
-
'da': { 'name': 'Danish' },
|
84
|
-
'nl': { 'name': 'Dutch' },
|
85
|
-
'eo': { 'name': 'Esperanto' },
|
86
|
-
'et': { 'name': 'Estonian' },
|
87
|
-
'tl': { 'name': 'Filipino' },
|
88
|
-
'fi': { 'name': 'Finnish' },
|
89
|
-
'fr': { 'name': 'French' },
|
90
|
-
'gl': { 'name': 'Galician' },
|
91
|
-
'ka': { 'name': 'Georgian' },
|
92
|
-
'de': { 'name': 'German' },
|
93
|
-
'el': { 'name': 'Greek' },
|
94
|
-
'gu': { 'name': 'Gujarati' },
|
95
|
-
'ht': { 'name': 'Haitian Creole' },
|
96
|
-
'iw': { 'name': 'Hebrew' },
|
97
|
-
'hi': { 'name': 'Hindi' },
|
98
|
-
'hu': { 'name': 'Hungarian' },
|
99
|
-
'is': { 'name': 'Icelandic' },
|
100
|
-
'id': { 'name': 'Indonesian' },
|
101
|
-
'ga': { 'name': 'Irish' },
|
102
|
-
'it': { 'name': 'Italian' },
|
103
|
-
'ja': { 'name': 'Japanese' },
|
104
|
-
'kn': { 'name': 'Kannada' },
|
105
|
-
'ko': { 'name': 'Korean' },
|
106
|
-
'la': { 'name': 'Latin' },
|
107
|
-
'lv': { 'name': 'Latvian' },
|
108
|
-
'lt': { 'name': 'Lithuanian' },
|
109
|
-
'mk': { 'name': 'Macedonian' },
|
110
|
-
'ms': { 'name': 'Malay' },
|
111
|
-
'mt': { 'name': 'Maltese' },
|
112
|
-
'no': { 'name': 'Norwegian' },
|
113
|
-
'fa': { 'name': 'Persian' },
|
114
|
-
'pl': { 'name': 'Polish' },
|
115
|
-
'pt': { 'name': 'Portuguese' },
|
116
|
-
'ro': { 'name': 'Romanian' },
|
117
|
-
'ru': { 'name': 'Russian' },
|
118
|
-
'sr': { 'name': 'Serbian' },
|
119
|
-
'sk': { 'name': 'Slovak' },
|
120
|
-
'sl': { 'name': 'Slovenian' },
|
121
|
-
'es': { 'name': 'Spanish' },
|
122
|
-
'sw': { 'name': 'Swahili' },
|
123
|
-
'sv': { 'name': 'Swedish' },
|
124
|
-
'ta': { 'name': 'Tamil' },
|
125
|
-
'te': { 'name': 'Telugu' },
|
126
|
-
'th': { 'name': 'Thai' },
|
127
|
-
'tr': { 'name': 'Turkish' },
|
128
|
-
'uk': { 'name': 'Ukrainian' },
|
129
|
-
'ur': { 'name': 'Urdu' },
|
130
|
-
'vi': { 'name': 'Vietnamese' },
|
131
|
-
'cy': { 'name': 'Welsh' },
|
132
|
-
'yi': { 'name': 'Yiddish' }
|
45
|
+
contentURL: '/assets/data/translator', // this URL must contain the dialog content (modals) in the needed languages
|
46
|
+
cookieName: 'j1.user.state', // the name of the User State Cookie (primary data)
|
47
|
+
cookieConsentName: 'j1.user.consent', // the name of the Cookie Consent Cookie (secondary data)
|
48
|
+
cookieStorageDays: 365, // the duration the cookie is stored on the client
|
49
|
+
cookieSameSite: 'Strict', // restrict consent cookie to first-party, do NOT send cookie to other domains
|
50
|
+
cookieSecure: cookieSecure, // secure flag on cookies
|
51
|
+
translationEnabled: false, // enable|disable translation on first page view
|
52
|
+
disableLanguageSelector: false, // disable language dropdown for translation in dialog (modal)
|
53
|
+
translatorName: 'google', // name of the default translator
|
54
|
+
translationLanguages: 'all', // supported languages for translation
|
55
|
+
translationLanguage: 'auto', // language used for translation
|
56
|
+
translateAllPages: true, // enable tranlation on all pages
|
57
|
+
hideSuggestionBox: true, // disable suggestions on translated text
|
58
|
+
hidePoweredBy: true, // disable label "Powered by Google"
|
59
|
+
hideTopFrame: true, // disable the (google) translator frame
|
60
|
+
dialogLanguage: 'content', // language used for the consent dialog (modal)
|
61
|
+
dialogLanguages: ['en','de'], // supported languages for the consent dialog (modal), defaults to first in array//
|
62
|
+
dialogContainerID: 'translator-modal', // container, the dialog modal is (dynamically) loaded
|
63
|
+
xhrDataElement: '', // container for the language-specific consent modal taken from /assets/data/cookieconsent.html
|
64
|
+
postSelectionCallback: '', // callback function, called after the user has made his selection
|
133
65
|
};
|
134
66
|
|
135
|
-
//
|
136
|
-
this.deeplTranslatorLanguages = {
|
137
|
-
'bg': { 'name': 'Bulgarian' },
|
138
|
-
'cs': { 'name': 'Czech' },
|
139
|
-
'da': { 'name': 'Danish' },
|
140
|
-
'de': { 'name': 'German' },
|
141
|
-
'el': { 'name': 'Greek' },
|
142
|
-
'es': { 'name': 'Spanish' },
|
143
|
-
'en': { 'name': 'English' },
|
144
|
-
'en-us': { 'name': 'English (American)' },
|
145
|
-
'en-uk': { 'name': 'English (British)' },
|
146
|
-
'et': { 'name': 'Estonian' },
|
147
|
-
'ft': { 'name': 'Finnish' },
|
148
|
-
'fr': { 'name': 'French' },
|
149
|
-
'hu': { 'name': 'Hungarian' },
|
150
|
-
'it': { 'name': 'Italian' },
|
151
|
-
'ja': { 'name': 'Japanese' },
|
152
|
-
'lv': { 'name': 'Latvian' },
|
153
|
-
'lt': { 'name': 'Lithuanian' },
|
154
|
-
'nl': { 'name': 'Dutch' },
|
155
|
-
'af': { 'name': 'Polish' },
|
156
|
-
'pt': { 'name': 'Portuguese' },
|
157
|
-
'pt-pt': { 'name': 'Portuguese (Portugal)' },
|
158
|
-
'pt-br': { 'name': 'Portuguese (Brazilian)' },
|
159
|
-
'ro': { 'name': 'Romanian' },
|
160
|
-
'ru': { 'name': 'Russian' },
|
161
|
-
'sk': { 'name': 'Slovak' },
|
162
|
-
'sl': { 'name': 'Slovenian' },
|
163
|
-
'sv': { 'name': 'Swedish' },
|
164
|
-
'zh': { 'name': 'Chinese' },
|
165
|
-
};
|
166
|
-
|
167
|
-
for (var property in props) {
|
168
|
-
this.props[property] = props[property];
|
169
|
-
}
|
170
|
-
|
171
|
-
// merge property settings
|
67
|
+
// merge properties from default|module
|
172
68
|
for (var property in props) {
|
173
69
|
this.props[property] = props[property];
|
174
70
|
}
|
175
71
|
|
72
|
+
// extract the language portion (e.g. "en" for English)
|
176
73
|
if (this.props.dialogLanguage.indexOf("-") !== -1) {
|
177
74
|
this.props.dialogLanguage = this.props.dialogLanguage.split("-")[0];
|
178
75
|
}
|
@@ -182,12 +79,9 @@ function Translator(props) {
|
|
182
79
|
this.props.dialogLanguage = this.props.dialogLanguages[0];
|
183
80
|
}
|
184
81
|
|
185
|
-
// set
|
82
|
+
// set the xhrDataElement of the modal loadad based on dialogLanguage
|
186
83
|
this.props.xhrDataElement = this.props.xhrDataElement + '-' + this.props.dialogLanguage;
|
187
84
|
|
188
|
-
// set modal by dialogLanguage that is loadad
|
189
|
-
this.props.cookieSecure = cookieSecure;
|
190
|
-
|
191
85
|
logger.info('\n' + 'initializing core module: started');
|
192
86
|
logger.info('\n' + 'state: started');
|
193
87
|
|
@@ -196,6 +90,7 @@ function Translator(props) {
|
|
196
90
|
// ---------------------------------------------------------------------------
|
197
91
|
|
198
92
|
// ---------------------------------------------------------------------------
|
93
|
+
// Cookie()
|
199
94
|
// manage cookies
|
200
95
|
// ---------------------------------------------------------------------------
|
201
96
|
var Cookie = {
|
@@ -232,7 +127,7 @@ function Translator(props) {
|
|
232
127
|
};
|
233
128
|
|
234
129
|
// ---------------------------------------------------------------------------
|
235
|
-
//
|
130
|
+
// global event handler
|
236
131
|
// ---------------------------------------------------------------------------
|
237
132
|
var Events = {
|
238
133
|
documentReady: function (onDocumentReady) {
|
@@ -245,45 +140,127 @@ function Translator(props) {
|
|
245
140
|
};
|
246
141
|
|
247
142
|
// ---------------------------------------------------------------------------
|
248
|
-
//
|
143
|
+
// extend()
|
144
|
+
// deep merge of two objects
|
145
|
+
// ---------------------------------------------------------------------------
|
146
|
+
function extend () {
|
147
|
+
var extended = {};
|
148
|
+
var deep = false;
|
149
|
+
var i = 0;
|
150
|
+
var length = arguments.length;
|
151
|
+
|
152
|
+
// Check if a deep merge
|
153
|
+
if ( Object.prototype.toString.call( arguments[0] ) === '[object Boolean]' ) {
|
154
|
+
deep = arguments[0];
|
155
|
+
i++;
|
156
|
+
}
|
157
|
+
|
158
|
+
// Merge the object into the extended object
|
159
|
+
var merge = function (obj) {
|
160
|
+
for ( var prop in obj ) {
|
161
|
+
if ( Object.prototype.hasOwnProperty.call( obj, prop ) ) {
|
162
|
+
// If deep merge and property is an object, merge properties
|
163
|
+
if ( deep && Object.prototype.toString.call(obj[prop]) === '[object Object]' ) {
|
164
|
+
extended[prop] = extend( true, extended[prop], obj[prop] );
|
165
|
+
} else {
|
166
|
+
extended[prop] = obj[prop];
|
167
|
+
}
|
168
|
+
}
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
// Loop through each object and conduct a merge
|
173
|
+
for ( ; i < length; i++ ) {
|
174
|
+
var obj = arguments[i];
|
175
|
+
merge(obj);
|
176
|
+
}
|
177
|
+
return extended;
|
178
|
+
}
|
179
|
+
|
180
|
+
// ---------------------------------------------------------------------------
|
181
|
+
// executeFunctionByName()
|
182
|
+
// execute a function by NAME (functionName) in a browser context
|
183
|
+
// (e.g. window) the function is published
|
184
|
+
// ---------------------------------------------------------------------------
|
185
|
+
function executeFunctionByName (functionName, context /*, args */) {
|
186
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
187
|
+
var namespaces = functionName.split('.');
|
188
|
+
var func = namespaces.pop();
|
189
|
+
for(var i = 0; i < namespaces.length; i++) {
|
190
|
+
context = context[namespaces[i]];
|
191
|
+
}
|
192
|
+
return context[func].apply(context, args);
|
193
|
+
}
|
194
|
+
|
195
|
+
// ---------------------------------------------------------------------------
|
196
|
+
// createMsDropdownFromJSON()
|
249
197
|
// Create a msDropdown select DYNAMICALLY from JSON data located in a file
|
250
198
|
// specified by "url". The JSON file contaians mutiple msDropdown elements
|
251
199
|
// selected by "elm". The base (empty) <div> container the msDropdown will
|
252
200
|
// be created is specified by theID given by "selector".
|
253
201
|
// ---------------------------------------------------------------------------
|
254
202
|
function createMsDropdownFromJSON (options /* url, elm, selector */) {
|
255
|
-
var
|
256
|
-
|
203
|
+
var selectorID;
|
204
|
+
|
205
|
+
// -----------------------------------------------------------------------
|
206
|
+
// Merge values from defaults|options
|
207
|
+
// -----------------------------------------------------------------------
|
208
|
+
var settings = extend ({
|
209
|
+
size: 0,
|
210
|
+
width: 250,
|
211
|
+
multiple: false,
|
212
|
+
selectedIndex: 1,
|
213
|
+
enableAutoFilter: false,
|
214
|
+
visibleRows: null,
|
215
|
+
}, options);
|
216
|
+
|
217
|
+
selectorID = '#' + settings.selector;
|
257
218
|
|
258
219
|
$.ajax({
|
259
|
-
url:
|
220
|
+
url: settings.url,
|
260
221
|
dataType: 'json',
|
261
222
|
success: function (data) {
|
223
|
+
var dropdownLanguages = [];
|
224
|
+
|
225
|
+
// collect translation languages
|
226
|
+
if (self.props.translationLanguages.includes('all')) {
|
227
|
+
dropdownLanguages = data[settings.elm];
|
228
|
+
} else {
|
229
|
+
for (var i = 0; i < data[settings.elm].length; i++) {
|
230
|
+
if(self.props.translationLanguages.includes(data[settings.elm][i].value)) {
|
231
|
+
dropdownLanguages.push(data[settings.elm][i]);
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
// correct rows of the dropdown if required
|
237
|
+
if (settings.visibleRows > dropdownLanguages.length) {
|
238
|
+
settings.visibleRows = dropdownLanguages.length;
|
239
|
+
}
|
240
|
+
|
241
|
+
// create the dropdown
|
262
242
|
MsDropdown.make(selectorID, {
|
263
243
|
byJson: {
|
264
|
-
data:
|
265
|
-
name:
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
// multiple: false
|
244
|
+
data: dropdownLanguages,
|
245
|
+
name: settings.name,
|
246
|
+
size: settings.size,
|
247
|
+
width: settings.width,
|
248
|
+
multiple: settings.multiple,
|
270
249
|
},
|
271
|
-
enableAutoFilter:
|
250
|
+
enableAutoFilter: settings.enableAutoFilter,
|
251
|
+
visibleRows: settings.visibleRows,
|
272
252
|
});
|
273
|
-
|
274
|
-
// msDropdown = document.getElementById(options.selector).msDropdown;
|
275
|
-
// msDropdown.selectedIndex = 1;
|
276
|
-
// $(selectorID).show();
|
277
|
-
// msDropdown.on('close', function() {
|
278
|
-
// console.log(msDropdown.value)
|
279
|
-
// });
|
280
253
|
},
|
281
254
|
error: function (jqXHR, textStatus, errorThrown) {
|
282
|
-
logger.error('\n' + 'failed to retrieve JSON data from: ' + url);
|
255
|
+
logger.error('\n' + 'failed to retrieve JSON data from: ' + settings.url);
|
283
256
|
}
|
284
257
|
});
|
285
258
|
}
|
286
259
|
|
260
|
+
// ---------------------------------------------------------------------------
|
261
|
+
// showDialog
|
262
|
+
// Show|Create the translation dialog (modal)
|
263
|
+
// ---------------------------------------------------------------------------
|
287
264
|
function showDialog() {
|
288
265
|
Events.documentReady(function () {
|
289
266
|
|
@@ -295,101 +272,85 @@ function Translator(props) {
|
|
295
272
|
self.modal.setAttribute('class', 'modal fade');
|
296
273
|
self.modal.setAttribute('tabindex', '-1');
|
297
274
|
self.modal.setAttribute('role', 'dialog');
|
298
|
-
self.modal.setAttribute('aria-labelledby', dialogContainerID);
|
275
|
+
self.modal.setAttribute('aria-labelledby', self.props.dialogContainerID);
|
299
276
|
document.body.append(self.modal);
|
300
277
|
self.$modal = $(self.modal);
|
301
278
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
});
|
306
|
-
}
|
279
|
+
// ---------------------------------------------------------------------
|
280
|
+
// register events for the dialog (modal)
|
281
|
+
// ---------------------------------------------------------------------
|
307
282
|
|
308
283
|
// ---------------------------------------------------------------------
|
309
|
-
//
|
284
|
+
// on 'show'
|
310
285
|
// ---------------------------------------------------------------------
|
286
|
+
self.$modal.on('show.bs.modal', function () {
|
287
|
+
var msDropdownJSON;
|
288
|
+
var index;
|
289
|
+
|
290
|
+
logger.info('\n' + 'show.bs.modal: entered');
|
291
|
+
|
292
|
+
// create msDropdown from JSON data
|
293
|
+
$.when (
|
294
|
+
createMsDropdownFromJSON({
|
295
|
+
url: '/assets/data/iso-639-language-codes-flags.json',
|
296
|
+
elm: 'iso-639-languages',
|
297
|
+
selector: 'dropdownJSON',
|
298
|
+
width: 400,
|
299
|
+
visibleRows: 8,
|
300
|
+
})
|
301
|
+
)
|
302
|
+
.then(function(data) {
|
303
|
+
logger.info('\n' + 'creating msDropdown from JSON data: finished');
|
304
|
+
});
|
305
|
+
}); // END modal on 'show'
|
311
306
|
|
312
307
|
// ---------------------------------------------------------------------
|
313
308
|
// on 'shown'
|
309
|
+
// ---------------------------------------------------------------------
|
314
310
|
self.$modal.on('shown.bs.modal', function () {
|
315
|
-
|
316
|
-
navigator_language = navigator.language || navigator.userLanguage;
|
317
|
-
translation_language = navigator_language.split('-')[0];
|
318
|
-
}
|
311
|
+
var msDropdownJSON = document.getElementById('dropdownJSON').msDropdown;
|
319
312
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
// msDropdown.selectedIndex = 1;
|
331
|
-
//
|
332
|
-
// msDropdown.on('close', function() {
|
333
|
-
// console.log(msDropdown.value)
|
334
|
-
// });
|
335
|
-
// });
|
336
|
-
|
337
|
-
var msDropdownSourceLanguage = document.getElementById("translate-source-language").msDropdown;
|
338
|
-
|
339
|
-
// msDropdownSourceLanguage.on('close', function() {
|
340
|
-
// var selectedLanguage = msDropdownSourceLanguage.value.toLowerCase();
|
341
|
-
//
|
342
|
-
// if (translation_language !== selectedLanguage) {
|
343
|
-
// settings = JSON.parse(Cookie.get(self.props.cookieName));
|
344
|
-
// settings.translationLanguage = selectedLanguage;
|
345
|
-
// Cookie.set(self.props.cookieName, JSON.stringify(settings), self.props.cookieStorageDays, self.props.sameSite, self.props.secure);
|
346
|
-
//
|
347
|
-
// logger.info('\n' + 'selected language: ' + selectedLanguage);
|
348
|
-
// return false;
|
349
|
-
// }
|
350
|
-
// });
|
351
|
-
|
352
|
-
// workaround: limit the height of the resulting list (UL)
|
353
|
-
// of the 'dd' select
|
354
|
-
// $('.ms-options').css('max-height', '10.5937rem');
|
355
|
-
|
356
|
-
// jadams, 2021-10-18: added stop scrolling on the body,
|
357
|
-
// if modal is OPEN
|
358
|
-
$('body').addClass('stop-scrolling');
|
359
|
-
|
360
|
-
// jadams, 2021-10-18: disable source language selection
|
361
|
-
if (self.props.translationLanguage === 'auto') {
|
362
|
-
msDropdownSourceLanguage.disabled = true;
|
363
|
-
// msDropdownSourceLanguage.disabled = false;
|
364
|
-
}
|
313
|
+
if (!msDropdownJSON.length) {
|
314
|
+
// critical error
|
315
|
+
logger.error('\n' + 'no msDropdown found in translation dialog');
|
316
|
+
self.$modal.hide();
|
317
|
+
} else {
|
318
|
+
// set translation language for auto detection
|
319
|
+
if (self.props.translationLanguage === 'auto') {
|
320
|
+
navigator_language = navigator.language || navigator.userLanguage;
|
321
|
+
translation_language = navigator_language.split('-')[0];
|
322
|
+
}
|
365
323
|
|
366
|
-
|
367
|
-
|
368
|
-
// set the size to limit the list
|
369
|
-
// msDropdownSourceLanguage.size = 1;
|
324
|
+
// set translation language for the dropdown
|
325
|
+
msDropdownJSON.selectedIndex = $('#dropdownJSON option[value=' + translation_language + ']').index();;
|
370
326
|
|
371
|
-
|
327
|
+
// disable translation language selection
|
328
|
+
if (self.props.disableLanguageSelector) {
|
329
|
+
msDropdownJSON.disabled = true;
|
330
|
+
}
|
372
331
|
|
373
|
-
|
374
|
-
// on 'hidden'
|
375
|
-
self.$modal.on('hidden.bs.modal', function () {
|
376
|
-
var msDropdownSourceLanguage = document.getElementById("translate-source-language").msDropdown;
|
377
|
-
var selectedLanguage = msDropdownSourceLanguage.value.toLowerCase();
|
378
|
-
var settings;
|
332
|
+
$('#dropdownJSON').show();
|
379
333
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
Cookie.set(self.props.cookieName, JSON.stringify(settings), self.props.cookieStorageDays, self.props.sameSite, self.props.secure);
|
334
|
+
// jadams, 2021-10-18: added stop scrolling on the body,
|
335
|
+
// if modal is OPEN
|
336
|
+
$('body').addClass('stop-scrolling');
|
384
337
|
|
385
|
-
logger.info('\n' + 'selected language: ' + selectedLanguage);
|
386
|
-
return false;
|
387
338
|
}
|
339
|
+
|
340
|
+
}); // END modal on 'shown'
|
341
|
+
|
342
|
+
// ---------------------------------------------------------------------
|
343
|
+
// on 'hidden'
|
344
|
+
// ---------------------------------------------------------------------
|
345
|
+
self.$modal.on('hidden.bs.modal', function () {
|
388
346
|
$('body').removeClass('stop-scrolling');
|
389
|
-
|
347
|
+
// run the postSelectionCallback for (final) translation
|
348
|
+
executeFunctionByName (self.props.postSelectionCallback, window);
|
349
|
+
}); // END modal on 'hidden'
|
390
350
|
|
391
|
-
//
|
392
|
-
//
|
351
|
+
// ---------------------------------------------------------------------
|
352
|
+
// load the dialog (modal content)
|
353
|
+
// ---------------------------------------------------------------------
|
393
354
|
var templateUrl = self.props.contentURL + '/' + 'index.html';
|
394
355
|
$.get(templateUrl)
|
395
356
|
.done(function (data) {
|
@@ -411,6 +372,9 @@ function Translator(props) {
|
|
411
372
|
updateButtons();
|
412
373
|
updateOptionsFromCookie();
|
413
374
|
|
375
|
+
// -------------------------------------------------------------------
|
376
|
+
// register button events for the dialog (modal)
|
377
|
+
// -------------------------------------------------------------------
|
414
378
|
$('#google-options').on('hide.bs.collapse', function () {
|
415
379
|
detailedSettingsShown = false;
|
416
380
|
updateButtons();
|
@@ -448,6 +412,7 @@ function Translator(props) {
|
|
448
412
|
}
|
449
413
|
|
450
414
|
// ---------------------------------------------------------------------------
|
415
|
+
// updateOptionsFromCookie()
|
451
416
|
// update all checkboxes in dialog (modal) from current cookie settings
|
452
417
|
// ---------------------------------------------------------------------------
|
453
418
|
function updateOptionsFromCookie() {
|
@@ -461,6 +426,7 @@ function Translator(props) {
|
|
461
426
|
}
|
462
427
|
|
463
428
|
// ---------------------------------------------------------------------------
|
429
|
+
// updateButtons()
|
464
430
|
// toggle dialog (modal) buttons
|
465
431
|
// ---------------------------------------------------------------------------
|
466
432
|
function updateButtons() {
|
@@ -478,7 +444,8 @@ function Translator(props) {
|
|
478
444
|
}
|
479
445
|
|
480
446
|
// ---------------------------------------------------------------------------
|
481
|
-
//
|
447
|
+
// gatherOptions()
|
448
|
+
// collect current settings from all checkboxes in dialog (modal)
|
482
449
|
// ---------------------------------------------------------------------------
|
483
450
|
function gatherOptions(setAllExceptNecessary) {
|
484
451
|
var $options = self.$modal.find('#google-options .translator-option');
|
@@ -499,16 +466,18 @@ function Translator(props) {
|
|
499
466
|
}
|
500
467
|
|
501
468
|
// ---------------------------------------------------------------------------
|
502
|
-
//
|
469
|
+
// agreeAll()
|
470
|
+
// process current settings from checkboxes for button 'agreeAll'
|
471
|
+
// On 'agreeAll', enable ALL settings required for translation
|
503
472
|
// ---------------------------------------------------------------------------
|
504
473
|
function agreeAll() {
|
505
|
-
var
|
506
|
-
var consentSettings
|
474
|
+
var translationSettings = gatherOptions(true);
|
475
|
+
var consentSettings = {};
|
507
476
|
|
508
|
-
settings
|
477
|
+
// enable and write all settings required for translation (consent cookie)
|
509
478
|
consentSettings = JSON.parse(Cookie.get(self.props.cookieConsentName));
|
510
|
-
consentSettings.analysis =
|
511
|
-
consentSettings.personalization =
|
479
|
+
consentSettings.analysis = translationSettings.analysis;
|
480
|
+
consentSettings.personalization = translationSettings.personalization;
|
512
481
|
|
513
482
|
Cookie.set(
|
514
483
|
self.props.cookieConsentName,
|
@@ -517,9 +486,11 @@ function Translator(props) {
|
|
517
486
|
self.props.sameSite,
|
518
487
|
self.props.secure
|
519
488
|
);
|
489
|
+
|
490
|
+
// enable and write all settings required for translation (translation cookie)
|
520
491
|
Cookie.set(
|
521
492
|
self.props.cookieName,
|
522
|
-
JSON.stringify(
|
493
|
+
JSON.stringify(translationSettings),
|
523
494
|
self.props.cookieStorageDays,
|
524
495
|
self.props.sameSite,
|
525
496
|
self.props.secure
|
@@ -529,7 +500,8 @@ function Translator(props) {
|
|
529
500
|
}
|
530
501
|
|
531
502
|
// ---------------------------------------------------------------------------
|
532
|
-
//
|
503
|
+
// doNotAgree()
|
504
|
+
// process current settings from checkboxes for button `doNotAgree`
|
533
505
|
// ---------------------------------------------------------------------------
|
534
506
|
function doNotAgree() {
|
535
507
|
var settings = gatherOptions();
|
@@ -546,6 +518,7 @@ function Translator(props) {
|
|
546
518
|
}
|
547
519
|
|
548
520
|
// ---------------------------------------------------------------------------
|
521
|
+
// saveSettings()
|
549
522
|
// write current settings from checkboxes to cookie
|
550
523
|
// ---------------------------------------------------------------------------
|
551
524
|
function saveSettings() {
|
@@ -581,6 +554,7 @@ function Translator(props) {
|
|
581
554
|
// ===========================================================================
|
582
555
|
|
583
556
|
// ---------------------------------------------------------------------------
|
557
|
+
// showDialog()
|
584
558
|
// show the translator dialog (modal)
|
585
559
|
// ---------------------------------------------------------------------------
|
586
560
|
this.showDialog = function () {
|
@@ -588,6 +562,7 @@ function Translator(props) {
|
|
588
562
|
}; // END showDialog
|
589
563
|
|
590
564
|
// ---------------------------------------------------------------------------
|
565
|
+
// getSettings()
|
591
566
|
// collect settings from cookie
|
592
567
|
// ---------------------------------------------------------------------------
|
593
568
|
this.getSettings = function (optionName) {
|