j1-template 2022.0.1 → 2022.0.5
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/blocks/ads/ad.html +14 -14
- data/_includes/themes/j1/layouts/content_generator_post.html +1 -1
- data/_includes/themes/j1/modules/connectors/analytic/google-analytics.html +3 -13
- data/_includes/themes/j1/modules/connectors/comment/hyvor.html +4 -5
- data/_includes/themes/j1/modules/navigator/generator.html +3 -3
- data/_includes/themes/j1/modules/search/docsearch.html +1 -1
- data/_includes/themes/j1/procedures/global/create_bs_button.proc +4 -4
- data/_includes/themes/j1/procedures/posts/collate_timeline.proc +2 -2
- data/_includes/themes/j1/procedures/posts/create_series_header.proc +1 -1
- data/_includes/themes/j1/procedures/posts/pager.proc +2 -2
- data/_layouts/default.html +3 -11
- data/assets/data/authclient.html +11 -11
- data/assets/data/cookieconsent.html +8 -8
- data/assets/data/gallery_customizer.html +4 -4
- data/assets/data/menu.html +13 -13
- data/assets/data/mmenu.html +2 -2
- data/assets/data/private.json +1 -5
- data/assets/data/quicklinks.html +62 -47
- data/assets/data/rtext_resizer.html +1 -1
- data/assets/data/themes.bootswatch.json +2 -2
- data/assets/data/themes.json +4 -4
- data/assets/data/translator.html +8 -8
- data/assets/themes/j1/adapter/js/clipboard.js +1 -1
- data/assets/themes/j1/adapter/js/cookieConsent.js +18 -13
- data/assets/themes/j1/adapter/js/j1.js +23 -23
- data/assets/themes/j1/adapter/js/navigator.js +3 -3
- data/assets/themes/j1/adapter/js/themer.js +13 -4
- data/assets/themes/j1/adapter/js/translator.js +10 -6
- data/assets/themes/j1/core/css/themes/{uno-dark → unodark}/bootstrap.css +0 -0
- data/assets/themes/j1/core/css/themes/{uno-dark → unodark}/bootstrap.min.css +0 -0
- data/assets/themes/j1/core/css/themes/{uno-light → unolight}/bootstrap.css +326 -18
- data/assets/themes/j1/core/css/themes/{uno-light → unolight}/bootstrap.min.css +1 -1
- data/assets/themes/j1/core/js/template.js +143 -65
- data/assets/themes/j1/core/js/template.min.js +5 -5
- data/assets/themes/j1/core/js/template.min.js.map +1 -1
- data/assets/themes/j1/modules/bmd/js/bmd.js +3 -3
- data/assets/themes/j1/modules/bmd/js/bmd.min.js +1 -1
- data/assets/themes/j1/modules/cryptoJS/js/aes.js +35 -0
- data/assets/themes/j1/modules/cryptoJS/js/aes.min.js +35 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-md5.js +21 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-ripemd160.js +31 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha1.js +17 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha224.js +19 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha256.js +18 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha3.js +21 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha384.js +27 -0
- data/assets/themes/j1/modules/cryptoJS/js/hmac-sha512.js +25 -0
- data/assets/themes/j1/modules/cryptoJS/js/md5.js +19 -0
- data/assets/themes/j1/modules/cryptoJS/js/pbkdf2.js +19 -0
- data/assets/themes/j1/modules/cryptoJS/js/rabbit-legacy.js +36 -0
- data/assets/themes/j1/modules/cryptoJS/js/rabbit.js +36 -0
- data/assets/themes/j1/modules/cryptoJS/js/rc4.js +33 -0
- data/assets/themes/j1/modules/cryptoJS/js/ripemd160.js +29 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha1.js +15 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha224.js +17 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha256.js +16 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha3.js +19 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha384.js +25 -0
- data/assets/themes/j1/modules/cryptoJS/js/sha512.js +23 -0
- data/assets/themes/j1/modules/cryptoJS/js/tripledes.js +51 -0
- data/assets/themes/j1/modules/deeplAPI/js/deeplAPI.2.js +460 -0
- data/assets/themes/j1/modules/deeplAPI/js/deeplAPI.js +379 -353
- data/assets/themes/j1/modules/deeplAPI/js/deeplAPI.min.js +1 -1
- data/assets/themes/j1/modules/gtag-opt-in/js/gtag-opt-in.js +93 -1
- data/assets/themes/j1/modules/materialize/js/autocomplete.js +1 -1
- data/assets/themes/j1/modules/materialize/js/bin/materialize.js +4 -4
- data/assets/themes/j1/modules/materialize/js/bin/materialize.min.js +1 -1
- data/assets/themes/j1/modules/materialize/js/global.js +1 -1
- data/assets/themes/j1/modules/materialize/js/select.js +1 -1
- data/assets/themes/j1/modules/materialize/js/tapTarget.cash.js +1 -1
- data/assets/themes/j1/modules/scroller/js/scroller.js +6 -6
- data/assets/themes/j1/modules/scroller/js/scroller.min.js +1 -1
- data/assets/themes/j1/modules/twemoji/js/picker/twemoji-picker.js +2 -2
- data/assets/themes/j1/modules/twemoji/js/picker/twemoji-picker.min.js +1 -1
- data/exe/j1 +6 -7
- data/lib/j1/commands/generate.rb +15 -16
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/Gemfile +7 -1
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/_defaults/j1_config.yml +1 -1
- data/lib/starter_web/_data/_defaults/private.yml +3 -2
- data/lib/starter_web/_data/_defaults/resources.yml +1 -1
- data/lib/starter_web/_data/blocks/banner.yml +5 -5
- data/lib/starter_web/_data/blocks/defaults/banner.yml +5 -5
- data/lib/starter_web/_data/blocks/defaults/panel.yml +3 -3
- data/lib/starter_web/_data/builder/defaults/blog_navigator.yml +50 -44
- data/lib/starter_web/_data/j1_config.yml +2 -2
- data/lib/starter_web/_data/modules/defaults/attics.yml +1 -1
- data/lib/starter_web/_data/modules/defaults/navigator.yml +31 -11
- data/lib/starter_web/_data/modules/translator.yml +3 -3
- data/lib/starter_web/_data/private.yml +3 -2
- data/lib/starter_web/_data/resources.yml +28 -3
- data/lib/starter_web/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/_plugins/encodeBase64.rb +46 -0
- data/lib/starter_web/_plugins/encryptAES.rb +53 -0
- data/lib/starter_web/_plugins/filters.rb +2 -1
- data/lib/starter_web/_plugins/lunr_index.rb +1 -1
- data/lib/starter_web/_plugins/minifyJSON.rb +2 -2
- data/lib/starter_web/assets/images/pages/roundtrip/500_themes/themes-menu-1280x800.jpg +0 -0
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/_test_pages/100_side-bar-tester.adoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_bottom_info.asciidoc +3 -3
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_bottom_left_warning.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_bottom_right_danger.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_central_success.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_full_height_left_info.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_full_height_right_success.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_top_info.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_top_left_info.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/410_top_right_success.asciidoc +1 -1
- data/lib/starter_web/pages/_test_pages/_includes/documents/419_advanced_modals_demo.asciidoc +22 -22
- data/lib/starter_web/pages/_test_pages/accordion-01-tester.adoc +3 -3
- data/lib/starter_web/pages/_test_pages/accordion-02-tester.adoc +3 -3
- data/lib/starter_web/pages/_test_pages/accordion-03-tester.adoc +4 -4
- data/lib/starter_web/pages/_test_pages/backdrop-tester.adoc +3 -3
- data/lib/starter_web/pages/_test_pages/button-tester-1.adoc +2 -2
- data/lib/starter_web/pages/_test_pages/cookieConsent.adoc +1 -1
- data/lib/starter_web/pages/_test_pages/infinite-scroll-tester.adoc +3 -3
- data/lib/starter_web/pages/public/asciidoc_skeletons/documentation/documentation.adoc +1 -1
- data/lib/starter_web/pages/public/asciidoc_skeletons/multi-document/multi.adoc +1 -1
- data/lib/starter_web/pages/public/asciidoc_skeletons/simple-document/simple.adoc +1 -1
- data/lib/starter_web/pages/public/blog/navigator/archive/categoryview.html +0 -21
- data/lib/starter_web/pages/public/blog/navigator/archive/dateview.html +1 -1
- data/lib/starter_web/pages/public/blog/navigator/archive/tagview.html +1 -0
- data/lib/starter_web/pages/public/blog/navigator/archive.html +1 -1
- data/lib/starter_web/pages/public/learn/quickstart.adoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/200_typography.adoc +4 -5
- data/lib/starter_web/pages/public/learn/roundtrip/410_bs_modals_extentions.adoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/500_themes.adoc +2 -2
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_bottom_info.asciidoc +3 -3
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_bottom_left_warning.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_bottom_right_danger.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_central_success.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_full_height_left_info.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_full_height_right_success.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_top_info.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_top_left_info.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/410_top_right_success.asciidoc +1 -1
- data/lib/starter_web/pages/public/learn/roundtrip/_includes/documents/419_advanced_modals_demo.asciidoc +51 -51
- data/lib/starter_web/pages/public/learn/where_to_go.adoc +1 -1
- data/lib/starter_web/pages/public/legal/de/100_copyright.adoc +1 -1
- data/lib/starter_web/pages/public/legal/de/100_impress.adoc +1 -1
- data/lib/starter_web/pages/public/legal/de/300_privacy.adoc +5 -5
- data/lib/starter_web/pages/public/legal/de/400_comment_policy.adoc +1 -1
- data/lib/starter_web/pages/public/legal/en/100_copyright.adoc +1 -1
- data/lib/starter_web/pages/public/legal/en/200_impress.adoc +1 -1
- data/lib/starter_web/pages/public/legal/en/300_privacy.adoc +4 -5
- data/lib/starter_web/pages/public/legal/en/400_comment_policy.adoc +1 -1
- data/lib/starter_web/pages/public/panels/intro_panel/_includes/attributes.asciidoc +55 -0
- data/lib/starter_web/pages/public/panels/intro_panel/panel.adoc +51 -3
- data/lib/starter_web/pages/public/previewer/preview_bootstrap_theme.adoc +163 -73
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +34 -9
- data/lib/j1/commands/help.rb +0 -32
- data/lib/j1/commands/module.rb +0 -69
@@ -21,393 +21,419 @@
|
|
21
21
|
// properly.
|
22
22
|
//
|
23
23
|
;(function($, window, document, undefined) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
var dependencies_met_page_ready = setInterval (function () {
|
91
|
-
if (typeof auth_key !== 'undefined' ) {
|
92
|
-
settings.auth_key = auth_key;
|
93
|
-
_this.translate(settings);
|
94
|
-
logger.info('\n' + 'translation: in progress');
|
95
|
-
clearInterval(dependencies_met_page_ready);
|
96
|
-
}
|
97
|
-
});
|
98
|
-
},
|
99
|
-
|
100
|
-
// -----------------------------------------------------------------------
|
101
|
-
// prepareXHR
|
102
|
-
// Prepare a XHR request according to DeepL API specification
|
103
|
-
// for the required HTTP header settings
|
104
|
-
// See: https://www.deepl.com/de/docs-api/simulator/
|
105
|
-
// -----------------------------------------------------------------------
|
106
|
-
// NOTE: "User-Agent" NOT used as the use is qualified UNSECURE
|
107
|
-
// -----------------------------------------------------------------------
|
108
|
-
prepareXHR: function (settings) {
|
109
|
-
if (settings.api === 'free') {
|
110
|
-
this.xhr.open("POST", "https://api-free.deepl.com/v2/translate", true);
|
111
|
-
} else if (settings.api === 'pro') {
|
112
|
-
this.xhr.open("POST", "https://api.deepl.com/v2/translate", true);
|
113
|
-
} else {
|
114
|
-
this.xhr.open("POST", "https://api-free.deepl.com/v2/translate", true);
|
24
|
+
'use strict';
|
25
|
+
|
26
|
+
// Create the defaults
|
27
|
+
var pluginName = 'deeplAPI',
|
28
|
+
defaults = {
|
29
|
+
api: 'free', // free (default) | pro
|
30
|
+
auth_key: '', // API authorization key
|
31
|
+
source_lang: 'auto', // autodetection (default: auto)|supported language. Specifies the language for the input text.
|
32
|
+
target_lang: 'DE', // language to be tranlasted in.
|
33
|
+
max_chars: false, // false (unlimited) or number. Number of chars from the source text passed for translation.
|
34
|
+
split_sentences: '1', // enabled (1, default)|disabled (0)|nonewlines. Sets the translation engine to first split the input text into sentences.
|
35
|
+
preserve_formatting: '0', // disabled (0, default)|enabled (1). Sets the translation engine to respect the original formatting.
|
36
|
+
formality: 'default', // default|more|less. Sets the translated text should lean towards formal or informal language.
|
37
|
+
tag_handling: false, // false (value=0)|xml. Sets which kind of tags should be handled. If set, API is able to process structured XML content.
|
38
|
+
outline_detection: true, // false (value=0) or true (NO value passed). Controls the automatic mechanism on XML tags for splitting. If disabled, all splitting_tags are to be specified.
|
39
|
+
non_splitting_tags: false, // false or comma-separated list of XML tags. Disable automated splitting on the tags specified.
|
40
|
+
splitting_tags: false, // false or comma-separated list of XML tags which always cause splitting.
|
41
|
+
ignore_tags: false, // false or comma-separated list of XML tags that indicate text NOT to be translated.
|
42
|
+
onInit: function (){}, // callback after plugin has initialized.
|
43
|
+
onBeforeTranslation: function (){}, // callback before translation started.
|
44
|
+
onAfterTranslation: function (){} // callback after translation finished.
|
45
|
+
};
|
46
|
+
|
47
|
+
// -------------------------------------------------------------------------
|
48
|
+
// plugin constructor
|
49
|
+
// create the jquery plugin
|
50
|
+
// -------------------------------------------------------------------------
|
51
|
+
function Plugin (element, options) {
|
52
|
+
this.element = element;
|
53
|
+
this.settings = $.extend( {}, defaults, options);
|
54
|
+
this.settings.elementID = '#' + this.element.id;
|
55
|
+
this.xhr = new XMLHttpRequest();
|
56
|
+
|
57
|
+
// call the plugin initializer
|
58
|
+
this.init(this.settings);
|
59
|
+
}
|
60
|
+
|
61
|
+
// Avoid plugin prototype conflicts
|
62
|
+
$.extend(Plugin.prototype, {
|
63
|
+
// -----------------------------------------------------------------------
|
64
|
+
// init()
|
65
|
+
// initialize|run the translation
|
66
|
+
// -----------------------------------------------------------------------
|
67
|
+
init: function(options) {
|
68
|
+
var _this = this;
|
69
|
+
var logger = log4javascript.getLogger('deeplAPI.init');
|
70
|
+
var data_url = '/assets/data/private.json';
|
71
|
+
var settings = options;
|
72
|
+
var auth_key;
|
73
|
+
var encodedString;
|
74
|
+
var encryptedString;
|
75
|
+
var jsonObject;
|
76
|
+
|
77
|
+
logger.info('\n' + 'initialize: started');
|
78
|
+
|
79
|
+
// loading private data (auth key)
|
80
|
+
$.ajax({
|
81
|
+
url: data_url,
|
82
|
+
dataType: 'text',
|
83
|
+
success: function (data) {
|
84
|
+
encodedString = atob(data);
|
85
|
+
jsonObject = JSON.parse(encodedString);
|
86
|
+
auth_key = jsonObject.translators.deepl.auth_key;
|
87
|
+
},
|
88
|
+
error: function (jqXHR, textStatus, errorThrown) {
|
89
|
+
logger.error('\n' + 'failed to retrieve JSON data from: ' + data_url);
|
115
90
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
// would have otherwise been lost because of the way DeepL accepts
|
127
|
-
// multiple sentences.
|
128
|
-
// -----------------------------------------------------------------------
|
129
|
-
prepareText: function (source_text) {
|
130
|
-
return source_text.split("\n");
|
131
|
-
},
|
132
|
-
|
133
|
-
// -----------------------------------------------------------------------
|
134
|
-
// translate
|
135
|
-
// Translate text function which uses all the other modules, in order to
|
136
|
-
// create a request, which is sent to the DeepL API to translate, and
|
137
|
-
// then display the result, designed as a module.
|
138
|
-
// -----------------------------------------------------------------------
|
139
|
-
translate: function (settings) {
|
140
|
-
const logger = log4javascript.getLogger('deeplAPI.translate');
|
141
|
-
const READYSTATE_DONE = 4;
|
142
|
-
const STATUS_OK = 200;
|
143
|
-
const SUPPORTED_LANG = ['BG', 'CS', 'DA', 'DE', 'EL', 'EN-GB', 'EN-US', 'EN', 'ES', 'ET', 'FI', 'FR', 'HU', 'IT', 'JA', 'LT', 'LV', 'NL', 'PL', 'PT-PT', 'PT-BR', 'PT', 'RO', 'RU', 'SK', 'SL', 'SV', 'ZH'];
|
144
|
-
const ALLOWED_FORMALITY_LANG = ['DE', 'FR', 'IT', 'ES', 'NL', 'PL', 'PT', 'PT-BR', 'RU'];
|
145
|
-
const ALLOWED_TAG_HANDLING = ['xml'];
|
146
|
-
const TARGET_ELEMENT = settings.targetElement;
|
147
|
-
const TARGET_ELEMENT_EXISTS = $(TARGET_ELEMENT).length;
|
148
|
-
const ERROR_TEXT = 'Translation failed.' + '\n' + 'Reason: ';
|
149
|
-
const WARNING_TEXT = 'Translation skipped.' + '\n' + 'Reason: ';
|
150
|
-
|
151
|
-
var BASE_TARGET_ELEMENT;
|
152
|
-
var ELEMENT_TYPE;
|
153
|
-
var SOURCE_TEXT_FOUND;
|
154
|
-
|
155
|
-
var API_RESPONSE = {};
|
156
|
-
API_RESPONSE['400'] = 'Bad request. Please check error message and your parameters.';
|
157
|
-
API_RESPONSE['401'] = 'Authorization failed. Please supply a valid DeepL-Auth-Key.';
|
158
|
-
API_RESPONSE['403'] = 'Forbidden. The access to the requested resource is denied, because of insufficient access rights.';
|
159
|
-
API_RESPONSE['404'] = 'The requested resource could not be found.';
|
160
|
-
API_RESPONSE['413'] = 'The request size exceeds the limit.';
|
161
|
-
API_RESPONSE['415'] = 'The requested entries format specified in the Accept header is not supported.';
|
162
|
-
API_RESPONSE['429'] = 'Too many requests. Please wait and resend your request.';
|
163
|
-
API_RESPONSE['456'] = 'Quota exceeded. The maximum amount of glossaries has been reached.';
|
164
|
-
API_RESPONSE['500'] = 'Internal server error';
|
165
|
-
API_RESPONSE['503'] = 'Resource currently unavailable. Try again later.';
|
166
|
-
API_RESPONSE['529'] = 'Too many requests. Please wait and resend your request.';
|
167
|
-
|
168
|
-
var reason_text;
|
169
|
-
var request = '';
|
170
|
-
var element = '';
|
171
|
-
var source_text = '';
|
172
|
-
var source_text_lines = '';
|
173
|
-
var source_lang;
|
174
|
-
var target_lang;
|
175
|
-
|
176
|
-
// check if passed HTML element or ID exists
|
177
|
-
if (TARGET_ELEMENT_EXISTS) {
|
178
|
-
BASE_TARGET_ELEMENT = (TARGET_ELEMENT.includes('.')||TARGET_ELEMENT.includes('#')) ? TARGET_ELEMENT.substring(1) : TARGET_ELEMENT;
|
179
|
-
ELEMENT_TYPE = $(TARGET_ELEMENT).get(0).nodeName;
|
180
|
-
|
181
|
-
// Read the text to be translated from the given HTML element
|
182
|
-
if (ELEMENT_TYPE === 'TEXTAREA') {
|
183
|
-
source_text = this.element.value;
|
184
|
-
} else if (ELEMENT_TYPE === 'P') {
|
185
|
-
element = this.element;
|
186
|
-
source_text = $(TARGET_ELEMENT).text();
|
187
|
-
}
|
188
|
-
SOURCE_TEXT_FOUND = source_text.length;
|
189
|
-
} else {
|
190
|
-
logger.error('\n' + 'target element does not exists: ' + TARGET_ELEMENT);
|
191
|
-
return false;
|
91
|
+
});
|
92
|
+
|
93
|
+
// run the translation (if private data loaded)
|
94
|
+
var dependencies_met_page_ready = setInterval (function () {
|
95
|
+
if (typeof auth_key !== 'undefined' ) {
|
96
|
+
settings.auth_key = auth_key;
|
97
|
+
_this.translate(settings);
|
98
|
+
logger.info('\n' + 'initialize: finished');
|
99
|
+
logger.info('\n' + 'translate: started');
|
100
|
+
clearInterval(dependencies_met_page_ready);
|
192
101
|
}
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
102
|
+
});
|
103
|
+
},
|
104
|
+
|
105
|
+
// decryptData: function (message = '', key = '', iv = '') {
|
106
|
+
// var test_key_32 = "2e35f242a46d67eeb74aabc37d5e5d05";
|
107
|
+
// var data = CryptoJS.AES.encrypt("Message", test_key_32); // Encryption Part
|
108
|
+
// var decrypted = CryptoJS.AES.decrypt(data, test_key_32).toString(CryptoJS.enc.Utf8);
|
109
|
+
//
|
110
|
+
// // Decode the base64 data so we can separate iv and crypt text.
|
111
|
+
// var rawData = atob(message);
|
112
|
+
// var iv = rawData.substring(0,16);
|
113
|
+
// var crypttext = rawData.substring(16);
|
114
|
+
//
|
115
|
+
// // Decrypt...
|
116
|
+
// var plaintextArray = CryptoJS.AES.decrypt(
|
117
|
+
// { ciphertext: CryptoJS.enc.Latin1.parse(crypttext) },
|
118
|
+
// CryptoJS.enc.Hex.parse(key),
|
119
|
+
// { iv: CryptoJS.enc.Latin1.parse(iv) }
|
120
|
+
// );
|
121
|
+
//
|
122
|
+
// var decrypted = CryptoJS.enc.Latin1.stringify(plaintextArray);
|
123
|
+
// return decrypted;
|
124
|
+
// },
|
125
|
+
|
126
|
+
// -----------------------------------------------------------------------
|
127
|
+
// prepareXHR
|
128
|
+
// Prepare a XHR request according to DeepL API specification
|
129
|
+
// for the required HTTP header settings
|
130
|
+
// See: https://www.deepl.com/de/docs-api/simulator/
|
131
|
+
// -----------------------------------------------------------------------
|
132
|
+
// NOTE: "User-Agent" NOT used as the use is qualified UNSECURE
|
133
|
+
// -----------------------------------------------------------------------
|
134
|
+
prepareXHR: function (settings) {
|
135
|
+
if (settings.api === 'free') {
|
136
|
+
this.xhr.open("POST", "https://api-free.deepl.com/v2/translate", true);
|
137
|
+
} else if (settings.api === 'pro') {
|
138
|
+
this.xhr.open("POST", "https://api.deepl.com/v2/translate", true);
|
139
|
+
} else {
|
140
|
+
this.xhr.open("POST", "https://api-free.deepl.com/v2/translate", true);
|
141
|
+
}
|
142
|
+
// Set required header parameters
|
143
|
+
this.xhr.setRequestHeader("Accept", "*/*");
|
144
|
+
this.xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
145
|
+
},
|
146
|
+
|
147
|
+
// -----------------------------------------------------------------------
|
148
|
+
// prepareText
|
149
|
+
// Prepare text function used to parse, or arrange text, designed as
|
150
|
+
// a module. Currently it splits all text whenever a newline ("\n")
|
151
|
+
// is met, so that it preserves the original layout of the text, which
|
152
|
+
// would have otherwise been lost because of the way DeepL accepts
|
153
|
+
// multiple sentences.
|
154
|
+
// -----------------------------------------------------------------------
|
155
|
+
prepareText: function (source_text) {
|
156
|
+
return source_text.split("\n");
|
157
|
+
},
|
158
|
+
|
159
|
+
// -----------------------------------------------------------------------
|
160
|
+
// translate
|
161
|
+
// Translate text function which uses all the other modules, in order to
|
162
|
+
// create a request, which is sent to the DeepL API to translate, and
|
163
|
+
// then display the result, designed as a module.
|
164
|
+
// -----------------------------------------------------------------------
|
165
|
+
translate: function (settings) {
|
166
|
+
const logger = log4javascript.getLogger('deeplAPI.translate');
|
167
|
+
const READYSTATE_DONE = 4;
|
168
|
+
const STATUS_OK = 200;
|
169
|
+
const SUPPORTED_LANG = ['BG', 'CS', 'DA', 'DE', 'EL', 'EN-GB', 'EN-US', 'EN', 'ES', 'ET', 'FI', 'FR', 'HU', 'IT', 'JA', 'LT', 'LV', 'NL', 'PL', 'PT-PT', 'PT-BR', 'PT', 'RO', 'RU', 'SK', 'SL', 'SV', 'ZH'];
|
170
|
+
const ALLOWED_FORMALITY_LANG = ['DE', 'FR', 'IT', 'ES', 'NL', 'PL', 'PT', 'PT-BR', 'RU'];
|
171
|
+
const ALLOWED_TAG_HANDLING = ['xml'];
|
172
|
+
const TARGET_ELEMENT = settings.targetElement;
|
173
|
+
const TARGET_ELEMENT_EXISTS = $(TARGET_ELEMENT).length;
|
174
|
+
const ERROR_TEXT = 'Translation failed.' + '\n' + 'Reason: ';
|
175
|
+
const WARNING_TEXT = 'Translation skipped.' + '\n' + 'Reason: ';
|
176
|
+
|
177
|
+
var BASE_TARGET_ELEMENT;
|
178
|
+
var ELEMENT_TYPE;
|
179
|
+
var SOURCE_TEXT_FOUND;
|
180
|
+
|
181
|
+
var API_RESPONSE = {};
|
182
|
+
API_RESPONSE['400'] = 'Bad request. Please check error message and your parameters.';
|
183
|
+
API_RESPONSE['401'] = 'Authorization failed. Please supply a valid DeepL-Auth-Key.';
|
184
|
+
API_RESPONSE['403'] = 'Forbidden. The access to the requested resource is denied, because of insufficient access rights.';
|
185
|
+
API_RESPONSE['404'] = 'The requested resource could not be found.';
|
186
|
+
API_RESPONSE['413'] = 'The request size exceeds the limit.';
|
187
|
+
API_RESPONSE['415'] = 'The requested entries format specified in the Accept header is not supported.';
|
188
|
+
API_RESPONSE['429'] = 'Too many requests. Please wait and resend your request.';
|
189
|
+
API_RESPONSE['456'] = 'Quota exceeded. The maximum amount of glossaries has been reached.';
|
190
|
+
API_RESPONSE['500'] = 'Internal server error';
|
191
|
+
API_RESPONSE['503'] = 'Resource currently unavailable. Try again later.';
|
192
|
+
API_RESPONSE['529'] = 'Too many requests. Please wait and resend your request.';
|
193
|
+
|
194
|
+
var reason_text;
|
195
|
+
var request = '';
|
196
|
+
var element = '';
|
197
|
+
var source_text = '';
|
198
|
+
var source_text_lines = '';
|
199
|
+
var source_lang;
|
200
|
+
var target_lang;
|
201
|
+
|
202
|
+
// check if passed HTML element or ID exists
|
203
|
+
if (TARGET_ELEMENT_EXISTS) {
|
204
|
+
BASE_TARGET_ELEMENT = (TARGET_ELEMENT.includes('.')||TARGET_ELEMENT.includes('#')) ? TARGET_ELEMENT.substring(1) : TARGET_ELEMENT;
|
205
|
+
ELEMENT_TYPE = $(TARGET_ELEMENT).get(0).nodeName;
|
206
|
+
|
207
|
+
// Read the text to be translated from the given HTML element
|
208
|
+
if (ELEMENT_TYPE === 'TEXTAREA') {
|
209
|
+
source_text = this.element.value;
|
210
|
+
} else if (ELEMENT_TYPE === 'P') {
|
211
|
+
element = this.element;
|
212
|
+
source_text = $(TARGET_ELEMENT).text();
|
199
213
|
}
|
200
|
-
|
214
|
+
SOURCE_TEXT_FOUND = source_text.length;
|
215
|
+
} else {
|
216
|
+
logger.error('\n' + 'target element does not exists: ' + TARGET_ELEMENT);
|
217
|
+
return false;
|
218
|
+
}
|
219
|
+
|
220
|
+
// limit the source text if required
|
221
|
+
if (settings.max_char && source_text.length > settings.max_char ) {
|
222
|
+
var source_text_limited = source_text.substring(0, settings.max_char -3);
|
223
|
+
source_text = source_text_limited + ' ...';
|
224
|
+
logger.info('\n' + 'limit for source text ' + '(max: ' + settings.max_char + ')' + ' reached: ' + source_text.length);
|
225
|
+
}
|
226
|
+
source_text_lines = this.prepareText(source_text);
|
201
227
|
|
202
|
-
|
203
|
-
|
228
|
+
// prepare the XHR request for the API (free/pro) requested
|
229
|
+
this.prepareXHR(settings);
|
204
230
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
231
|
+
// Makes a request with every line, as a new text to translate
|
232
|
+
var source_text_request = "";
|
233
|
+
for(var i = 0; i < source_text_lines.length; i++) {
|
234
|
+
source_text_request += "&text=" + source_text_lines[i];
|
235
|
+
}
|
210
236
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
}
|
223
|
-
logger.info('\n' + 'translation: finished');
|
224
|
-
|
225
|
-
// update the HTM element (content) by the tranlation
|
226
|
-
if (ELEMENT_TYPE === 'TEXTAREA') {
|
227
|
-
$(TARGET_ELEMENT).val(translated_text);
|
228
|
-
} else if (ELEMENT_TYPE === 'P') {
|
229
|
-
$(TARGET_ELEMENT).text(translated_text);
|
230
|
-
}
|
231
|
-
} else {
|
232
|
-
logger.error('\n' + 'API returned ' + this.status + ': ' + API_RESPONSE[this.status]);
|
237
|
+
this.xhr.onload = function () {
|
238
|
+
if (this.readyState === READYSTATE_DONE) {
|
239
|
+
if (this.status === STATUS_OK) {
|
240
|
+
// JSON parse the response
|
241
|
+
var result = JSON.parse(this.responseText);
|
242
|
+
|
243
|
+
// recreate the response as one text to keep its original layout
|
244
|
+
var translated_text = "";
|
245
|
+
for(var i = 0; i < result.translations.length; i++) {
|
246
|
+
translated_text += result.translations[i].text;
|
247
|
+
translated_text += "\n";
|
233
248
|
}
|
249
|
+
logger.info('\n' + 'translation: finished');
|
250
|
+
|
251
|
+
// update the HTM element (content) by the tranlation
|
252
|
+
if (ELEMENT_TYPE === 'TEXTAREA') {
|
253
|
+
$(TARGET_ELEMENT).val(translated_text);
|
254
|
+
} else if (ELEMENT_TYPE === 'P') {
|
255
|
+
$(TARGET_ELEMENT).text(translated_text);
|
256
|
+
}
|
257
|
+
} else {
|
258
|
+
logger.error('\n' + 'API returned ' + this.status + ': ' + API_RESPONSE[this.status]);
|
234
259
|
}
|
235
|
-
}
|
260
|
+
}
|
261
|
+
};
|
236
262
|
|
237
|
-
|
238
|
-
|
239
|
-
|
263
|
+
// ---------------------------------------------------------------------
|
264
|
+
// preflight (validity check) on given parameters
|
265
|
+
// ---------------------------------------------------------------------
|
240
266
|
|
241
|
-
|
242
|
-
|
243
|
-
|
267
|
+
// Check for SUPPORTED language by option source_lang|target_lang
|
268
|
+
source_lang = this.settings.source_lang;
|
269
|
+
target_lang = this.settings.target_lang;
|
244
270
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
271
|
+
if (this.settings.source_lang !== 'auto') {
|
272
|
+
this.settings.source_lang = (SUPPORTED_LANG.indexOf(this.settings.source_lang) > -1) ? this.settings.source_lang : false;
|
273
|
+
}
|
274
|
+
this.settings.target_lang = (SUPPORTED_LANG.indexOf(this.settings.target_lang) > -1) ? this.settings.target_lang : false;
|
249
275
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
276
|
+
// stop processing if invalid language or NO AUTH key passed
|
277
|
+
if (!this.settings.auth_key || !this.settings.source_lang || !this.settings.target_lang) {
|
278
|
+
if (!this.settings.auth_key) {
|
279
|
+
reason_text = 'NO AUTH key passed.';
|
280
|
+
logger.error('\n' + 'invalid option found. ' + reason_text);
|
281
|
+
}
|
282
|
+
if (!this.settings.source_lang) {
|
283
|
+
reason_text = 'WRONG source language passed: ' + source_lang;
|
284
|
+
logger.error('\n' + 'invalid option found. ' + reason_text);
|
285
|
+
}
|
286
|
+
if (!this.settings.target_lang) {
|
287
|
+
reason_text = 'WRONG target language passed: ' + target_lang;
|
288
|
+
logger.error('\n' + 'invalid option found. ' + reason_text);
|
289
|
+
}
|
264
290
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
}
|
271
|
-
return false;
|
291
|
+
// update the HTML element (content) by an error text
|
292
|
+
if (ELEMENT_TYPE === 'TEXTAREA') {
|
293
|
+
$(TARGET_ELEMENT).val(ERROR_TEXT + reason_text);
|
294
|
+
} else if (ELEMENT_TYPE === 'P') {
|
295
|
+
$(TARGET_ELEMENT).text(ERROR_TEXT + reason_text);
|
272
296
|
}
|
297
|
+
return false;
|
298
|
+
}
|
273
299
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
}
|
282
|
-
logger.warn('\n' + 'no text found for translation');
|
283
|
-
return false;
|
300
|
+
if(!SOURCE_TEXT_FOUND) {
|
301
|
+
reason_text = 'NO text found for translation';
|
302
|
+
// update the HTML element (content) by an error text
|
303
|
+
if (ELEMENT_TYPE === 'TEXTAREA') {
|
304
|
+
$(TARGET_ELEMENT).val(WARNING_TEXT + reason_text);
|
305
|
+
} else if (ELEMENT_TYPE === 'P') {
|
306
|
+
$(TARGET_ELEMENT).text(WARNING_TEXT + reason_text);
|
284
307
|
}
|
308
|
+
logger.warn('\n' + 'no text found for translation');
|
309
|
+
return false;
|
310
|
+
}
|
285
311
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
}
|
291
|
-
this.settings.formality = (ALLOWED_FORMALITY_LANG.indexOf(this.settings.target_lang) > -1) ? this.settings.formality : 'default';
|
312
|
+
// Check for VALID language supported by option 'formality'
|
313
|
+
if (this.settings.formality !== 'default' ) {
|
314
|
+
if (!(ALLOWED_FORMALITY_LANG.indexOf(this.settings.target_lang) > -1)) {
|
315
|
+
logger.warn('\n' + 'wrong language found for formality setting: ' + this.settings.target_lang);
|
292
316
|
}
|
317
|
+
this.settings.formality = (ALLOWED_FORMALITY_LANG.indexOf(this.settings.target_lang) > -1) ? this.settings.formality : 'default';
|
318
|
+
}
|
293
319
|
|
294
|
-
|
320
|
+
// Check for VALID tag handling and options
|
321
|
+
if (this.settings.tag_handling) {
|
322
|
+
var tag_handling = this.settings.tag_handling;
|
323
|
+
// check for VALID method
|
324
|
+
this.settings.tag_handling = (ALLOWED_TAG_HANDLING.indexOf(this.settings.tag_handling) > -1) ? this.settings.tag_handling : false;
|
295
325
|
if (this.settings.tag_handling) {
|
296
|
-
|
297
|
-
|
298
|
-
this.settings.
|
299
|
-
if (this.settings.tag_handling) {
|
300
|
-
this.settings.non_splitting_tags = this.settings.non_splitting_tags ? encodeURIComponent(this.settings.non_splitting_tags) : false;
|
301
|
-
this.settings.splitting_tags = this.settings.splitting_tags ? encodeURIComponent(this.settings.splitting_tags) : false;
|
302
|
-
this.settings.ignore_tags = this.settings.ignore_tags ? encodeURIComponent(this.settings.ignore_tags) : false;
|
303
|
-
} else {
|
304
|
-
logger.error('\n' + 'invalid option found for tag handling : ' + tag_handling);
|
305
|
-
logger.warn('\n' + 'disable option: ' + 'tag_handling');
|
306
|
-
// reset to defaults if WRONG method detected
|
307
|
-
if (this.settings.non_splitting_tags) {
|
308
|
-
logger.warn('\n' + 'disable option: ' + this.settings.non_splitting_tags);
|
309
|
-
this.settings.non_splitting_tags = false;
|
310
|
-
}
|
311
|
-
if (this.settings.splitting_tags) {
|
312
|
-
logger.warn('\n' + 'disable option : ' + this.settings.splitting_tags);
|
313
|
-
this.settings.splitting_tags = false;
|
314
|
-
}
|
315
|
-
if (this.settings.ignore_tags) {
|
316
|
-
logger.warn('\n' + 'disable option: ' + this.settings.ignore_tags);
|
317
|
-
this.settings.ignore_tags = false;
|
318
|
-
}
|
319
|
-
}
|
326
|
+
this.settings.non_splitting_tags = this.settings.non_splitting_tags ? encodeURIComponent(this.settings.non_splitting_tags) : false;
|
327
|
+
this.settings.splitting_tags = this.settings.splitting_tags ? encodeURIComponent(this.settings.splitting_tags) : false;
|
328
|
+
this.settings.ignore_tags = this.settings.ignore_tags ? encodeURIComponent(this.settings.ignore_tags) : false;
|
320
329
|
} else {
|
321
|
-
|
330
|
+
logger.error('\n' + 'invalid option found for tag handling : ' + tag_handling);
|
331
|
+
logger.warn('\n' + 'disable option: ' + 'tag_handling');
|
332
|
+
// reset to defaults if WRONG method detected
|
322
333
|
if (this.settings.non_splitting_tags) {
|
323
|
-
logger.warn('\n' + '
|
334
|
+
logger.warn('\n' + 'disable option: ' + this.settings.non_splitting_tags);
|
324
335
|
this.settings.non_splitting_tags = false;
|
325
336
|
}
|
326
337
|
if (this.settings.splitting_tags) {
|
327
|
-
logger.warn('\n' + '
|
338
|
+
logger.warn('\n' + 'disable option : ' + this.settings.splitting_tags);
|
328
339
|
this.settings.splitting_tags = false;
|
329
340
|
}
|
330
341
|
if (this.settings.ignore_tags) {
|
331
|
-
logger.warn('\n' + '
|
342
|
+
logger.warn('\n' + 'disable option: ' + this.settings.ignore_tags);
|
332
343
|
this.settings.ignore_tags = false;
|
333
344
|
}
|
334
345
|
}
|
346
|
+
} else {
|
347
|
+
// reset tags to their defaults if NO tag_handling is enabled but settings passed
|
348
|
+
if (this.settings.non_splitting_tags) {
|
349
|
+
logger.warn('\n' + 'invalid option found: ' + this.settings.non_splitting_tags);
|
350
|
+
this.settings.non_splitting_tags = false;
|
351
|
+
}
|
352
|
+
if (this.settings.splitting_tags) {
|
353
|
+
logger.warn('\n' + 'invalid option found: ' + this.settings.splitting_tags);
|
354
|
+
this.settings.splitting_tags = false;
|
355
|
+
}
|
356
|
+
if (this.settings.ignore_tags) {
|
357
|
+
logger.warn('\n' + 'invalid option found: ' + this.settings.ignore_tags);
|
358
|
+
this.settings.ignore_tags = false;
|
359
|
+
}
|
360
|
+
}
|
335
361
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
362
|
+
// ---------------------------------------------------------------------
|
363
|
+
// construct the API request body
|
364
|
+
// ---------------------------------------------------------------------
|
365
|
+
request = "auth_key=" + this.settings.auth_key;
|
366
|
+
request += (this.settings.source_lang !== 'auto' ) ? "&source_lang=" + this.settings.source_lang : '';
|
367
|
+
request += "&target_lang=" + this.settings.target_lang;
|
368
|
+
request += (this.settings.formality !== 'default' ) ? "&formality=" + this.settings.formality : '';
|
369
|
+
request += (this.settings.split_sentences) ? "&split_sentences=" + this.settings.formality : '';
|
370
|
+
request += (this.settings.tag_handling) ? "&tag_handling=" + this.settings.tag_handling : "&tag_handling=0";
|
371
|
+
request += (this.settings.tag_handling && this.settings.non_splitting_tags) ? "&non_splitting_tags=" + this.settings.non_splitting_tags : '';
|
372
|
+
request += (this.settings.tag_handling && this.settings.splitting_tags) ? "&splitting_tags=" + this.settings.splitting_tags : '';
|
373
|
+
request += (this.settings.tag_handling && this.settings.ignore_tags) ? "&ignore_tags=" + this.settings.ignore_tags : '';
|
374
|
+
request += source_text_request;
|
375
|
+
|
376
|
+
// Send the constructed request to the API for translation
|
377
|
+
this.xhr.send(request);
|
378
|
+
} // END translate
|
379
|
+
|
380
|
+
}); // END prototype
|
381
|
+
|
382
|
+
// ---------------------------------------------------------------------------
|
383
|
+
// plugin wrapper
|
384
|
+
// A really lightweight plugin wrapper around the constructor,
|
385
|
+
// wrapper around the constructor to prevent multiple instantiations
|
386
|
+
// preventing against multiple instantiations and allowing any
|
387
|
+
// public function (ie. a function whose name doesn't start
|
388
|
+
// with an underscore) to be called via the jQuery plugin,
|
389
|
+
// e.g. $(element).defaultPluginName('functionName', arg1, arg2)
|
390
|
+
// ---------------------------------------------------------------------------
|
391
|
+
$.fn[pluginName] = function ( options ) {
|
392
|
+
var args = arguments;
|
393
|
+
|
394
|
+
// Is the first parameter an object (options), or was omitted,
|
395
|
+
// instantiate a new instance of the plugin.
|
396
|
+
//
|
397
|
+
if (options === undefined || typeof options === 'object') {
|
398
|
+
return this.each(function () {
|
399
|
+
// Only allow the plugin to be instantiated once,
|
400
|
+
// so we check that the element has no plugin instantiation yet
|
401
|
+
if (!$.data(this, 'plugin_' + pluginName)) {
|
402
|
+
// if it has no instance, create a new one, pass options to the
|
403
|
+
// plugin constructor, and store the plugin instance in the
|
404
|
+
// elements jQuery data object.
|
405
|
+
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
|
406
|
+
}
|
407
|
+
});
|
408
|
+
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
|
409
|
+
// If the first parameter is a string and it doesn't start
|
410
|
+
// with an underscore or "contains" the `init`-function,
|
411
|
+
// treat this as a call to a public method.
|
412
|
+
|
413
|
+
// Cache the method call to make it possible to return a value
|
414
|
+
var returns;
|
415
|
+
|
416
|
+
this.each(function () {
|
417
|
+
var instance = $.data(this, 'plugin_' + pluginName);
|
418
|
+
|
419
|
+
// Tests that there's already a plugin-instance
|
420
|
+
// and checks that the requested public method exists
|
421
|
+
if (instance instanceof Plugin && typeof instance[options] === 'function') {
|
422
|
+
// Call the method of our plugin instance,
|
423
|
+
// and pass it the supplied arguments.
|
424
|
+
returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
|
380
425
|
}
|
381
|
-
});
|
382
|
-
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
|
383
|
-
// If the first parameter is a string and it doesn't start
|
384
|
-
// with an underscore or "contains" the `init`-function,
|
385
|
-
// treat this as a call to a public method.
|
386
|
-
|
387
|
-
// Cache the method call to make it possible to return a value
|
388
|
-
var returns;
|
389
|
-
|
390
|
-
this.each(function () {
|
391
|
-
var instance = $.data(this, 'plugin_' + pluginName);
|
392
|
-
|
393
|
-
// Tests that there's already a plugin-instance
|
394
|
-
// and checks that the requested public method exists
|
395
|
-
if (instance instanceof Plugin && typeof instance[options] === 'function') {
|
396
|
-
// Call the method of our plugin instance,
|
397
|
-
// and pass it the supplied arguments.
|
398
|
-
returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
|
399
|
-
}
|
400
426
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
427
|
+
// Allow instances to be destroyed via the 'destroy' method
|
428
|
+
if (options === 'destroy') {
|
429
|
+
$.data(this, 'plugin_' + pluginName, null);
|
430
|
+
}
|
431
|
+
});
|
406
432
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
433
|
+
// If the earlier cached method gives a value back return the value,
|
434
|
+
// otherwise return "this" to preserve chainability.
|
435
|
+
return returns !== undefined ? returns : this;
|
436
|
+
}
|
437
|
+
}; // END plugin wrapper
|
412
438
|
|
413
439
|
})(jQuery, window, document);
|