j1_template 2019.4.11 → 2019.4.12
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/layouts/_unused/layout_resource_generator.html.org +58 -0
- data/_includes/themes/j1/layouts/layout_resource_generator.html +21 -30
- data/_includes/themes/j1/procedures/layouts/_unused/resource_writer.proc.org +240 -0
- data/_includes/themes/j1/procedures/layouts/resource_writer.proc +123 -169
- data/lib/j1/version.rb +1 -1
- data/lib/starter_web/Gemfile +1 -1
- data/lib/starter_web/_cc_test_data/_config.yml +1 -1
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_categories.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_colors.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_config.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_font_sizes.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_i18n.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_resources.org.yml +0 -0
- data/lib/starter_web/_data/{_old_configs → _unused}/j1_resources.yml +0 -0
- data/lib/starter_web/assets/themes/j1/adapter/js/themer.js +21 -21
- data/lib/starter_web/assets/themes/j1/adapter/js/toccer.js +8 -8
- data/lib/starter_web/assets/themes/j1/core/js/_unused/j1.js +1835 -0
- data/lib/starter_web/assets/themes/j1/core/js/j1.js +59 -0
- data/lib/starter_web/assets/themes/j1/core/js/template.js +1 -1
- data/lib/starter_web/assets/themes/j1/core/js/template.js.map +1 -1
- data/lib/starter_web/assets/themes/j1/core/js/template.min.js +1 -1
- data/lib/starter_web/dot.gitignore +1 -0
- data/lib/starter_web/favicon.ico +0 -0
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/start/downloads/quickstarter/100_linux_starter.adoc +1 -1
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +12 -9
data/lib/j1/version.rb
CHANGED
data/lib/starter_web/Gemfile
CHANGED
@@ -48,7 +48,7 @@ gem 'jekyll', '~> 3.8.5'
|
|
48
48
|
|
49
49
|
# Theme Rubies, default: J1 Template
|
50
50
|
#
|
51
|
-
gem 'j1_template', '~> 2019.4.
|
51
|
+
gem 'j1_template', '~> 2019.4.12'
|
52
52
|
|
53
53
|
# ------------------------------------------------------------------------------
|
54
54
|
# PRODUCTION: Gem needed for the Jekyll and J1 prod environment
|
data/lib/starter_web/_config.yml
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -268,33 +268,33 @@ j1.adapter['themer'] = (function (j1, window) {
|
|
268
268
|
// -------------------------------------------------------------------------
|
269
269
|
setCss: function () {
|
270
270
|
var bg_primary = j1.getStyleValue('bg-primary', 'background-color');
|
271
|
+
|
271
272
|
// var admonitionblock_note_color = j1.getStyleValue('icon-note', 'color');
|
272
273
|
// var admonitionblock_tip_color = j1.getStyleValue('icon-tip', 'color');
|
273
274
|
// var admonitionblock_important_color = j1.getStyleValue('icon-important', 'color');
|
274
275
|
// var admonitionblock_warning_color = j1.getStyleValue('icon-warning', 'color');
|
275
276
|
// var admonitionblock_caution_color = j1.getStyleValue('icon-caution', 'color');
|
276
277
|
|
277
|
-
var admonitionblock_note_color = j1.getStyleValue('btn-info', 'background-color');
|
278
|
-
var admonitionblock_tip_color = j1.getStyleValue('btn-success', 'background-color');
|
279
|
-
var admonitionblock_important_color = j1.getStyleValue('btn-warning', 'background-color');
|
280
|
-
var admonitionblock_warning_color = j1.getStyleValue('icon-warning', 'color');
|
281
|
-
var admonitionblock_caution_color = j1.getStyleValue('btn-danger', 'background-color');
|
282
|
-
|
283
|
-
var tabs_pills_link_color_active = j1.setColorData('md_blue'); // j1.getStyleValue('btn-info', 'background-color');
|
284
|
-
var tabs_pills_link_color_hover = j1.setColorData('md_gray_300'); // j1.getStyleValue('btn-secondary', 'background-color');
|
285
|
-
|
286
|
-
$('head').append('<style>.g-bg-primary { background-color: ' +bg_primary+ ' !important; }</style>');
|
287
|
-
$('head').append('<style>.mdi-md-bg-primary { color: ' +bg_primary+ '; }</style>');
|
288
|
-
|
289
|
-
$('head').append('<style>.nav-link:hover { background-color: ' +tabs_pills_link_color_hover+ ' !important; }</style>');
|
290
|
-
$('head').append('<style>.nav-link.active { background-color: ' +tabs_pills_link_color_active+ ' !important; }</style>');
|
291
|
-
|
292
|
-
$('head').append('<style>.icon-note { color: ' +admonitionblock_note_color+ ' !important; }</style>');
|
293
|
-
$('head').append('<style>.icon-tip { color: ' +admonitionblock_tip_color+ ' !important; }</style>');
|
294
|
-
$('head').append('<style>.icon-important { color: ' +admonitionblock_important_color+ ' !important; }</style>');
|
295
|
-
$('head').append('<style>.icon-warning { color: ' +admonitionblock_warning_color+ ' !important; }</style>');
|
296
|
-
$('head').append('<style>.icon-caution { color: ' +admonitionblock_caution_color+ ' !important; }</style>');
|
297
|
-
|
278
|
+
// var admonitionblock_note_color = j1.getStyleValue('btn-info', 'background-color');
|
279
|
+
// var admonitionblock_tip_color = j1.getStyleValue('btn-success', 'background-color');
|
280
|
+
// var admonitionblock_important_color = j1.getStyleValue('btn-warning', 'background-color');
|
281
|
+
// var admonitionblock_warning_color = j1.getStyleValue('icon-warning', 'color');
|
282
|
+
// var admonitionblock_caution_color = j1.getStyleValue('btn-danger', 'background-color');
|
283
|
+
//
|
284
|
+
// var tabs_pills_link_color_active = j1.setColorData('md_blue'); // j1.getStyleValue('btn-info', 'background-color');
|
285
|
+
// var tabs_pills_link_color_hover = j1.setColorData('md_gray_300'); // j1.getStyleValue('btn-secondary', 'background-color');
|
286
|
+
//
|
287
|
+
// $('head').append('<style>.g-bg-primary { background-color: ' +bg_primary+ ' !important; }</style>');
|
288
|
+
// $('head').append('<style>.mdi-md-bg-primary { color: ' +bg_primary+ '; }</style>');
|
289
|
+
//
|
290
|
+
// $('head').append('<style>.nav-link:hover { background-color: ' +tabs_pills_link_color_hover+ ' !important; }</style>');
|
291
|
+
// $('head').append('<style>.nav-link.active { background-color: ' +tabs_pills_link_color_active+ ' !important; }</style>');
|
292
|
+
//
|
293
|
+
// $('head').append('<style>.icon-note { color: ' +admonitionblock_note_color+ ' !important; }</style>');
|
294
|
+
// $('head').append('<style>.icon-tip { color: ' +admonitionblock_tip_color+ ' !important; }</style>');
|
295
|
+
// $('head').append('<style>.icon-important { color: ' +admonitionblock_important_color+ ' !important; }</style>');
|
296
|
+
// $('head').append('<style>.icon-warning { color: ' +admonitionblock_warning_color+ ' !important; }</style>');
|
297
|
+
// $('head').append('<style>.icon-caution { color: ' +admonitionblock_caution_color+ ' !important; }</style>');
|
298
298
|
|
299
299
|
return true;
|
300
300
|
}, // END setCss
|
@@ -174,9 +174,9 @@ j1.adapter['toccer'] = (function () {
|
|
174
174
|
return true;
|
175
175
|
}, // END init
|
176
176
|
|
177
|
-
//
|
177
|
+
// -------------------------------------------------------------------------
|
178
178
|
// Set Toccer options
|
179
|
-
//
|
179
|
+
// -------------------------------------------------------------------------
|
180
180
|
initToccerCore: function ( options ) {
|
181
181
|
|
182
182
|
if (options !== undefined) {
|
@@ -227,10 +227,10 @@ j1.adapter['toccer'] = (function () {
|
|
227
227
|
return true;
|
228
228
|
}, // END initToccerCore
|
229
229
|
|
230
|
-
//
|
230
|
+
// -------------------------------------------------------------------------
|
231
231
|
// Calculate|Set Affix offset Top|Bottom of the Toccer menu
|
232
232
|
// depending on the size of the page header (attic)
|
233
|
-
//
|
233
|
+
// -------------------------------------------------------------------------
|
234
234
|
initAffix: function () {
|
235
235
|
var nav_bar = $('nav.navbar');
|
236
236
|
var side_bar = $('#j1-sidebar');
|
@@ -267,10 +267,10 @@ j1.adapter['toccer'] = (function () {
|
|
267
267
|
return true;
|
268
268
|
}, // END initAffix
|
269
269
|
|
270
|
-
//
|
270
|
+
// -------------------------------------------------------------------------
|
271
271
|
// Calculate|Set Top position of the Toccer menu
|
272
272
|
// depending on the size of the page header (attic)
|
273
|
-
//
|
273
|
+
// -------------------------------------------------------------------------
|
274
274
|
setTop: function (options) {
|
275
275
|
$(window).scroll(function(event){
|
276
276
|
var navbar = $('nav.navbar.navigator');
|
@@ -293,9 +293,9 @@ j1.adapter['toccer'] = (function () {
|
|
293
293
|
return true;
|
294
294
|
}, // END setTop
|
295
295
|
|
296
|
-
//
|
296
|
+
// -------------------------------------------------------------------------
|
297
297
|
// Set dynamic styles
|
298
|
-
//
|
298
|
+
// -------------------------------------------------------------------------
|
299
299
|
setCss: function () {
|
300
300
|
|
301
301
|
var bg_primary = j1.getStyleValue('bg-primary', 'background-color');
|
@@ -0,0 +1,1835 @@
|
|
1
|
+
---
|
2
|
+
regenerate: true
|
3
|
+
---
|
4
|
+
|
5
|
+
{% capture cache %}
|
6
|
+
|
7
|
+
{% comment %}
|
8
|
+
# -----------------------------------------------------------------------------
|
9
|
+
# ~/assets/themes/j1/core/js/j1.js
|
10
|
+
# Liquid template to initialize J1 Template Core functions
|
11
|
+
#
|
12
|
+
# Product/Info:
|
13
|
+
# https://jekyll.one
|
14
|
+
#
|
15
|
+
# Copyright (C) 2019 Juergen Adams
|
16
|
+
#
|
17
|
+
# J1 Template is licensed under the MIT License.
|
18
|
+
# For details, see https://jekyll.one
|
19
|
+
# -----------------------------------------------------------------------------
|
20
|
+
# TODO: jadams, 2019-01-20: Isolate drawer, switch from BME code
|
21
|
+
# -----------------------------------------------------------------------------
|
22
|
+
# Test data:
|
23
|
+
# {{ liquid_var | debug }}
|
24
|
+
# -----------------------------------------------------------------------------
|
25
|
+
{% endcomment %}
|
26
|
+
|
27
|
+
{% comment %} Liquid procedures
|
28
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
29
|
+
|
30
|
+
{% comment %} Set global settings
|
31
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
32
|
+
{% assign environment = site.environment %}
|
33
|
+
{% assign template_version = site.version %}
|
34
|
+
|
35
|
+
{% if site.permalink == 'none' %}
|
36
|
+
{% capture page_url %}{{ site.url }}.html{% endcapture %}
|
37
|
+
{% else %}
|
38
|
+
{% capture page_url %}{{ site.url }}{% endcapture %}
|
39
|
+
{% endif %}
|
40
|
+
|
41
|
+
{% comment %} Process YML config data
|
42
|
+
================================================================================ {% endcomment %}
|
43
|
+
|
44
|
+
{% comment %} Set config files
|
45
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
46
|
+
{% assign template_config = site.data.template_settings %}
|
47
|
+
{% assign blocks = site.data.blocks %}
|
48
|
+
{% assign modules = site.data.modules %}
|
49
|
+
|
50
|
+
{% comment %} Set config data
|
51
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
52
|
+
{% assign banner_config_defaults = blocks.defaults.banner.defaults %}
|
53
|
+
{% assign banner_config_settings = blocks.banner.settings %}
|
54
|
+
{% assign panel_config_defaults = blocks.defaults.panel.defaults %}
|
55
|
+
{% assign panel_config_settings = blocks.panel.settings %}
|
56
|
+
{% assign footer_config_defaults = blocks.defaults.footer.defaults %}
|
57
|
+
{% assign toccer_defaults = modules.defaults.toccer.defaults %}
|
58
|
+
{% assign toccer_settings = modules.toccer.settings %}
|
59
|
+
{% assign themer_defaults = modules.defaults.themer.defaults %}
|
60
|
+
{% assign themer_settings = modules.themer.settings %}
|
61
|
+
|
62
|
+
{% comment %} Set config options
|
63
|
+
-------------------------------------------------------------------------------- {% endcomment %}
|
64
|
+
{% assign toccer_options = toccer_defaults | merge: toccer_settings %}
|
65
|
+
{% assign themer_options = themer_defaults | merge: themer_settings %}
|
66
|
+
{% assign footer_id = footer_config_defaults.container-id %}
|
67
|
+
{% assign footer_data_path = footer_config_defaults.data_path %}
|
68
|
+
{% assign banner_data_path = banner_config_defaults.data_path %}
|
69
|
+
{% assign panel_data_path = panel_config_defaults.data_path %}
|
70
|
+
|
71
|
+
{% assign hideOnReload = modules.themer_options.hideOnReload %}
|
72
|
+
|
73
|
+
/*
|
74
|
+
# -----------------------------------------------------------------------------
|
75
|
+
# ~/assets/themes/j1/adapter/js/j1_template.js
|
76
|
+
# JS Adapter for J1 Template
|
77
|
+
#
|
78
|
+
# Product/Info:
|
79
|
+
# https://jekyll.one
|
80
|
+
#
|
81
|
+
# Copyright (C) 2019 Juergen Adams
|
82
|
+
#
|
83
|
+
# J1 Template is licensed under the MIT License.
|
84
|
+
# For details, see https://jekyll.one
|
85
|
+
# -----------------------------------------------------------------------------
|
86
|
+
# Adapter generated: {{site.time}}
|
87
|
+
# -----------------------------------------------------------------------------
|
88
|
+
*/
|
89
|
+
'use strict';
|
90
|
+
|
91
|
+
var j1 = (function () {
|
92
|
+
|
93
|
+
// ---------------------------------------------------------------------------
|
94
|
+
// globals
|
95
|
+
// ---------------------------------------------------------------------------
|
96
|
+
var rePager = new RegExp('navigator|dateview|tagview|archive');
|
97
|
+
var environment = '{{environment}}';
|
98
|
+
var moduleOptions = {};
|
99
|
+
|
100
|
+
// Status information
|
101
|
+
var state = 'not_started';
|
102
|
+
var mode = 'not_detected';
|
103
|
+
|
104
|
+
var current_page;
|
105
|
+
var previous_page;
|
106
|
+
var last_pager;
|
107
|
+
var last_pager_url;
|
108
|
+
var app_detected;
|
109
|
+
var user_state_detected;
|
110
|
+
|
111
|
+
// Theme information
|
112
|
+
var themeName;
|
113
|
+
var themeCss;
|
114
|
+
var themeExtensionCss;
|
115
|
+
|
116
|
+
// Pathes of J1 data files
|
117
|
+
var colors_data_path = '{{template_config.colors_data_path}}';
|
118
|
+
var font_size_data_path = '{{template_config.font_size_data_path}}';
|
119
|
+
var message_catalog_data_path = '{{template_config.message_catalog_data_path}}';
|
120
|
+
|
121
|
+
// Logger
|
122
|
+
var logger;
|
123
|
+
var logText;
|
124
|
+
|
125
|
+
var _this;
|
126
|
+
var settings;
|
127
|
+
var json_data;
|
128
|
+
var ep;
|
129
|
+
var baseUrl;
|
130
|
+
var referrer;
|
131
|
+
|
132
|
+
var default_theme_css = environment === 'production' ? '/assets/themes/j1/core/css/uno.min.css' : '/assets/themes/j1/core/css/uno.css'
|
133
|
+
var default_theme_name = 'Uno';
|
134
|
+
var default_theme_author = 'J1 Team';
|
135
|
+
var default_theme_link = 'https://jekyll.one/';
|
136
|
+
|
137
|
+
var cookie_names = {
|
138
|
+
'app_session': '{{template_config.cookies.app_session}}',
|
139
|
+
'user_session': '{{template_config.cookies.user_session}}',
|
140
|
+
'cookie_consent': '{{template_config.cookies.cookie_consent}}'
|
141
|
+
}
|
142
|
+
|
143
|
+
// J1 UserState Cookie (initial values)
|
144
|
+
var user_state = {
|
145
|
+
'theme_css': default_theme_css,
|
146
|
+
'theme_extension_css': '{{themer_options.includeBootswatch}}',
|
147
|
+
'theme_name': default_theme_name,
|
148
|
+
'theme_author': default_theme_author,
|
149
|
+
'theme_author_url': '{{template_config.theme_author_url}}',
|
150
|
+
'theme_link': default_theme_link,
|
151
|
+
'theme_version': '{{site.version}}',
|
152
|
+
'provider': '{{template_config.user.provider}}',
|
153
|
+
'provider_membership': '{{template_config.user.provider_membership}}',
|
154
|
+
'provider_permissions': '{{template_config.user.provider_permissions}}',
|
155
|
+
'provider_site_url': '{{template_config.user.provider_site_url}}',
|
156
|
+
'provider_home_url': '{{template_config.user.provider_home_url}}',
|
157
|
+
'provider_blog_url': '{{template_config.user.provider_blog_url}}',
|
158
|
+
'provider_member_url': '{{template_config.user.provider_member_url}}',
|
159
|
+
'provider_privacy_url': '{{template_config.user.provider_privacy_url}}',
|
160
|
+
'mode': 'na',
|
161
|
+
'user_name': '{{template_config.user.user_name}}',
|
162
|
+
'locale': navigator.language || navigator.userLanguage,
|
163
|
+
'requested_page': 'na',
|
164
|
+
'previous_page': 'na',
|
165
|
+
'last_pager': '/pages/public/blog/navigator/',
|
166
|
+
'cookies_accepted': 'pending'
|
167
|
+
};
|
168
|
+
|
169
|
+
// ---------------------------------------------------------------------------
|
170
|
+
// helper functions
|
171
|
+
// ---------------------------------------------------------------------------
|
172
|
+
|
173
|
+
function executeFunctionByName(functionName, context /*, args */) {
|
174
|
+
// See: https://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string
|
175
|
+
//
|
176
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
177
|
+
var namespaces = functionName.split(".");
|
178
|
+
var func = namespaces.pop();
|
179
|
+
for(var i = 0; i < namespaces.length; i++) {
|
180
|
+
context = context[namespaces[i]];
|
181
|
+
}
|
182
|
+
return context[func].apply(context, args);
|
183
|
+
}
|
184
|
+
|
185
|
+
// ---------------------------------------------------------------------------
|
186
|
+
// main object
|
187
|
+
// ---------------------------------------------------------------------------
|
188
|
+
return {
|
189
|
+
|
190
|
+
// -------------------------------------------------------------------------
|
191
|
+
// init
|
192
|
+
// Initializer
|
193
|
+
// -------------------------------------------------------------------------
|
194
|
+
init: function ( options ) {
|
195
|
+
|
196
|
+
// initialize state flag
|
197
|
+
//j1.state = 'pending';
|
198
|
+
|
199
|
+
var url = new parseURL(window.location.href)
|
200
|
+
var baseUrl = url.origin;
|
201
|
+
|
202
|
+
// -----------------------------------------------------------------------
|
203
|
+
// options loader
|
204
|
+
// -----------------------------------------------------------------------
|
205
|
+
var defaults = {
|
206
|
+
toc: false,
|
207
|
+
scrollbar: false,
|
208
|
+
comments: false
|
209
|
+
};
|
210
|
+
var args = $.extend(defaults, options);
|
211
|
+
|
212
|
+
// -----------------------------------------------------------------------
|
213
|
+
// init global vars
|
214
|
+
// -----------------------------------------------------------------------
|
215
|
+
var epoch = Math.floor(Date.now()/1000);
|
216
|
+
var timestamp_now = moment.unix(epoch).format('YYYY-MM-DD HH:mm:ss');
|
217
|
+
var curr_state = 'started';
|
218
|
+
|
219
|
+
logger = log4javascript.getLogger('j1.init');
|
220
|
+
user_state.created = timestamp_now;
|
221
|
+
user_state.timestamp = timestamp_now;
|
222
|
+
|
223
|
+
// -----------------------------------------------------------------------
|
224
|
+
// Initialize||Load (existing) user session cookie
|
225
|
+
// -----------------------------------------------------------------------
|
226
|
+
user_state = j1.existsCookie(cookie_names.user_session)
|
227
|
+
? j1.readCookie(cookie_names.user_session)
|
228
|
+
: j1.writeCookie({
|
229
|
+
name: cookie_names.user_session,
|
230
|
+
data: user_state
|
231
|
+
});
|
232
|
+
|
233
|
+
// Detect middleware (mode 'app') and update user state cookie
|
234
|
+
// -----------------------------------------------------------------------
|
235
|
+
// if (user_state.mode === 'na' || user_state.mode === 'app') {
|
236
|
+
if (user_state.mode === 'na') {
|
237
|
+
var url = new parseURL(window.location.href)
|
238
|
+
|
239
|
+
baseUrl = url.origin;
|
240
|
+
ep = baseUrl + '/status' + '?page=' + window.location.pathname;
|
241
|
+
|
242
|
+
$.when ($.ajax(ep))
|
243
|
+
.then(function(data) {
|
244
|
+
var logger = log4javascript.getLogger('j1.init');
|
245
|
+
user_state = j1.readCookie(cookie_names.user_session);
|
246
|
+
user_state.mode = 'app';
|
247
|
+
user_state.timestamp = timestamp_now;
|
248
|
+
user_state.requested_page = window.location.pathname;
|
249
|
+
user_state = j1.mergeData(user_state, data);
|
250
|
+
logText = 'mode detected: ' + user_state.mode;
|
251
|
+
|
252
|
+
logger.info(logText);
|
253
|
+
logger.info('update user state cookie');
|
254
|
+
j1.writeCookie({
|
255
|
+
name: cookie_names.user_session,
|
256
|
+
data: user_state
|
257
|
+
});
|
258
|
+
j1.setState(curr_state);
|
259
|
+
})
|
260
|
+
.catch(function(error) {
|
261
|
+
var logger = log4javascript.getLogger('j1.init');
|
262
|
+
user_state.mode = 'web';
|
263
|
+
user_state.requested_page = window.location.pathname;
|
264
|
+
user_state.timestamp = timestamp_now;
|
265
|
+
logText = 'mode detected: ' + user_state.mode;
|
266
|
+
logger.info(logText);
|
267
|
+
j1.writeCookie({
|
268
|
+
name: cookie_names.user_session,
|
269
|
+
data: user_state
|
270
|
+
});
|
271
|
+
logger.info('update user state cookie');
|
272
|
+
j1.setState(curr_state);
|
273
|
+
});
|
274
|
+
} else {
|
275
|
+
state = 'started';
|
276
|
+
logger.info('state: ' + state);
|
277
|
+
logger.info('page is being initialized');
|
278
|
+
}
|
279
|
+
|
280
|
+
{% comment %} Deferred data loads
|
281
|
+
See: https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done
|
282
|
+
Load J1 Template data objects 'asychronously'
|
283
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
284
|
+
|
285
|
+
// -----------------------------------------------------------------------
|
286
|
+
// data loader (should be rewitten to xhrDATA() )
|
287
|
+
// -----------------------------------------------------------------------
|
288
|
+
$.when (
|
289
|
+
j1.getColorData(colors_data_path),
|
290
|
+
j1.getFontSizeData(font_size_data_path),
|
291
|
+
j1.getMessageCatalog(message_catalog_data_path))
|
292
|
+
.done (function(colorData, fontSizes, messageCatalog) {
|
293
|
+
j1.colors = colorData[0];
|
294
|
+
j1.fonts = fontSizes[0];
|
295
|
+
|
296
|
+
// set logger for callback|anonymous
|
297
|
+
//
|
298
|
+
var logger = log4javascript.getLogger('j1.init');
|
299
|
+
|
300
|
+
logText = j1.getMessage('info', 'getState', 'text');
|
301
|
+
logText = logText + j1.getMessage('info', 'getState', 'data_objects');
|
302
|
+
logText = logText + j1.getMessage('info', 'getState', 'finished');
|
303
|
+
j1.logger('j1.init', 'info', logText);
|
304
|
+
|
305
|
+
logText = j1.getMessage('info', 'setState', 'text');
|
306
|
+
logText = logText + j1.getMessage('info', 'setState', 'started');
|
307
|
+
j1.logger('j1.init', 'info', logText);
|
308
|
+
executeFunctionByName('j1.setState', window, state);
|
309
|
+
|
310
|
+
// set logger for callback|anonymous
|
311
|
+
var logger = log4javascript.getLogger('j1.init');
|
312
|
+
|
313
|
+
if ( args.scrollbar === 'false' ) {
|
314
|
+
$('body').addClass( 'hide-scrollbar' )
|
315
|
+
$('html').addClass( 'hide-scrollbar-moz' )
|
316
|
+
}
|
317
|
+
|
318
|
+
logger.info('read user state from cookie');
|
319
|
+
user_state = j1.readCookie(cookie_names.user_session);
|
320
|
+
|
321
|
+
// process|update UserState
|
322
|
+
//
|
323
|
+
themeName = user_state.theme_name;
|
324
|
+
themeCss = user_state.theme_css;
|
325
|
+
themeExtensionCss = user_state.theme_extension_css;
|
326
|
+
|
327
|
+
// save last page access
|
328
|
+
// See: https://stackoverflow.com/questions/3528324/how-to-get-the-previous-url-in-javascript
|
329
|
+
// See: https://developer.mozilla.org/de/docs/Web/API/Window/history
|
330
|
+
//
|
331
|
+
user_state.timestamp = timestamp_now;
|
332
|
+
referrer = new parseURL(document.referrer);
|
333
|
+
current_page = window.location.pathname;
|
334
|
+
user_state.requested_page = current_page;
|
335
|
+
user_state.previous_page = referrer.search === '' ?
|
336
|
+
(referrer.pathname === '' ? current_page : referrer.pathname) :
|
337
|
+
(user_state.previous_page === '' || user_state.previous_page === 'na'
|
338
|
+
? '/'
|
339
|
+
: user_state.previous_page);
|
340
|
+
|
341
|
+
// calculate last 'pager' if any
|
342
|
+
//
|
343
|
+
if (rePager.test(user_state.previous_page)) {
|
344
|
+
last_pager = user_state.previous_page;
|
345
|
+
user_state.last_pager = last_pager;
|
346
|
+
} else {
|
347
|
+
last_pager = user_state.last_pager;
|
348
|
+
}
|
349
|
+
|
350
|
+
logger.info('update user state cookie');
|
351
|
+
j1.writeCookie({
|
352
|
+
name: cookie_names.user_session,
|
353
|
+
data: user_state
|
354
|
+
});
|
355
|
+
|
356
|
+
// ---------------------------------------------------------------------
|
357
|
+
// Initialize page resources for global modules (sequential asynchronous)
|
358
|
+
// (should be rewitten to xhrDATA() )
|
359
|
+
// ---------------------------------------------------------------------
|
360
|
+
$.when (
|
361
|
+
j1.initBanner(settings),
|
362
|
+
j1.initPanel(settings),
|
363
|
+
j1.initFooter(settings) )
|
364
|
+
.then (function (initBanner_response, initPanel_response, initFooter_response) {
|
365
|
+
var logger = log4javascript.getLogger('j1.init');
|
366
|
+
|
367
|
+
// Wait for LAST thenable (footer) in chain finishes
|
368
|
+
var footerLoaded = setInterval(function() {
|
369
|
+
if ( j1.getState() == 'footer_loaded') {
|
370
|
+
// clear interval checking
|
371
|
+
clearInterval(footerLoaded);
|
372
|
+
logger.info('loading data completed');
|
373
|
+
|
374
|
+
// Continue to run initializers
|
375
|
+
//
|
376
|
+
state = j1.getMessage('info', 'setState', 'running');
|
377
|
+
logText = j1.getMessage('info', 'setState', 'text');
|
378
|
+
logText = logText + j1.getMessage('info', 'setState', 'running');
|
379
|
+
j1.logger('j1.init', 'info', logText);
|
380
|
+
|
381
|
+
user_state.timestamp = timestamp_now;
|
382
|
+
j1.writeCookie({
|
383
|
+
name: cookie_names.user_session,
|
384
|
+
data: user_state
|
385
|
+
});
|
386
|
+
|
387
|
+
// ---------------------------------------------------------------
|
388
|
+
// Finalize|Display page (sequential asynchronous)
|
389
|
+
// NOTE:
|
390
|
+
// jadams 2019-01-20: for MDB, enabled only drawer, switch
|
391
|
+
// and ripples
|
392
|
+
// ---------------------------------------------------------------
|
393
|
+
$.when (
|
394
|
+
j1.initMDB(settings),
|
395
|
+
j1.initClipboard(settings))
|
396
|
+
.then (function () {
|
397
|
+
j1.displayPage();
|
398
|
+
})
|
399
|
+
.catch(function(error) {
|
400
|
+
var logger = log4javascript.getLogger('j1.init');
|
401
|
+
json_data = JSON.stringify(error, undefined, 2);
|
402
|
+
logText = 'deferred: ' + json_data;
|
403
|
+
logger.error(logText);
|
404
|
+
});
|
405
|
+
}
|
406
|
+
}, 25); // END 'footerLoaded'
|
407
|
+
}) // END load global modules
|
408
|
+
.catch(function(error) {
|
409
|
+
var logger = log4javascript.getLogger('j1.init');
|
410
|
+
json_data = JSON.stringify(error, undefined, 2);
|
411
|
+
logText = 'deferred: ' + json_data;
|
412
|
+
logger.error(logText);
|
413
|
+
});
|
414
|
+
}) // END load global data objects
|
415
|
+
.catch(function(error) {
|
416
|
+
var logger = log4javascript.getLogger('j1.init');
|
417
|
+
json_data = JSON.stringify(error, undefined, 2);
|
418
|
+
logText = 'deferred: ' + json_data;
|
419
|
+
logger.error(logText);
|
420
|
+
});
|
421
|
+
|
422
|
+
}, // END init
|
423
|
+
|
424
|
+
// -------------------------------------------------------------------------
|
425
|
+
// initBanner
|
426
|
+
// AJAX fetcher to load and place all banner used for a page
|
427
|
+
// -------------------------------------------------------------------------
|
428
|
+
initBanner: function (options) {
|
429
|
+
var logger = log4javascript.getLogger('j1.initBanner');
|
430
|
+
var banner = [];
|
431
|
+
var bannerOptions = [];
|
432
|
+
var mod = 'j1';
|
433
|
+
|
434
|
+
{% comment %}
|
435
|
+
Closure to pass additional data (e.g. #banner_id) to AJAX load callback
|
436
|
+
See: http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback
|
437
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
438
|
+
var cb_load_closure = function(banner_id) {
|
439
|
+
return function ( responseTxt, statusTxt, xhr ) {
|
440
|
+
if ( statusTxt == 'success' ) {
|
441
|
+
logText = 'loading banner on ID ' +banner_id+ ' completed';
|
442
|
+
logger.info(logText);
|
443
|
+
}
|
444
|
+
if ( statusTxt == 'error' ) {
|
445
|
+
logText = 'loading banner on ID ' +banner_id+ ' failed: ' + xhr.status + ': ' + xhr.statusText;
|
446
|
+
logger.error(logText);
|
447
|
+
// Set|Log status
|
448
|
+
state = 'failed';
|
449
|
+
logger.error('state: ' + state);
|
450
|
+
}
|
451
|
+
};
|
452
|
+
};
|
453
|
+
|
454
|
+
{% comment %} Collect all banner id|s configured
|
455
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
456
|
+
{% for items in banner_config_settings %}
|
457
|
+
{% assign key = items[0] %}
|
458
|
+
{% assign value = items[1] %}
|
459
|
+
|
460
|
+
{% if key == 'divider' %} {% assign banner_config = value %} {% endif %}
|
461
|
+
{% if key == 'teaser' %} {% assign banner_config = value %} {% endif %}
|
462
|
+
{% if key == 'image' %} {% assign banner_config = value %} {% endif %}
|
463
|
+
{% if key == 'parallax' %} {% assign banner_config = value %} {% endif %}
|
464
|
+
{% if key == 'exception' %} {% assign banner_config = value %} {% endif %}
|
465
|
+
|
466
|
+
{% for items in banner_config %}
|
467
|
+
{% for banners in items %}
|
468
|
+
|
469
|
+
{% for banner in banners %}
|
470
|
+
{% for item in banner %}
|
471
|
+
{% assign key = item[0] %}
|
472
|
+
{% assign value = item[1] %}
|
473
|
+
|
474
|
+
{% if key and debug %} item:value {{key}}:{{value}} {% endif %}
|
475
|
+
|
476
|
+
{% if key == 'id' %} {% assign id = value %} {% endif %}
|
477
|
+
{% if key == 'enabled' %} {% assign enabled = value %} {% endif %}
|
478
|
+
{% if key == 'background_color_1' %} {% assign background_color_1 = value %} {% endif %}
|
479
|
+
{% if key == 'background_color_2' %} {% assign background_color_2 = value %} {% endif %}
|
480
|
+
{% endfor %}
|
481
|
+
{% endfor %}
|
482
|
+
|
483
|
+
{% if id and enabled %}
|
484
|
+
{% comment %} Add CSS styles for current banner to section <HEAD>
|
485
|
+
-------------------------------------------------------------------- {% endcomment %}
|
486
|
+
{% if background_color_1 and background_color_2 %}
|
487
|
+
var banner_backround_style = '';
|
488
|
+
// Initialze banner background gradient/colors
|
489
|
+
banner_backround_style += "<style> .{{id}}-background { ";
|
490
|
+
banner_backround_style += "background-image: -webkit-gradient(linear, left top, left bottom, from( " +j1.setColorData('{{background_color_1}}')+ " ), to( " +j1.setColorData('{{background_color_2}}')+ " ));";
|
491
|
+
banner_backround_style += "background-image: -webkit-linear-gradient(top, " +j1.setColorData('{{background_color_1}}')+ " 0%, " +j1.setColorData('{{background_color_2}}')+ " 100%);";
|
492
|
+
banner_backround_style += "background-image: -o-linear-gradient(top, " +j1.setColorData('{{background_color_1}}')+ " 0%, " +j1.setColorData('{{background_color_2}}')+ " 100%);";
|
493
|
+
banner_backround_style += "background-image: linear-gradient(to bottom, " +j1.setColorData('{{background_color_1}}')+ " 0%, " +j1.setColorData('{{background_color_2}}')+ " 100%);";
|
494
|
+
banner_backround_style += 'filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="' +j1.setColorData('{{background_color_1}}')+ '", endColorstr="' +j1.setColorData('{{background_color_2}}')+ '", GradientType=0); ';
|
495
|
+
banner_backround_style += "} </style>";
|
496
|
+
$('head').append( banner_backround_style );
|
497
|
+
{% endif %}
|
498
|
+
|
499
|
+
{% comment %} Register current banner
|
500
|
+
-------------------------------------------------------------------- {% endcomment %}
|
501
|
+
banner.push('{{id}}');
|
502
|
+
{% endif %}
|
503
|
+
|
504
|
+
{% endfor %} {% comment %} END banners {% endcomment %}
|
505
|
+
|
506
|
+
{% comment %} Reset (Liquid) element variables
|
507
|
+
---------------------------------------------------------------------- {% endcomment %}
|
508
|
+
{% assign id = nil %}
|
509
|
+
{% assign enabled = nil %}
|
510
|
+
{% assign background_color_1 = nil %}
|
511
|
+
{% assign background_color_2 = nil %}
|
512
|
+
{% assign banner_config = nil %}
|
513
|
+
|
514
|
+
{% endfor %} {% comment %} END banner_config {% endcomment %}
|
515
|
+
{% endfor %} {% comment %} END banner_config_settings {% endcomment %}
|
516
|
+
|
517
|
+
{% comment %} REGISTER exceptions container
|
518
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
519
|
+
banner.push('exception_container');
|
520
|
+
|
521
|
+
{% comment %} LOAD all banner registered
|
522
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
523
|
+
if ( banner.length ) {
|
524
|
+
for (var i in banner) {
|
525
|
+
var id = '#' + banner[i];
|
526
|
+
var selector = $(id);
|
527
|
+
if (selector.length) {
|
528
|
+
logText = 'loading banner on ID: ' +banner[i];
|
529
|
+
logger.info(logText);
|
530
|
+
var banner_data_path = '{{banner_data_path}} ' + id + ' > *';
|
531
|
+
selector.load( banner_data_path, cb_load_closure( id ) );
|
532
|
+
}
|
533
|
+
}
|
534
|
+
} else {
|
535
|
+
logText = 'no banner found in site';
|
536
|
+
logger.info(logText);
|
537
|
+
}
|
538
|
+
|
539
|
+
return true;
|
540
|
+
}, // END initBanner
|
541
|
+
|
542
|
+
// -------------------------------------------------------------------------
|
543
|
+
// initPanel
|
544
|
+
// AJAX fetcher to load and place all panel used for a page
|
545
|
+
// -------------------------------------------------------------------------
|
546
|
+
// ToDo:
|
547
|
+
initPanel: function ( options ) {
|
548
|
+
var logger = log4javascript.getLogger('j1.initPanel');
|
549
|
+
var panel = [];
|
550
|
+
var mod = 'j1';
|
551
|
+
|
552
|
+
{% comment %} Closure to pass additional data (e.g. panel_id) to AJAX load callback
|
553
|
+
See: http://stackoverflow.com/questions/939032/jquery-pass-more-parameters-into-callback
|
554
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
555
|
+
var cb_load_closure = function(panel_id) {
|
556
|
+
return function ( responseTxt, statusTxt, xhr ) {
|
557
|
+
if ( statusTxt == 'success' ) {
|
558
|
+
logText = 'loading panel on ID ' +panel_id+ ' completed';
|
559
|
+
logger.info(logText);
|
560
|
+
}
|
561
|
+
if ( statusTxt == 'error' ) {
|
562
|
+
logText = 'loading panel on ID ' +panel_id+ ' failed: ' + xhr.status + ': ' + xhr.statusText;
|
563
|
+
logger.error(logText);
|
564
|
+
// Set|Log status
|
565
|
+
state = 'Error';
|
566
|
+
logger.error('state: ' + state);
|
567
|
+
}
|
568
|
+
};
|
569
|
+
};
|
570
|
+
|
571
|
+
{% comment %} Collect all panel id|s configured
|
572
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
573
|
+
{% for items in panel_config_settings %}
|
574
|
+
{% assign key = items[0] %}
|
575
|
+
{% assign value = items[1] %}
|
576
|
+
|
577
|
+
{% if key == 'intro' %} {% assign panel_config = value %} {% endif %}
|
578
|
+
{% if key == 'service' %} {% assign panel_config = value %} {% endif %}
|
579
|
+
{% if key == 'step' %} {% assign panel_config = value %} {% endif %}
|
580
|
+
{% if key == 'news' %} {% assign panel_config = value %} {% endif %}
|
581
|
+
{% if key == 'exception' %} {% assign panel_config = value %} {% endif %}
|
582
|
+
|
583
|
+
{% for items in panel_config %}
|
584
|
+
{% for panels in items %}
|
585
|
+
|
586
|
+
{% for panel in panels %}
|
587
|
+
{% for item in panel %}
|
588
|
+
{% assign key = item[0] %}
|
589
|
+
{% assign value = item[1] %}
|
590
|
+
|
591
|
+
{% if key and debug %} item:value {{key}}:{{value}} {% endif %}
|
592
|
+
|
593
|
+
{% if key == 'id' %} {% assign id = value %} {% endif %}
|
594
|
+
{% if key == 'enabled' %} {% assign enabled = value %} {% endif %}
|
595
|
+
{% endfor %}
|
596
|
+
{% endfor %}
|
597
|
+
|
598
|
+
{% comment %} Register current panel
|
599
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
600
|
+
{% if id and enabled %}
|
601
|
+
panel.push('{{id}}');
|
602
|
+
{% endif %}
|
603
|
+
|
604
|
+
{% comment %} Reset (Liquid) element variables
|
605
|
+
-------------------------------------------------------------------------- {% endcomment %}
|
606
|
+
{% assign id = nil %}
|
607
|
+
{% assign enabled = nil %}
|
608
|
+
{% assign panel_config = nil %}
|
609
|
+
|
610
|
+
{% endfor %} {% comment %} END panels {% endcomment %}
|
611
|
+
{% endfor %} {% comment %} END panel_config {% endcomment %}
|
612
|
+
{% endfor %} {% comment %} END panel_config_settings {% endcomment %}
|
613
|
+
|
614
|
+
if ( panel.length ) {
|
615
|
+
for (var i in panel) {
|
616
|
+
var id = "#" + panel[i];
|
617
|
+
var selector = $(id);
|
618
|
+
if ( selector.length ) {
|
619
|
+
logText = 'loading panel on ID: ' +panel[i];
|
620
|
+
logger.info(logText);
|
621
|
+
var panel_data_path = '{{panel_data_path}} ' + id + ' > *';
|
622
|
+
selector.load( panel_data_path, cb_load_closure( id ) );
|
623
|
+
}
|
624
|
+
}
|
625
|
+
} else {
|
626
|
+
logText = 'no panel found in site';
|
627
|
+
logger.info(logText);
|
628
|
+
}
|
629
|
+
|
630
|
+
return true;
|
631
|
+
}, // END initPanel
|
632
|
+
|
633
|
+
// -------------------------------------------------------------------------
|
634
|
+
// initFooter
|
635
|
+
// AJAX fetcher to load and place the footer used for a page
|
636
|
+
// -------------------------------------------------------------------------
|
637
|
+
initFooter: function ( options ) {
|
638
|
+
var logger = log4javascript.getLogger('j1.initFooter');
|
639
|
+
var mod = 'j1';
|
640
|
+
|
641
|
+
logText = 'begin initialization';
|
642
|
+
logger.info(logText);
|
643
|
+
|
644
|
+
var cb_load_closure = function(footer_id) {
|
645
|
+
return function ( responseTxt, statusTxt, xhr ) {
|
646
|
+
if ( statusTxt == 'success' ) {
|
647
|
+
logText = 'footer on ID ' +footer_id+ ' loaded successfully';
|
648
|
+
logger.info(logText);
|
649
|
+
|
650
|
+
state = 'footer_loaded';
|
651
|
+
logger.info('Set state for module ' + mod + ': ' + state);
|
652
|
+
executeFunctionByName(mod + '.setState', window, state)
|
653
|
+
|
654
|
+
logText = 'initialization completed';
|
655
|
+
logger.info(logText);
|
656
|
+
}
|
657
|
+
if ( statusTxt == 'error' ) {
|
658
|
+
logText = 'footer on ID ' +footer_id+ ' loading failed. Error: ' + xhr.status + ': ' + xhr.statusText;
|
659
|
+
logger.error(logText);
|
660
|
+
// Set|Log status
|
661
|
+
state = 'failed';
|
662
|
+
logger.error('state: ' + state);
|
663
|
+
logText = 'initialization completed';
|
664
|
+
logger.info(logText);
|
665
|
+
}
|
666
|
+
};
|
667
|
+
};
|
668
|
+
|
669
|
+
var id = '#' + '{{footer_id}}';
|
670
|
+
var selector = $(id);
|
671
|
+
if ( selector.length ) {
|
672
|
+
var footer_data_path = '{{footer_data_path}}';
|
673
|
+
// var footer_data_path = '{{footer_data_path}}' + id + ' > *';
|
674
|
+
selector.load( footer_data_path, cb_load_closure( id ) );
|
675
|
+
}
|
676
|
+
|
677
|
+
return true;
|
678
|
+
}, // END initFooter
|
679
|
+
|
680
|
+
// -------------------------------------------------------------------------
|
681
|
+
// initClipboard
|
682
|
+
// Create copy-to-clipboard for all pages
|
683
|
+
// -------------------------------------------------------------------------
|
684
|
+
initClipboard: function ( options ) {
|
685
|
+
var logger = log4javascript.getLogger('j1.initClipboard');
|
686
|
+
|
687
|
+
logText = 'begin initialization';
|
688
|
+
logger.info(logText);
|
689
|
+
|
690
|
+
// insert copy to clipboard button before all elements having a
|
691
|
+
// class of ".highlight" assigned to (e.g. Asciidoc source blocks)
|
692
|
+
$('.highlight').each(function () {
|
693
|
+
// Check if no clipboard should be applied
|
694
|
+
var isNoClip = $(this).closest('.noclip');
|
695
|
+
if ( isNoClip.length == 0) {
|
696
|
+
var btnHtml = '<div class="j1-clipboard"><span class="btn-clipboard j1-tooltip" title="Copy to clipboard">Copy</span></div>';
|
697
|
+
var bumms = $(this).closest('.noclip');
|
698
|
+
$(this).before(btnHtml);
|
699
|
+
$('.btn-clipboard').tooltip();
|
700
|
+
}
|
701
|
+
});
|
702
|
+
var clipboard = new Clipboard( '.btn-clipboard', {
|
703
|
+
target: function target(trigger) {
|
704
|
+
return trigger.parentNode.nextElementSibling;
|
705
|
+
}
|
706
|
+
});
|
707
|
+
|
708
|
+
// Manage clipboard events
|
709
|
+
clipboard.on('success', function (e) {
|
710
|
+
$(e.trigger).attr('title', 'Copied!').tooltip('_fixTitle').tooltip('show').attr('title', 'Copy to clipboard').tooltip('_fixTitle');
|
711
|
+
var logger = log4javascript.getLogger('j1.initClipboard');
|
712
|
+
var logText = 'Copy-To-Clipboard sucessfull';
|
713
|
+
logger.debug(logText);
|
714
|
+
/* Cleanup clipped data for trailing numbers */
|
715
|
+
var splitted = e.text.split('\n');
|
716
|
+
var concat;
|
717
|
+
var i;
|
718
|
+
for (i=0; i<splitted.length; i++) {
|
719
|
+
concat += splitted[i].replace(/^\s+\d+/, '');
|
720
|
+
}
|
721
|
+
e.clearSelection();
|
722
|
+
});
|
723
|
+
clipboard.on('error', function (e) {
|
724
|
+
var fallbackMsg = /Mac/i.test(navigator.userAgent) ? 'Press \u2318 to copy' : 'Press Ctrl-C to copy';
|
725
|
+
logger = log4javascript.getLogger('j1.initClipboard');
|
726
|
+
logText = 'Copy-To-Clipboard failed. Use fallback.';
|
727
|
+
logger.warn(logText);
|
728
|
+
$(e.trigger).attr('title', fallbackMsg).tooltip('_fixTitle').tooltip('show').attr('title', 'Copy to clipboard').tooltip('_fixTitle');
|
729
|
+
});
|
730
|
+
|
731
|
+
logText = 'initialization completed';
|
732
|
+
logger.info(logText);
|
733
|
+
|
734
|
+
return true;
|
735
|
+
}, // END initClipboard
|
736
|
+
|
737
|
+
// -------------------------------------------------------------------------
|
738
|
+
// displayPage
|
739
|
+
// Show the page after timeout of {{hideOnReload}} ms
|
740
|
+
// -------------------------------------------------------------------------
|
741
|
+
// NOTE:
|
742
|
+
// jadams, 2019-08-21: for unknown reason, the user state data
|
743
|
+
// (read from cookie) seems not coorect (or loaded too late).
|
744
|
+
// To make correct data sure for APP mode, a status request is done
|
745
|
+
// to load the current state from the middleware (skipped in WEB mode)
|
746
|
+
// -------------------------------------------------------------------------
|
747
|
+
displayPage: function (options) {
|
748
|
+
var logger = log4javascript.getLogger('j1.displayPage');
|
749
|
+
var flickerTimeout = {{template_config.flicker_timeout}};
|
750
|
+
var url = new parseURL(window.location.href)
|
751
|
+
var baseUrl = url.origin;
|
752
|
+
var ep = baseUrl + '/status' + '?page=' + window.location.pathname;
|
753
|
+
var user_state = j1.readCookie(cookie_names.user_session);
|
754
|
+
var provider;
|
755
|
+
var previous_page;
|
756
|
+
var appDetected;
|
757
|
+
var providerPermissions;
|
758
|
+
var categoryAllowed;
|
759
|
+
|
760
|
+
j1.setCss();
|
761
|
+
|
762
|
+
if (j1.appDetected()) {
|
763
|
+
// APP mode
|
764
|
+
$.when ($.ajax(ep))
|
765
|
+
.then(function(data) {
|
766
|
+
var logger = log4javascript.getLogger('j1.displayPage');
|
767
|
+
|
768
|
+
user_state = j1.mergeData(user_state, data);
|
769
|
+
user_state.current_page = window.location.href;
|
770
|
+
|
771
|
+
j1.writeCookie({
|
772
|
+
name: cookie_names.user_session,
|
773
|
+
data: user_state
|
774
|
+
});
|
775
|
+
|
776
|
+
providerPermissions = user_state.provider_permissions;
|
777
|
+
providerPermissions.push('public');
|
778
|
+
categoryAllowed = providerPermissions.includes(user_state.page_permission);
|
779
|
+
|
780
|
+
// Make sure that protected pages are ALWAYS checked for permissions
|
781
|
+
// -------------------------------------------------------------------
|
782
|
+
if (user_state.page_permission !== 'public' && categoryAllowed === false) {
|
783
|
+
// redirect to middleware|page_authentication
|
784
|
+
if (data.authenticated === 'true') {
|
785
|
+
ep = baseUrl + '/post_authentication';
|
786
|
+
window.location.href = ep;
|
787
|
+
} else {
|
788
|
+
ep = baseUrl + '/page_validation?page=' + window.location.pathname;
|
789
|
+
window.location.href = ep;
|
790
|
+
return false;
|
791
|
+
}
|
792
|
+
} // END check protected pages
|
793
|
+
|
794
|
+
setTimeout (function() {
|
795
|
+
// Display page
|
796
|
+
$('#no_flicker').css('display', 'block');
|
797
|
+
|
798
|
+
// Show or Hide cookie icon
|
799
|
+
if (user_state.cookies_accepted === 'accepted') {
|
800
|
+
// Display cookie icon
|
801
|
+
$('#quickLinksCookieButton').css('display', 'block');
|
802
|
+
} else {
|
803
|
+
logText = 'Hide cookie icon';
|
804
|
+
logger.info(logText);
|
805
|
+
// Display cookie icon
|
806
|
+
$('#quickLinksCookieButton').css('display', 'none');
|
807
|
+
}
|
808
|
+
|
809
|
+
// Show Control Center icon
|
810
|
+
$('#quickLinksControlCenterButton').css('display', 'block');
|
811
|
+
|
812
|
+
// Show or Hide SignInOut icon
|
813
|
+
if (j1.authClientEnabled()) {
|
814
|
+
logger.info('APP mode deteced, present SignInOut icon');
|
815
|
+
if (user_state.authenticated === 'true') {
|
816
|
+
// Set SignOut
|
817
|
+
$('#navLinkSignInOut').attr("data-target","#modalOmniSignOut");
|
818
|
+
$('#iconSignInOut').removeClass( "mdi-login" ).addClass( "mdi-logout" );
|
819
|
+
} else {
|
820
|
+
// Set SignIn
|
821
|
+
$('#navLinkSignInOut').attr("data-target","#modalOmniSignIn");
|
822
|
+
$('#iconSignInOut').removeClass( "mdi-logout" ).addClass( "mdi-login" );
|
823
|
+
}
|
824
|
+
logger.info('authentication detected as: ' + user_state.authenticated);
|
825
|
+
logger.info('Show SignInOut icon');
|
826
|
+
$('#quickLinksSignInOutButton').css('display', 'block');
|
827
|
+
}
|
828
|
+
|
829
|
+
// If the page requested contains an anchor element,
|
830
|
+
// do a smooth scroll to
|
831
|
+
j1.scrollTo();
|
832
|
+
|
833
|
+
if (user_state.previous_page !== user_state.current_page) {
|
834
|
+
logText = 'Page change detected';
|
835
|
+
logger.info(logText);
|
836
|
+
logText = 'Previous page: ' + user_state.previous_page;
|
837
|
+
logger.info(logText);
|
838
|
+
logText = 'Current page: ' + user_state.current_page;
|
839
|
+
logger.info(logText);
|
840
|
+
}
|
841
|
+
|
842
|
+
j1.core.navigator.updateSidebar(user_state);
|
843
|
+
|
844
|
+
// Set|Log status
|
845
|
+
state = 'finished';
|
846
|
+
logText = 'state: ' + state;
|
847
|
+
logger.info(logText);
|
848
|
+
logText = "J1 Template successfully initialized";
|
849
|
+
logger.info(logText);
|
850
|
+
|
851
|
+
}, flickerTimeout);
|
852
|
+
});
|
853
|
+
// END APP mode
|
854
|
+
} else {
|
855
|
+
// WEB mode
|
856
|
+
setTimeout (function() {
|
857
|
+
// Display page
|
858
|
+
$('#no_flicker').css('display', 'block');
|
859
|
+
|
860
|
+
logger.info('WEB mode detetced, hide SignInOut icon');
|
861
|
+
$('#quickLinksSignInOutButton').css('display', 'none');
|
862
|
+
|
863
|
+
user_state.current_page = window.location.href;
|
864
|
+
j1.writeCookie({
|
865
|
+
name: cookie_names.user_session,
|
866
|
+
data: user_state
|
867
|
+
});
|
868
|
+
|
869
|
+
// Show or Hide cookie icon
|
870
|
+
if (user_state.cookies_accepted === 'accepted') {
|
871
|
+
// Display cookie icon
|
872
|
+
$('#quickLinksCookieButton').css('display', 'block');
|
873
|
+
} else {
|
874
|
+
logText = 'Hide cookie icon';
|
875
|
+
logger.info(logText);
|
876
|
+
// Display cookie icon
|
877
|
+
$('#quickLinksCookieButton').css('display', 'none');
|
878
|
+
}
|
879
|
+
|
880
|
+
// If the page requested contains an anchor element,
|
881
|
+
// do a smooth scroll to
|
882
|
+
j1.scrollTo();
|
883
|
+
|
884
|
+
if (user_state.previous_page !== user_state.current_page) {
|
885
|
+
logText = 'Page change detected';
|
886
|
+
logger.info(logText);
|
887
|
+
logText = 'Previous page: ' + user_state.previous_page;
|
888
|
+
logger.info(logText);
|
889
|
+
logText = 'Current page: ' + user_state.current_page;
|
890
|
+
logger.info(logText);
|
891
|
+
}
|
892
|
+
|
893
|
+
j1.core.navigator.updateSidebar(user_state);
|
894
|
+
|
895
|
+
// Set|Log status
|
896
|
+
state = 'finished';
|
897
|
+
logText = 'state: ' + state;
|
898
|
+
logger.info(logText);
|
899
|
+
logText = "J1 Template successfully initialized";
|
900
|
+
logger.info(logText);
|
901
|
+
|
902
|
+
}, flickerTimeout);
|
903
|
+
} // END WEB mode
|
904
|
+
}, // END displayPage
|
905
|
+
|
906
|
+
// -------------------------------------------------------------------------
|
907
|
+
// Initialize BS Material Design
|
908
|
+
// -------------------------------------------------------------------------
|
909
|
+
// ToDo:
|
910
|
+
initMDB: function (options) {
|
911
|
+
var logger;
|
912
|
+
|
913
|
+
logger = log4javascript.getLogger('j1.initMDB');
|
914
|
+
logText = 'MDB is being initialized';
|
915
|
+
logger.info(logText);
|
916
|
+
|
917
|
+
$('body').bootstrapMaterialDesign();
|
918
|
+
//new WOW().init();
|
919
|
+
|
920
|
+
var logText = 'initializing MDB completed';
|
921
|
+
logger.info(logText);
|
922
|
+
|
923
|
+
return true;
|
924
|
+
}, // END initMDB
|
925
|
+
|
926
|
+
// -------------------------------------------------------------------------
|
927
|
+
// Helper functions
|
928
|
+
// -------------------------------------------------------------------------
|
929
|
+
|
930
|
+
// -------------------------------------------------------------------------
|
931
|
+
// Merge two objects (properties) and returns the resulting object
|
932
|
+
// TODO: Improve comment, give synopsis and example
|
933
|
+
// See: https://stackoverflow.com/questions/43109229/merge-default-options-containing-object-with-json-object
|
934
|
+
// -------------------------------------------------------------------------
|
935
|
+
mergeData: function () {
|
936
|
+
var a = [].slice.call(arguments), o = a.shift();
|
937
|
+
|
938
|
+
for(var i=0,l=a.length; i<l; i++){
|
939
|
+
for(var p in a[i]){
|
940
|
+
o[p] = a[i][p];
|
941
|
+
}
|
942
|
+
}
|
943
|
+
|
944
|
+
return o;
|
945
|
+
}, // END mergeData
|
946
|
+
|
947
|
+
// -------------------------------------------------------------------------
|
948
|
+
// returns the last vistited page
|
949
|
+
// -------------------------------------------------------------------------
|
950
|
+
getPrevPage: function () {
|
951
|
+
return previous_page;
|
952
|
+
}, // END getPrevPage
|
953
|
+
|
954
|
+
// -------------------------------------------------------------------------
|
955
|
+
// returns the preferred language taken form window.navigator
|
956
|
+
// See:
|
957
|
+
// https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference
|
958
|
+
// -------------------------------------------------------------------------
|
959
|
+
getLanguage: function () {
|
960
|
+
var language = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage);
|
961
|
+
|
962
|
+
return language;
|
963
|
+
}, // END getLanguage
|
964
|
+
|
965
|
+
// -------------------------------------------------------------------------
|
966
|
+
// returns the template version taken from site config ( _config.yml)
|
967
|
+
// -------------------------------------------------------------------------
|
968
|
+
getTemplateVersion: function () {
|
969
|
+
return '{{template_version}}';
|
970
|
+
}, // END getTemplateVersion
|
971
|
+
|
972
|
+
// -------------------------------------------------------------------------
|
973
|
+
// Scrolls smooth to any anchor referenced by an page URL
|
974
|
+
// Values for delay|offset are taken from TOC module (Tocbot)
|
975
|
+
// -------------------------------------------------------------------------
|
976
|
+
scrollTo: function () {
|
977
|
+
// Unclear why a offset correction is needed (sometimes ???)
|
978
|
+
var offset_correction = {{toccer_options.headingsOffset}};
|
979
|
+
var offset = {{toccer_options.smoothScrollOffset}};
|
980
|
+
var anchor_id = window.location.href.split("#")[1];
|
981
|
+
var selector;
|
982
|
+
var heading;
|
983
|
+
var re;
|
984
|
+
|
985
|
+
if (anchor_id) {
|
986
|
+
selector = $('.' + anchor_id + ', #' + anchor_id +',[name='+anchor_id+']');
|
987
|
+
heading = selector[0].nodeName;
|
988
|
+
|
989
|
+
|
990
|
+
// scroll only, if an anchor is given with URL
|
991
|
+
if (selector.length) {
|
992
|
+
var delay = {{toccer_options.smoothScrollDuration}};
|
993
|
+
var scroll_to = parseInt( selector.offset().top - offset - offset_correction );
|
994
|
+
//var scroll_to = selector.offset().top;
|
995
|
+
$('html,body').animate({scrollTop: scroll_to}, delay,
|
996
|
+
function () {
|
997
|
+
// scroll the page one pixel back and forth
|
998
|
+
// to get the right position for the NAV Module (Tocbot)
|
999
|
+
$(window).scrollTop($(window).scrollTop()+1);
|
1000
|
+
$(window).scrollTop($(window).scrollTop()-1);
|
1001
|
+
});
|
1002
|
+
} else {
|
1003
|
+
// TODO: to be checked if this else is needed
|
1004
|
+
// scroll the page one pixel back and forth
|
1005
|
+
// to get the right position for the NAV Module (Tocbot)
|
1006
|
+
$(window).scrollTop($(window).scrollTop()+1);
|
1007
|
+
$(window).scrollTop($(window).scrollTop()-1);
|
1008
|
+
} // selector.length
|
1009
|
+
} else {
|
1010
|
+
// scroll the page one pixel back and forth
|
1011
|
+
// to get the right position for the NAV Module (Tocbot)
|
1012
|
+
$(window).scrollTop($(window).scrollTop()+1);
|
1013
|
+
$(window).scrollTop($(window).scrollTop()-1);
|
1014
|
+
} // END if anchor_id
|
1015
|
+
|
1016
|
+
return true;
|
1017
|
+
}, // END scrollTo
|
1018
|
+
|
1019
|
+
// -------------------------------------------------------------------------
|
1020
|
+
// Detect if a page has changed
|
1021
|
+
//
|
1022
|
+
// Note:
|
1023
|
+
// Returns true on a change. Otherwise false
|
1024
|
+
// some of the "values" set ealier by j1.resolveMacros needs to be
|
1025
|
+
// updated
|
1026
|
+
// -------------------------------------------------------------------------
|
1027
|
+
hasPageChanged: function ( data ) {
|
1028
|
+
var user_state = data;
|
1029
|
+
var logger;
|
1030
|
+
var logText;
|
1031
|
+
|
1032
|
+
if (user_state.previous_page == user_state.current_page ) {
|
1033
|
+
return false;
|
1034
|
+
} else {
|
1035
|
+
return true;
|
1036
|
+
}
|
1037
|
+
|
1038
|
+
}, // END hasPageChanged
|
1039
|
+
|
1040
|
+
// -------------------------------------------------------------------------
|
1041
|
+
// authClientEnabled:
|
1042
|
+
// Returns the state of the authClient
|
1043
|
+
// -------------------------------------------------------------------------
|
1044
|
+
authClientEnabled: function () {
|
1045
|
+
var authClientEnabled = {{site.j1_auth.enabled}};
|
1046
|
+
|
1047
|
+
return authClientEnabled;
|
1048
|
+
}, // END authClientEnabled
|
1049
|
+
|
1050
|
+
// -------------------------------------------------------------------------
|
1051
|
+
// appDetected:
|
1052
|
+
// Returns true if a web session cookie exists
|
1053
|
+
// -------------------------------------------------------------------------
|
1054
|
+
appDetected: function () {
|
1055
|
+
var user_state = j1.readCookie(cookie_names.user_session);
|
1056
|
+
var detected = user_state.mode === 'app' ? true : false;
|
1057
|
+
|
1058
|
+
return detected;
|
1059
|
+
}, // END appDetected
|
1060
|
+
|
1061
|
+
// -------------------------------------------------------------------------
|
1062
|
+
// xhrDATA:
|
1063
|
+
// Load data asychronously using XHR on a DIV container
|
1064
|
+
// specified (from options: xhr_data_path)
|
1065
|
+
// -------------------------------------------------------------------------
|
1066
|
+
xhrDATA: function (mod, options, status) {
|
1067
|
+
var logger = log4javascript.getLogger('j1.xhrDATA');
|
1068
|
+
var state = status;
|
1069
|
+
var logText;
|
1070
|
+
|
1071
|
+
var cb_load_closure = function(mod, id) {
|
1072
|
+
return function (responseTxt, statusTxt, xhr) {
|
1073
|
+
if ( statusTxt === 'success' ) {
|
1074
|
+
if (state) {
|
1075
|
+
logger.info('set state for ' +mod+ ' to: ' + state);
|
1076
|
+
executeFunctionByName(mod + '.setState', window, state);
|
1077
|
+
}
|
1078
|
+
logText = 'data on ' +id+ ' loaded successfully';
|
1079
|
+
logger.info(logText);
|
1080
|
+
}
|
1081
|
+
if ( statusTxt === 'error' ) {
|
1082
|
+
state = 'failed';
|
1083
|
+
logger.info('set state for ' +mod+ ' to: ' + state);
|
1084
|
+
executeFunctionByName(mod + '.setState', window, state);
|
1085
|
+
logText = 'data on ' +id+ ' loading failed: ' + xhr.status + ': ' + xhr.statusText;
|
1086
|
+
logger.error(logText);
|
1087
|
+
}
|
1088
|
+
};
|
1089
|
+
};
|
1090
|
+
|
1091
|
+
var id = "#" + options.xhr_container_id;
|
1092
|
+
var selector = $(id);
|
1093
|
+
|
1094
|
+
if ( selector.length ) {
|
1095
|
+
var modal_html_data_path = options.xhr_data_path + " > *";
|
1096
|
+
selector.load( modal_html_data_path, cb_load_closure( mod, id ) );
|
1097
|
+
return true;
|
1098
|
+
} else {
|
1099
|
+
logText = "Data not loaded"
|
1100
|
+
logger.warn(logText);
|
1101
|
+
// Set processing state to 'finished' to complete module load
|
1102
|
+
state = 'finished';
|
1103
|
+
logger.info('state: ' + state);
|
1104
|
+
executeFunctionByName(mod + '.setState', window, state)
|
1105
|
+
return false;
|
1106
|
+
}
|
1107
|
+
}, // END xhrDATA
|
1108
|
+
|
1109
|
+
// -------------------------------------------------------------------------
|
1110
|
+
// xhrAPI: XMLHttpRequest (XHR) based async server API request
|
1111
|
+
// Request an REST API at 'url', using verb 'type' of response type 'type'
|
1112
|
+
// -------------------------------------------------------------------------
|
1113
|
+
xhrAPI: function (url, request_type, data_type) {
|
1114
|
+
var type = typeof request_type == 'undefined' || request_type == '' ? 'GET' : request_type;
|
1115
|
+
var data_type = typeof data_type == 'undefined' || data_type == '' ? 'json' : data_type;
|
1116
|
+
|
1117
|
+
return $.ajax({
|
1118
|
+
url: url,
|
1119
|
+
type: type,
|
1120
|
+
dataType: data_type,
|
1121
|
+
success: function(data) {
|
1122
|
+
if (typeof data == 'string') {
|
1123
|
+
return JSON.parse(data);
|
1124
|
+
}
|
1125
|
+
if (typeof data == 'object') {
|
1126
|
+
return data;
|
1127
|
+
}
|
1128
|
+
},
|
1129
|
+
error: function(error) {
|
1130
|
+
json_data = JSON.stringify(error, undefined, 2);
|
1131
|
+
logger.error("XHR request failed: " + json_data);
|
1132
|
+
}
|
1133
|
+
});
|
1134
|
+
|
1135
|
+
}, // END xhrAPI
|
1136
|
+
|
1137
|
+
// -------------------------------------------------------------------------
|
1138
|
+
// fetchAPI: Fetch (Promise) based async request
|
1139
|
+
// Returns the current git state collected from /git endpoint
|
1140
|
+
// -------------------------------------------------------------------------
|
1141
|
+
fetchAPI: function (params, cbData) {
|
1142
|
+
var cbData = cbData;
|
1143
|
+
var parameters = params == '' ? 'all' : params;
|
1144
|
+
var url = 'http://localhost:41001/gut';
|
1145
|
+
|
1146
|
+
async function callAPI() {
|
1147
|
+
const URL = url;
|
1148
|
+
const fetchResult = fetch(URL)
|
1149
|
+
const response = await fetchResult;
|
1150
|
+
|
1151
|
+
if (response.ok) {
|
1152
|
+
const jsonData = await response.json();
|
1153
|
+
json_data = JSON.stringify(jsonData, undefined, 2);
|
1154
|
+
logText = 'Response from Fetch received: ' + json_data;
|
1155
|
+
logger.info(logText);
|
1156
|
+
//console.log(jsonData);
|
1157
|
+
} else {
|
1158
|
+
throw Error(response.statusText);
|
1159
|
+
// logger.error("Fetch request failed: " + response.statusText);
|
1160
|
+
}
|
1161
|
+
}
|
1162
|
+
callAPI();
|
1163
|
+
|
1164
|
+
return true;
|
1165
|
+
}, // END fetchAPI
|
1166
|
+
|
1167
|
+
// -------------------------------------------------------------------------
|
1168
|
+
// getColorData: Returns the j1_colors object
|
1169
|
+
// Load color definitions from colors_data_path
|
1170
|
+
// -------------------------------------------------------------------------
|
1171
|
+
getColorData: function (data_path) {
|
1172
|
+
var logger = log4javascript.getLogger('j1.getColorData');
|
1173
|
+
var j1_colors = {};
|
1174
|
+
|
1175
|
+
return $.ajax({
|
1176
|
+
url: data_path,
|
1177
|
+
success: function (data) {
|
1178
|
+
var logText = "Color data loaded successfully"
|
1179
|
+
logger.info(logText);
|
1180
|
+
state = 'color_data_loaded_success';
|
1181
|
+
logger.info('state: ' + state);
|
1182
|
+
executeFunctionByName('j1.setState', window, state);
|
1183
|
+
|
1184
|
+
if (typeof data == 'string') {
|
1185
|
+
j1_colors = JSON.parse(data);
|
1186
|
+
}
|
1187
|
+
if (typeof data == 'object') {
|
1188
|
+
j1_colors = data;
|
1189
|
+
}
|
1190
|
+
},
|
1191
|
+
error: function (data) {
|
1192
|
+
var logText = "Color data not loaded"
|
1193
|
+
logger.warn(logText);
|
1194
|
+
state = 'color_data_loaded_failed';
|
1195
|
+
logger.info('state: ' + state);
|
1196
|
+
executeFunctionByName('j1.setState', window, state)
|
1197
|
+
return false;
|
1198
|
+
}
|
1199
|
+
});
|
1200
|
+
|
1201
|
+
}, // END getColorData
|
1202
|
+
|
1203
|
+
// -------------------------------------------------------------------------
|
1204
|
+
// getColorData: Returns a color out of the j1_colors object
|
1205
|
+
// if
|
1206
|
+
// -------------------------------------------------------------------------
|
1207
|
+
setColorData: function (color) {
|
1208
|
+
|
1209
|
+
if ( typeof color != 'undefined' ) {
|
1210
|
+
var reHex = /^#[A-Fa-f0-9]+$/;
|
1211
|
+
var reRGBA = /^rgba/;
|
1212
|
+
var isHex = color.match(reHex);
|
1213
|
+
var isRGBA = color.match(reRGBA);
|
1214
|
+
|
1215
|
+
if ( typeof j1.colors[color] != 'undefined' ) {
|
1216
|
+
return j1.colors[color];
|
1217
|
+
} else if (isHex) {
|
1218
|
+
return color;
|
1219
|
+
} else if (isRGBA) {
|
1220
|
+
return color;
|
1221
|
+
} else {
|
1222
|
+
return false;
|
1223
|
+
}
|
1224
|
+
} else {
|
1225
|
+
return false;
|
1226
|
+
}
|
1227
|
+
|
1228
|
+
}, // END setColorData
|
1229
|
+
|
1230
|
+
// -------------------------------------------------------------------------
|
1231
|
+
// getFontSizeData: Returns the j1_font_sizes object
|
1232
|
+
// Load loadFontSize definitions from font_size_data_path
|
1233
|
+
// -------------------------------------------------------------------------
|
1234
|
+
getFontSizeData: function (data_path) {
|
1235
|
+
var logger = log4javascript.getLogger('j1.getFontSizeData');
|
1236
|
+
var j1_font_sizes = {};
|
1237
|
+
|
1238
|
+
return $.ajax({
|
1239
|
+
url: data_path,
|
1240
|
+
success: function (data) {
|
1241
|
+
var logText = "Font size data loaded successfully"
|
1242
|
+
logger.info(logText);
|
1243
|
+
state = 'fontsize_data_loaded_success';
|
1244
|
+
logger.info('state: ' + state);
|
1245
|
+
executeFunctionByName('j1.setState', window, state);
|
1246
|
+
|
1247
|
+
if (typeof data == 'string') {
|
1248
|
+
j1_font_sizes = JSON.parse(data);
|
1249
|
+
}
|
1250
|
+
if (typeof data == 'object') {
|
1251
|
+
j1_font_sizes = data;
|
1252
|
+
}
|
1253
|
+
},
|
1254
|
+
error: function (data) {
|
1255
|
+
var logText = "Font size data not loaded"
|
1256
|
+
logger.warn(logText);
|
1257
|
+
state = 'fontsize_data_loaded_failed';
|
1258
|
+
logger.info('state: ' + state);
|
1259
|
+
executeFunctionByName('j1.setState', window, state)
|
1260
|
+
return false;
|
1261
|
+
}
|
1262
|
+
});
|
1263
|
+
|
1264
|
+
}, // END getFontSizeData
|
1265
|
+
|
1266
|
+
// -------------------------------------------------------------------------
|
1267
|
+
// getFontSize: Returns the CSS value for a 'logical' fontsize
|
1268
|
+
// out of the j1_font_sizes object
|
1269
|
+
// -------------------------------------------------------------------------
|
1270
|
+
setFontSize: function (size) {
|
1271
|
+
|
1272
|
+
if ( typeof size != 'undefined' ) {
|
1273
|
+
var reCSS = /\bpx\b|\brem\b|\bem\b|\%|\binherit\b|\binitial\b|\bunset\b/;
|
1274
|
+
var isCSS = size.match(reCSS);
|
1275
|
+
|
1276
|
+
// if ( typeof j1_font_sizes[size] != "undefined" ) {
|
1277
|
+
if ( typeof j1.fonts[size] != "undefined" ) {
|
1278
|
+
return j1.fonts[size];
|
1279
|
+
} else if (isCSS) {
|
1280
|
+
return size;
|
1281
|
+
} else {
|
1282
|
+
return false;
|
1283
|
+
}
|
1284
|
+
} else {
|
1285
|
+
return false;
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
}, // END getFontSize
|
1289
|
+
|
1290
|
+
// -------------------------------------------------------------------------
|
1291
|
+
// loadMessageCatalog
|
1292
|
+
// Loads the message catalog object
|
1293
|
+
// -------------------------------------------------------------------------
|
1294
|
+
getMessageCatalog: function (data_path /*, request_type, data_type*/) {
|
1295
|
+
var logger = log4javascript.getLogger('j1.loadMessageCatalog');
|
1296
|
+
var message_catalog = {};
|
1297
|
+
var type = typeof request_type == 'undefined' || request_type == '' ? 'GET' : request_type;
|
1298
|
+
var data_type = typeof data_type == 'undefined' || data_type == '' ? 'text' : data_type;
|
1299
|
+
var messageData;
|
1300
|
+
var logBase;
|
1301
|
+
var logText;
|
1302
|
+
var property;
|
1303
|
+
|
1304
|
+
return $.ajax({
|
1305
|
+
url: data_path,
|
1306
|
+
type: type,
|
1307
|
+
dataType: data_type,
|
1308
|
+
success: function (data) {
|
1309
|
+
messageData = yaml.safeLoad(data);
|
1310
|
+
for (property in messageData) {
|
1311
|
+
if (messageData.hasOwnProperty(property)) {
|
1312
|
+
message_catalog[property] = {};
|
1313
|
+
messageData[property].forEach((element) => {
|
1314
|
+
var key = Object.keys(element)[0];
|
1315
|
+
var value = element[Object.keys(element)[0]];
|
1316
|
+
message_catalog[property][key] = value;
|
1317
|
+
});
|
1318
|
+
}
|
1319
|
+
}
|
1320
|
+
j1.messages = message_catalog;
|
1321
|
+
logBase = message_catalog.info.getData.message
|
1322
|
+
logText = logBase.text + logBase.message_catalog + logBase.finished;
|
1323
|
+
logger.info(logText);
|
1324
|
+
},
|
1325
|
+
error: function(data) {
|
1326
|
+
var json_data = JSON.stringify(data, undefined, 2);
|
1327
|
+
logBase = message_catalog.error.getData.message;
|
1328
|
+
logText = logBase.text + logBase.xhr + ': ' + json_data
|
1329
|
+
logger.error(logText);
|
1330
|
+
}
|
1331
|
+
});
|
1332
|
+
|
1333
|
+
}, // END getMessageCatalog
|
1334
|
+
|
1335
|
+
// -------------------------------------------------------------------------
|
1336
|
+
// readCookie:
|
1337
|
+
//
|
1338
|
+
// -------------------------------------------------------------------------
|
1339
|
+
readCookie: function (name) {
|
1340
|
+
var data;
|
1341
|
+
var data_json;
|
1342
|
+
data_json = window.atob(Cookies.get(name));
|
1343
|
+
data = JSON.parse(data_json);
|
1344
|
+
|
1345
|
+
if (data) {
|
1346
|
+
return data;
|
1347
|
+
} else {
|
1348
|
+
return false;
|
1349
|
+
}
|
1350
|
+
}, // END readCookie
|
1351
|
+
|
1352
|
+
// -------------------------------------------------------------------------
|
1353
|
+
// writeCookie:
|
1354
|
+
// Write 'data' to a cookie 'name'. If not exists, the cookie gets
|
1355
|
+
// created. Returns 'true' if cookie was written, otherwise 'false'.
|
1356
|
+
//
|
1357
|
+
writeCookie: function (options /*name, data, [path, expires, secure]*/) {
|
1358
|
+
var defaults = {
|
1359
|
+
name: '',
|
1360
|
+
data: {},
|
1361
|
+
path: '/',
|
1362
|
+
expires: 0,
|
1363
|
+
secure: false
|
1364
|
+
};
|
1365
|
+
var args = $.extend(defaults, options);
|
1366
|
+
|
1367
|
+
var epoch = Math.floor(Date.now()/1000);
|
1368
|
+
var timestamp = moment.unix(epoch).format('YYYY-MM-DD hh:mm:ss');
|
1369
|
+
var cookie_data = {};
|
1370
|
+
var data_json;
|
1371
|
+
var data_encoded;
|
1372
|
+
|
1373
|
+
if (j1.existsCookie(args.name)) {
|
1374
|
+
cookie_data = j1.readCookie(args.name);
|
1375
|
+
cookie_data.timestamp = timestamp;
|
1376
|
+
cookie_data = j1.mergeData(cookie_data, args.data);
|
1377
|
+
data_json = JSON.stringify( cookie_data );
|
1378
|
+
data_encoded = window.btoa(data_json);
|
1379
|
+
if (args.expires > 0) {
|
1380
|
+
Cookies.set(args.name, data_encoded, { expires: args.expires });
|
1381
|
+
} else {
|
1382
|
+
Cookies.set(args.name, data_encoded);
|
1383
|
+
}
|
1384
|
+
} else {
|
1385
|
+
cookie_data = args.data
|
1386
|
+
data_json = JSON.stringify( args.data );
|
1387
|
+
data_encoded = window.btoa(data_json);
|
1388
|
+
if (args.expires > 0) {
|
1389
|
+
Cookies.set(args.name, data_encoded, { expires: args.expires });
|
1390
|
+
} else {
|
1391
|
+
Cookies.set(args.name, data_encoded);
|
1392
|
+
}
|
1393
|
+
}
|
1394
|
+
|
1395
|
+
if (j1.existsCookie(args.name)) {
|
1396
|
+
return cookie_data;
|
1397
|
+
} else {
|
1398
|
+
return false;
|
1399
|
+
}
|
1400
|
+
|
1401
|
+
}, // END writeCookie
|
1402
|
+
|
1403
|
+
// -------------------------------------------------------------------------
|
1404
|
+
// Clears all given cookies by name (except cookies set to httpOnly).
|
1405
|
+
// For all cookies the expire date is set in the past, those cookies
|
1406
|
+
// are 'session' cookies. All session cookies are deleted (automatically)
|
1407
|
+
// by the browser if the last session (browser window) is closed.
|
1408
|
+
// See: https://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript
|
1409
|
+
// -------------------------------------------------------------------------
|
1410
|
+
removeCookie: function (options /*name [, path]*/) {
|
1411
|
+
var cookieExists;
|
1412
|
+
var defaults = {
|
1413
|
+
name: '',
|
1414
|
+
path: '/'
|
1415
|
+
};
|
1416
|
+
var args = $.extend(defaults, options);
|
1417
|
+
|
1418
|
+
Cookies.remove(args.name, { path: args.path });
|
1419
|
+
|
1420
|
+
}, // END removeCookie
|
1421
|
+
|
1422
|
+
// -------------------------------------------------------------------------
|
1423
|
+
// Clears all given cookies by name (except cookies set to httpOnly).
|
1424
|
+
// For all cookies the expire date is set in the past, those cookies
|
1425
|
+
// are 'session' cookies. All session cookies are deleted (automatically)
|
1426
|
+
// by the browser if the last session (browser window) is closed.
|
1427
|
+
// See: https://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript
|
1428
|
+
// -------------------------------------------------------------------------
|
1429
|
+
deleteCookie: function (options) {
|
1430
|
+
var name = options;
|
1431
|
+
var all_cookies = document.cookie.split("; ");
|
1432
|
+
|
1433
|
+
if ( name === 'all' ) {
|
1434
|
+
for (var c = 0; c < all_cookies.length; c++) {
|
1435
|
+
var d = window.location.hostname.split(".");
|
1436
|
+
while (d.length > 0) {
|
1437
|
+
var cookieBase = encodeURIComponent(all_cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path=';
|
1438
|
+
var p = location.pathname.split('/');
|
1439
|
+
document.cookie = cookieBase + '/';
|
1440
|
+
while (p.length > 0) {
|
1441
|
+
document.cookie = cookieBase + p.join('/');
|
1442
|
+
p.pop();
|
1443
|
+
};
|
1444
|
+
d.shift();
|
1445
|
+
}
|
1446
|
+
}
|
1447
|
+
} else {
|
1448
|
+
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
1449
|
+
}
|
1450
|
+
|
1451
|
+
return true;
|
1452
|
+
}, // END deleteCookie
|
1453
|
+
|
1454
|
+
// -------------------------------------------------------------------------
|
1455
|
+
// returns true if a given cookie exists
|
1456
|
+
// -------------------------------------------------------------------------
|
1457
|
+
existsCookie: function (name) {
|
1458
|
+
var dc = document.cookie;
|
1459
|
+
var prefix = name + "=";
|
1460
|
+
var begin = dc.indexOf("; " + prefix);
|
1461
|
+
var end = dc.length; // default to end of the string
|
1462
|
+
var cookieExists = false;
|
1463
|
+
var cookieContent = '';
|
1464
|
+
|
1465
|
+
// found, and not in first position
|
1466
|
+
if (begin !== -1) {
|
1467
|
+
// exclude the "; "
|
1468
|
+
begin += 2;
|
1469
|
+
} else {
|
1470
|
+
//see if cookie is in first position
|
1471
|
+
begin = dc.indexOf(prefix);
|
1472
|
+
// not found at all or found as a portion of another cookie name
|
1473
|
+
if (begin === -1 || begin !== 0 ) return null;
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
// if ";" is found somewhere after the prefix position then "end" is
|
1477
|
+
// that position, otherwise it defaults to the end of the string
|
1478
|
+
if (dc.indexOf(";", begin) !== -1) {
|
1479
|
+
end = dc.indexOf(";", begin);
|
1480
|
+
}
|
1481
|
+
|
1482
|
+
cookieContent = decodeURI(dc.substring(begin + prefix.length, end) ).replace(/"/g, '');
|
1483
|
+
cookieExists = cookieContent.length ? true : false;
|
1484
|
+
|
1485
|
+
return cookieExists;
|
1486
|
+
}, // END existsCookie
|
1487
|
+
|
1488
|
+
// -------------------------------------------------------------------------
|
1489
|
+
// Resolve MACROs
|
1490
|
+
//
|
1491
|
+
// See:
|
1492
|
+
// https://stackoverflow.com/questions/5376431/wildcards-in-jquery-selectors
|
1493
|
+
// https://stackoverflow.com/questions/16400072/jquery-each-only-affects-last-element
|
1494
|
+
// https://dzone.com/articles/why-does-javascript-loop-only-use-last-value
|
1495
|
+
// https://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery
|
1496
|
+
// -------------------------------------------------------------------------
|
1497
|
+
resolveMacros: function ( user_data ) {
|
1498
|
+
|
1499
|
+
// default settings
|
1500
|
+
// user_data.theme_author_url = '{{site.data.template_settings.theme_author_url}}'
|
1501
|
+
// user_data.theme_version = j1.getTemplateVersion();
|
1502
|
+
|
1503
|
+
$('[id^=macro-]').each(function() {
|
1504
|
+
|
1505
|
+
$('#macro-provider').each(function() {
|
1506
|
+
var $this = $(this);
|
1507
|
+
var $html = $this.html();
|
1508
|
+
$this.html($html.replace('??provider', user_data.provider));
|
1509
|
+
this.href = this.href.replace(/.*\/??provider-site-url/, user_data.provider_site_url);
|
1510
|
+
});
|
1511
|
+
$('#macro-user-name').each(function() {
|
1512
|
+
var $this = $(this);
|
1513
|
+
var $html = $this.html();
|
1514
|
+
$this.html($html.replace('??user-name', user_data.user_name));
|
1515
|
+
this.href = this.href.replace(/.*\/??provider_member_url/, user_data.provider_member_url);
|
1516
|
+
});
|
1517
|
+
$('#macro-provider-permissions').each(function() {
|
1518
|
+
var $this = $(this);
|
1519
|
+
var $html = $this.html();
|
1520
|
+
$this.html($html.replace('??provider-permissions', user_data.provider_permissions));
|
1521
|
+
this.href = this.href.replace(/.*\/??provider_member_url/, user_data.provider_member_url);
|
1522
|
+
});
|
1523
|
+
$('#macro-provider-membership').each(function() {
|
1524
|
+
var $this = $(this);
|
1525
|
+
var $html = $this.html();
|
1526
|
+
$this.html($html.replace('??provider-membership', user_data.provider_membership));
|
1527
|
+
this.href = this.href.replace(/.*\/??provider_member_url/, user_data.provider_member_url);
|
1528
|
+
});
|
1529
|
+
$('#macro-cookie-state').each(function() {
|
1530
|
+
var $this = $(this);
|
1531
|
+
var $html = $this.html();
|
1532
|
+
$this.html($html.replace('??cookie-state', user_data.cookies_accepted));
|
1533
|
+
this.href = this.href.replace(/.*\/??provider_privacy_url/, user_data.provider_privacy_url);
|
1534
|
+
});
|
1535
|
+
$('#macro-theme-name').each(function() {
|
1536
|
+
var $this = $(this);
|
1537
|
+
var $html = $this.html();
|
1538
|
+
$this.html($html.replace('??theme-name', user_data.theme_name));
|
1539
|
+
});
|
1540
|
+
$('#macro-theme-author').each(function() {
|
1541
|
+
var $this = $(this);
|
1542
|
+
var $html = $this.html();
|
1543
|
+
$this.html($html.replace('??theme-author', user_data.theme_author));
|
1544
|
+
this.href = this.href.replace(/.*\/??theme-author-url/, user_data.theme_author_url);
|
1545
|
+
});
|
1546
|
+
$('#macro-theme-version').each(function() {
|
1547
|
+
var $this = $(this);
|
1548
|
+
var $html = $this.html();
|
1549
|
+
$this.html($html.replace('??theme-version', user_data.theme_version));
|
1550
|
+
});
|
1551
|
+
|
1552
|
+
});
|
1553
|
+
|
1554
|
+
return true;
|
1555
|
+
}, // END resolveMacros
|
1556
|
+
|
1557
|
+
// -------------------------------------------------------------------------
|
1558
|
+
// Update MACROs
|
1559
|
+
// Update the values, NOT the placeholders
|
1560
|
+
// -------------------------------------------------------------------------
|
1561
|
+
updateMacros: function ( user_data ) {
|
1562
|
+
|
1563
|
+
$('[id^=macro-]').each(function() {
|
1564
|
+
|
1565
|
+
$('#macro-provider').each(function() {
|
1566
|
+
var $this = $(this);
|
1567
|
+
var $html = $this.html();
|
1568
|
+
$this.html($html.replace(/Provider:.*/, 'Provider: ' + user_data.provider));
|
1569
|
+
$('#macro-provider').attr("href", user_data.provider_site_url);
|
1570
|
+
});
|
1571
|
+
$('#macro-user-name').each(function() {
|
1572
|
+
var $this = $(this);
|
1573
|
+
var $html = $this.html();
|
1574
|
+
$this.html($html.replace(/User:.*/, 'User: ' + user_data.user_name));
|
1575
|
+
$('#macro-user-name').attr("href", user_data.provider_member_url);
|
1576
|
+
});
|
1577
|
+
$('#macro-provider-permissions').each(function() {
|
1578
|
+
var $this = $(this);
|
1579
|
+
var $html = $this.html();
|
1580
|
+
// $this.html($html.replace(/public|protected|private|blocked/, user_data.provider_permissions));
|
1581
|
+
$this.html($html.replace(/public.*|protected.*|private.*|blocked.*/, user_data.provider_permissions));
|
1582
|
+
$('#macro-provider-permissions').attr("href", user_data.provider_member_url);
|
1583
|
+
});
|
1584
|
+
$('#macro-provider-membership').each(function() {
|
1585
|
+
var $this = $(this);
|
1586
|
+
var $html = $this.html();
|
1587
|
+
$this.html($html.replace(/guest|member/, user_data.provider_membership));
|
1588
|
+
$('#macro-provider-membership').attr("href", user_data.provider_member_url);
|
1589
|
+
});
|
1590
|
+
$('#macro-cookie-state').each(function() {
|
1591
|
+
var $this = $(this);
|
1592
|
+
var $html = $this.html();
|
1593
|
+
$this.html($html.replace(/accepted|declined|pending/, user_data.cookies_accepted));
|
1594
|
+
$('#macro-cookie-state').attr("href", user_data.provider_privacy_url);
|
1595
|
+
});
|
1596
|
+
|
1597
|
+
});
|
1598
|
+
|
1599
|
+
return true;
|
1600
|
+
}, // END updateMacros
|
1601
|
+
|
1602
|
+
// -------------------------------------------------------------------------
|
1603
|
+
// getMessage
|
1604
|
+
// Get a log message from the log message catalog object
|
1605
|
+
// -------------------------------------------------------------------------
|
1606
|
+
getMessage: function (level, message, property) {
|
1607
|
+
var message = j1.messages[level][message]["message"][property];
|
1608
|
+
|
1609
|
+
return message;
|
1610
|
+
}, // END getMessage
|
1611
|
+
|
1612
|
+
// -------------------------------------------------------------------------
|
1613
|
+
// logger
|
1614
|
+
// Log a message
|
1615
|
+
// -------------------------------------------------------------------------
|
1616
|
+
logger: function (logger, level, message) {
|
1617
|
+
var logger = log4javascript.getLogger(logger);
|
1618
|
+
|
1619
|
+
logger[level](message);
|
1620
|
+
|
1621
|
+
return true;
|
1622
|
+
}, // END logger
|
1623
|
+
|
1624
|
+
// -------------------------------------------------------------------------
|
1625
|
+
// getBaseUrl
|
1626
|
+
// -------------------------------------------------------------------------
|
1627
|
+
// getBaseUrl: function () {
|
1628
|
+
// var myUrl = window.location.href;
|
1629
|
+
// var ua = platform.name.toLowerCase();
|
1630
|
+
// var reURL = new RegExp('(http[s]?:\/\/)?([^\/]+)(.*)');
|
1631
|
+
// var baseUrl;
|
1632
|
+
// //var reGroups;
|
1633
|
+
//
|
1634
|
+
// // NOTE: named capture groups NOT supported by FF + IE11
|
1635
|
+
// // if ( ua === 'chrome' ) {
|
1636
|
+
// // reURL = new RegExp('(?<prot>http[s]?:\/\/)?(?<host>[^\/]+)(?<path>.*)');
|
1637
|
+
// // reGroups = myUrl.match(reURL).groups;
|
1638
|
+
// // baseUrl = reGroups.prot + reGroups.host;
|
1639
|
+
// // } else {
|
1640
|
+
// // reURL = new RegExp('(http[s]?:\/\/)?([^\/]+)(.*)');
|
1641
|
+
// // myUrl.match(reURL);
|
1642
|
+
// // baseUrl = RegExp.$1 + RegExp.$2 + RegExp.$3;
|
1643
|
+
// // }
|
1644
|
+
//
|
1645
|
+
// myUrl.match(reURL);
|
1646
|
+
// // baseUrl = RegExp.$1 + RegExp.$2 + RegExp.$3;
|
1647
|
+
// baseUrl = RegExp.$1 + RegExp.$2;
|
1648
|
+
//
|
1649
|
+
// return baseUrl;
|
1650
|
+
// }, // END getBaseUrl
|
1651
|
+
|
1652
|
+
// -------------------------------------------------------------------------
|
1653
|
+
// getPath
|
1654
|
+
// See: https://stackoverflow.com/questions/27745/getting-parts-of-a-url-regex
|
1655
|
+
// -------------------------------------------------------------------------
|
1656
|
+
// getPath: function ( myUrl ) {
|
1657
|
+
// var url = new parseURL(myUrl)
|
1658
|
+
// // var reURL = new RegExp('(http[s]?:\/\/)?([^\/]+)(.*)');
|
1659
|
+
// // var path;
|
1660
|
+
// //
|
1661
|
+
// // myUrl.match(reURL);
|
1662
|
+
// path = url.path;
|
1663
|
+
//
|
1664
|
+
// return path;
|
1665
|
+
// }, // END getPath
|
1666
|
+
|
1667
|
+
// -------------------------------------------------------------------------
|
1668
|
+
// Send message
|
1669
|
+
// -------------------------------------------------------------------------
|
1670
|
+
sendMessage: function ( sender, receiver, message ) {
|
1671
|
+
var logger = log4javascript.getLogger('j1.sendMessage');
|
1672
|
+
var json_message = JSON.stringify(message, undefined, 2);
|
1673
|
+
|
1674
|
+
if ( receiver === 'j1' ) {
|
1675
|
+
logText = 'Send message from ' + sender + ' to' + receiver + ': ' + json_message;
|
1676
|
+
logger.debug(logText);
|
1677
|
+
executeFunctionByName('j1' + '.messageHandler', window, sender, message)
|
1678
|
+
} else {
|
1679
|
+
logText = 'Send message from ' + sender + ' to ' + receiver + ': ' + json_message;
|
1680
|
+
logger.debug(logText);
|
1681
|
+
//executeFunctionByName('j1.' + receiver + '.messageHandler', window, sender, message)
|
1682
|
+
executeFunctionByName(receiver + '.messageHandler', window, sender, message)
|
1683
|
+
}
|
1684
|
+
|
1685
|
+
}, // END sendMessage
|
1686
|
+
|
1687
|
+
// -------------------------------------------------------------------------
|
1688
|
+
// messageHandler: MessageHandler for J1 CookieConsent module
|
1689
|
+
// Manage messages send from other J1 modules
|
1690
|
+
// -------------------------------------------------------------------------
|
1691
|
+
messageHandler: function ( sender, message ) {
|
1692
|
+
var json_message = JSON.stringify(message, undefined, 2);
|
1693
|
+
|
1694
|
+
logText = 'Received message from ' + sender + ': ' + json_message;
|
1695
|
+
logger.debug(logText);
|
1696
|
+
|
1697
|
+
// -----------------------------------------------------------------------
|
1698
|
+
// Process commands|actions
|
1699
|
+
// -----------------------------------------------------------------------
|
1700
|
+
if ( message.type === 'command' && message.action === 'module_initialized' ) {
|
1701
|
+
_this.setState('finished');
|
1702
|
+
logger.info(message.text);
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
//
|
1706
|
+
// Place handling of other command|action here
|
1707
|
+
//
|
1708
|
+
|
1709
|
+
return true;
|
1710
|
+
}, // END messageHandler
|
1711
|
+
|
1712
|
+
// -------------------------------------------------------------------------
|
1713
|
+
// getStyleValue:
|
1714
|
+
// returns the value of a style from a css class definition
|
1715
|
+
// example: j1.getStyleValue('bg-primary', 'background-color')
|
1716
|
+
getStyleValue: function (className, style) {
|
1717
|
+
var elementId = 'test-' + className,
|
1718
|
+
testElement = document.getElementById(elementId),
|
1719
|
+
val;
|
1720
|
+
|
1721
|
+
if (testElement === null) {
|
1722
|
+
testElement = document.createElement('div');
|
1723
|
+
testElement.className = className;
|
1724
|
+
testElement.style.display = 'none';
|
1725
|
+
document.body.appendChild(testElement);
|
1726
|
+
}
|
1727
|
+
val = $(testElement).css(style);
|
1728
|
+
document.body.removeChild(testElement);
|
1729
|
+
|
1730
|
+
return val;
|
1731
|
+
}, // END getStyleValue
|
1732
|
+
|
1733
|
+
// -------------------------------------------------------------------------
|
1734
|
+
// Returns the names of cookies used for J1 Template
|
1735
|
+
// -------------------------------------------------------------------------
|
1736
|
+
getCookieNames: function () {
|
1737
|
+
return cookie_names;
|
1738
|
+
}, // end getCookieNames
|
1739
|
+
|
1740
|
+
// ---------------------------------------------------------------------
|
1741
|
+
// Set dynamic styles
|
1742
|
+
// ---------------------------------------------------------------------
|
1743
|
+
setCss: function () {
|
1744
|
+
var bg_primary = j1.getStyleValue('bg-primary', 'background-color');
|
1745
|
+
|
1746
|
+
$('head').append('<style>.mdi-md-bg-primary { color: ' +bg_primary+ ' !important; }</style>');
|
1747
|
+
$('head').append('<style>.g-bg-primary { color: ' +bg_primary+ ' !important; }</style>');
|
1748
|
+
|
1749
|
+
var admonitionblock_note_color = j1.getStyleValue('btn-info', 'background-color');
|
1750
|
+
var admonitionblock_tip_color = j1.getStyleValue('btn-success', 'background-color');
|
1751
|
+
var admonitionblock_important_color = j1.getStyleValue('btn-warning', 'background-color');
|
1752
|
+
var admonitionblock_warning_color = j1.getStyleValue('icon-warning', 'color');
|
1753
|
+
var admonitionblock_caution_color = j1.getStyleValue('btn-danger', 'background-color');
|
1754
|
+
|
1755
|
+
var tabs_pills_link_color_active = j1.setColorData('md_blue'); // j1.getStyleValue('btn-info', 'background-color');
|
1756
|
+
var tabs_pills_link_color_hover = j1.setColorData('md_gray_300'); // j1.getStyleValue('btn-secondary', 'background-color');
|
1757
|
+
|
1758
|
+
$('head').append('<style>.g-bg-primary { background-color: ' +bg_primary+ ' !important; }</style>');
|
1759
|
+
$('head').append('<style>.mdi-md-bg-primary { color: ' +bg_primary+ '; }</style>');
|
1760
|
+
|
1761
|
+
$('head').append('<style>.nav-link:hover { background-color: ' +tabs_pills_link_color_hover+ ' !important; }</style>');
|
1762
|
+
$('head').append('<style>.nav-link.active { background-color: ' +tabs_pills_link_color_active+ ' !important; }</style>');
|
1763
|
+
|
1764
|
+
$('head').append('<style>.icon-note { color: ' +admonitionblock_note_color+ ' !important; }</style>');
|
1765
|
+
$('head').append('<style>.icon-tip { color: ' +admonitionblock_tip_color+ ' !important; }</style>');
|
1766
|
+
$('head').append('<style>.icon-important { color: ' +admonitionblock_important_color+ ' !important; }</style>');
|
1767
|
+
$('head').append('<style>.icon-warning { color: ' +admonitionblock_warning_color+ ' !important; }</style>');
|
1768
|
+
$('head').append('<style>.icon-caution { color: ' +admonitionblock_caution_color+ ' !important; }</style>');
|
1769
|
+
|
1770
|
+
return true;
|
1771
|
+
}, // END setCss
|
1772
|
+
|
1773
|
+
// -------------------------------------------------------------------------
|
1774
|
+
// Set the current (processing) state of the module
|
1775
|
+
// -------------------------------------------------------------------------
|
1776
|
+
setState: function (stat) {
|
1777
|
+
state= stat;
|
1778
|
+
//j1.state stat;
|
1779
|
+
}, // end setState
|
1780
|
+
|
1781
|
+
// -------------------------------------------------------------------------
|
1782
|
+
// Returns the current (processing) state of the module
|
1783
|
+
// -------------------------------------------------------------------------
|
1784
|
+
getState: function () {
|
1785
|
+
// return j1.state;
|
1786
|
+
return state;
|
1787
|
+
}, // end getState
|
1788
|
+
|
1789
|
+
// -------------------------------------------------------------------------
|
1790
|
+
// Set the current mode of the site (web|app)
|
1791
|
+
// -------------------------------------------------------------------------
|
1792
|
+
setMode: function (mod) {
|
1793
|
+
mode = mod;
|
1794
|
+
}, // END setMode
|
1795
|
+
|
1796
|
+
// -------------------------------------------------------------------------
|
1797
|
+
// Return the current mode of the site (web|app)
|
1798
|
+
// -------------------------------------------------------------------------
|
1799
|
+
getMode: function () {
|
1800
|
+
return mode;
|
1801
|
+
}, // END getMode
|
1802
|
+
|
1803
|
+
// -------------------------------------------------------------------------
|
1804
|
+
// getUserAgent
|
1805
|
+
// Return the name of the web browser
|
1806
|
+
// -------------------------------------------------------------------------
|
1807
|
+
checkUserAgent: function (ua_name) {
|
1808
|
+
if (navigator.userAgent.search(ua_name) >= 0) {
|
1809
|
+
return true;
|
1810
|
+
} else {
|
1811
|
+
return false;
|
1812
|
+
}
|
1813
|
+
}, // END checkUserAgent
|
1814
|
+
|
1815
|
+
// -------------------------------------------------------------------------
|
1816
|
+
// Return always true (for testing purposes)
|
1817
|
+
// -------------------------------------------------------------------------
|
1818
|
+
getTrue: function () {
|
1819
|
+
return true;
|
1820
|
+
}, // END isTrue
|
1821
|
+
|
1822
|
+
// -------------------------------------------------------------------------
|
1823
|
+
// Return always false (for testing purposes)
|
1824
|
+
// -------------------------------------------------------------------------
|
1825
|
+
getFalse: function () {
|
1826
|
+
return false;
|
1827
|
+
}, // END isTrue
|
1828
|
+
|
1829
|
+
} // END j1 (return)
|
1830
|
+
}) (j1, window);
|
1831
|
+
|
1832
|
+
{% endcapture %}
|
1833
|
+
|
1834
|
+
{{ cache | strip_empty_lines }}
|
1835
|
+
{% assign cache = nil %}
|