j1-template 2021.1.6 → 2021.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
1
+ ---
2
+ regenerate: true
3
+ ---
4
+
5
+ {% capture cache %}
6
+
7
+ {% comment %}
8
+ # -----------------------------------------------------------------------------
9
+ # ~/assets/themes/j1/adapter/js/themer.js
10
+ # Liquid template to adapt theme functions
11
+ #
12
+ # Product/Info:
13
+ # https://jekyll.one
14
+ #
15
+ # Copyright (C) 2021 Juergen Adams
16
+ #
17
+ # J1 Template is licensed under the MIT License.
18
+ # For details, see https://jekyll.one
19
+ #
20
+ # -----------------------------------------------------------------------------
21
+ # Test data:
22
+ # {{config| debug }}
23
+ # -----------------------------------------------------------------------------
24
+ {% endcomment %}
25
+
26
+ {% comment %} Liquid procedures
27
+ -------------------------------------------------------------------------------- {% endcomment %}
28
+
29
+ {% comment %} Set global settings
30
+ -------------------------------------------------------------------------------- {% endcomment %}
31
+ {% assign environment = site.environment %}
32
+ {% assign template_version = site.version %}
33
+ {% assign asset_path = "/assets/themes/j1" %}
34
+
35
+ {% comment %} Process YML config data
36
+ ================================================================================ {% endcomment %}
37
+
38
+ {% comment %} Set config files
39
+ -------------------------------------------------------------------------------- {% endcomment %}
40
+ {% assign template_config = site.data.j1_config %}
41
+ {% assign blocks = site.data.blocks %}
42
+ {% assign modules = site.data.modules %}
43
+
44
+ {% comment %} Set config data
45
+ -------------------------------------------------------------------------------- {% endcomment %}
46
+ {% assign themer_defaults = modules.defaults.themer.defaults %}
47
+ {% assign themer_settings = modules.themer.settings %}
48
+
49
+ {% comment %} Set config options
50
+ -------------------------------------------------------------------------------- {% endcomment %}
51
+ {% assign themer_options = themer_defaults| merge: themer_settings %}
52
+ {% assign default_theme = template_config.theme %}
53
+ {% assign theme_base = "core/css/themes" %}
54
+
55
+ {% if environment == "development" or environment == "test" %}
56
+ {% assign theme_ext = "css" %}
57
+ {% else %}
58
+ {% assign theme_ext = "min.css" %}
59
+ {% endif %}
60
+
61
+ {% assign production = false %}
62
+ {% if environment == 'prod' or environment == 'production' %}
63
+ {% assign production = true %}
64
+ {% endif %}
65
+
66
+ /*
67
+ # -----------------------------------------------------------------------------
68
+ # ~/assets/themes/j1/adapter/js/themer.js
69
+ # JS Adapter for J1 themer (bootstrapThemeSwitcher)
70
+ #
71
+ # Product/Info:
72
+ # https://jekyll.one
73
+ # https://github.com/jguadagno/bootstrapThemeSwitcher
74
+ #
75
+ # Copyright (C) 2021 Juergen Adams
76
+ # Copyright (C) 2014 Joseph Guadagno
77
+ #
78
+ # J1 Template is licensed under the MIT License.
79
+ # For details, see https://jekyll.one
80
+ # bootstrapThemeSwitcher is licensed under the MIT License.
81
+ # For details, see https://github.com/jguadagno/bootstrapThemeSwitcher/blob/master/LICENSE
82
+ # -----------------------------------------------------------------------------
83
+ # NOTE:
84
+ # Setup of theme loaders for local_themes|remote_themes moved
85
+ # to adapter navigator.js
86
+ # -----------------------------------------------------------------------------
87
+ # Adapter generated: {{site.time}}
88
+ # -----------------------------------------------------------------------------
89
+ */
90
+
91
+ // -----------------------------------------------------------------------------
92
+ // ESLint shimming
93
+ // -----------------------------------------------------------------------------
94
+ /* eslint indent: "off" */
95
+ /* eslint quotes: "off" */
96
+ // -----------------------------------------------------------------------------
97
+
98
+ 'use strict';
99
+
100
+ j1.adapter['themer'] = (function (j1, window) {
101
+ // ---------------------------------------------------------------------------
102
+ // globals
103
+ // ---------------------------------------------------------------------------
104
+ var environment = '{{environment}}';
105
+ var themerOptions = $.extend({}, {{themer_options | replace: '=>', ':' | replace: 'nil', '""' }});
106
+ var user_state = {};
107
+ var user_consent = {};
108
+ var cookie_names = j1.getCookieNames();
109
+ var user_state_detected = false;
110
+ var styleLoaded = false;
111
+ var id = 'default';
112
+ var user_state_cookie;
113
+ var theme_css_html;
114
+ var _this;
115
+ var logger;
116
+ var logText;
117
+
118
+ var cssExtension = (environment === 'production')
119
+ ? '.min.css'
120
+ : '.css';
121
+
122
+ var default_theme_name = '{{default_theme.name}}';
123
+ var default_theme_author = '{{default_theme.author}}';
124
+ var default_theme_author_url = '{{default_theme.author_url}}';
125
+ var default_theme_css_name = default_theme_name.toLowerCase().replace(' ', '-');
126
+ var default_theme_css = '{{asset_path}}/{{theme_base}}/' + default_theme_css_name + '/bootstrap' + cssExtension;
127
+
128
+ // ---------------------------------------------------------------------------
129
+ // helper functions
130
+ // ---------------------------------------------------------------------------
131
+
132
+ function styleSheetLoaded(styleSheet) {
133
+ var sheets = document.styleSheets, stylesheet = sheets[(sheets.length - 1)];
134
+
135
+ // find CSS file 'styleSheetName' in document
136
+ for(var i in document.styleSheets) {
137
+ if(sheets[i].href && sheets[i].href.indexOf(styleSheet) > -1) {
138
+ return true;
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+
144
+ // ---------------------------------------------------------------------------
145
+ // Main object
146
+ // ---------------------------------------------------------------------------
147
+ return {
148
+ // -------------------------------------------------------------------------
149
+ // initializer
150
+ // -------------------------------------------------------------------------
151
+ init: function () {
152
+ // -----------------------------------------------------------------------
153
+ // globals
154
+ // -----------------------------------------------------------------------
155
+ _this = j1.adapter.themer;
156
+ logger = log4javascript.getLogger('j1.adapter.themer');
157
+
158
+ // initialize state flag
159
+ _this.state = 'started';
160
+ logger.info('state: ' + _this.getState());
161
+
162
+ // detect|set user state cookie
163
+ user_state_detected = j1.existsCookie(cookie_names.user_state);
164
+ if (user_state_detected) {
165
+ user_state = j1.readCookie(cookie_names.user_state);
166
+ user_consent = j1.readCookie(cookie_names.user_consent);
167
+ }
168
+
169
+ // initial theme data
170
+ if (user_state.theme_css === '') {
171
+ user_state.theme_name = default_theme_name;
172
+ user_state.theme_css = default_theme_css;
173
+ user_state.theme_author = default_theme_author;
174
+ user_state.theme_author_url = default_theme_author_url;
175
+ }
176
+
177
+ styleLoaded = styleSheetLoaded(user_state.theme_css);
178
+ theme_css_html = '<link rel="stylesheet" id="' + id + '" href="' + user_state.theme_css + '" type="text/css" />';
179
+
180
+ // skip loading theme UNO css file except NOT loaded
181
+ if (!user_state.theme_name.includes('Uno') || !styleLoaded) {
182
+ $('head').append(theme_css_html);
183
+ }
184
+
185
+ // store if theme_switcher is enabled
186
+ user_state.theme_switcher = themerOptions.enabled;
187
+
188
+ if (!user_consent.analyses || !user_consent.personalization) {
189
+ // expire state cookie to session
190
+ j1.writeCookie({
191
+ name: cookie_names.user_state,
192
+ data: user_state,
193
+ samesite: 'Strict'
194
+ });
195
+ } else {
196
+ j1.writeCookie({
197
+ name: cookie_names.user_state,
198
+ data: user_state,
199
+ samesite: 'Strict',
200
+ expires: 365
201
+ });
202
+ }
203
+
204
+ // jadams, 2021-01-03: dependency has to be checked in more detail
205
+ var dependencies_met_j1_finished = setInterval (function () {
206
+ if (j1.getState() == 'finished') {
207
+ if (themerOptions.enabled) {
208
+ // enable BS ThemeSwitcher
209
+ logger.info('themes detected as: enabled');
210
+ logger.info('theme is being initialized: ' + user_state.theme_name);
211
+
212
+ // jadams, 2021-02-22: make sure that remote themes are loaded
213
+ // max retries = max_count
214
+
215
+ // load list of remote themes
216
+ //
217
+ if ( $('#remote_themes').length ) {
218
+ var themes_count;
219
+ var interval_count = 0;
220
+ var max_count = themerOptions.retries;
221
+
222
+ /* eslint-disable */
223
+ // initialize Bootswatch Theme Switcher
224
+ $('#remote_themes').bootstrapThemeSwitcher.defaults = {
225
+ debug: themerOptions.debug,
226
+ saveToCookie: themerOptions.saveToCookie,
227
+ cssThemeLink: themerOptions.cssThemeLink,
228
+ cookieThemeName: themerOptions.cookieThemeName,
229
+ cookieDefaultThemeName: themerOptions.cookieDefaultThemeName,
230
+ cookieThemeCss: themerOptions.cookieThemeCss,
231
+ cookieThemeExtensionCss: themerOptions.cookieThemeExtensionCss,
232
+ cookieExpiration: themerOptions.cookieExpiration,
233
+ cookiePath: themerOptions.cookiePath,
234
+ defaultCssFile: themerOptions.defaultCssFile,
235
+ bootswatchApiUrl: themerOptions.bootswatchApiUrl,
236
+ bootswatchApiVersion: themerOptions.bootswatchApiVersion,
237
+ loadFromBootswatch: themerOptions.loadFromBootswatch,
238
+ localFeed: themerOptions.localThemes,
239
+ excludeBootswatch: themerOptions.excludeBootswatch,
240
+ includeBootswatch: themerOptions.includeBootswatch,
241
+ skipIncludeBootswatch: themerOptions.skipIncludeBootswatch
242
+ }
243
+ /* eslint-enable */
244
+
245
+ // var dependencies_met_remote_themes_loaded = setInterval(function() {
246
+ // interval_count += 1;
247
+ // themes_count = document.getElementById("remote_themes").getElementsByTagName("li").length;
248
+ // if ( themes_count > 0 ) {
249
+ // logger.info('remote themes loaded: successfully');
250
+ // logger.info('remote themes loaded: successfully after: ' + interval_count * 25 + ' ms');
251
+ //
252
+ // clearInterval(dependencies_met_remote_themes_loaded);
253
+ // } else {
254
+ // logger.debug('wait for theme to be loaded: ' + user_state.theme_name);
255
+ // }
256
+ // if (interval_count > max_count) {
257
+ // logger.warn('remote themes loading: failed');
258
+ // logger.warn('continue processing');
259
+ // clearInterval(dependencies_met_remote_themes_loaded);
260
+ // }
261
+ // }, 25);
262
+
263
+ logger.info('theme loaded: ' + user_state.theme_name);
264
+ logger.info('theme css file: ' + user_state.theme_css);
265
+ _this.setState('finished');
266
+ logger.info('state: ' + _this.getState());
267
+ logger.info('module initialized successfully');
268
+ logger.info('met dependencies for: j1.adapter');
269
+ }
270
+ } else {
271
+ _this.setState('finished');
272
+ logger.info('state: ' + _this.getState());
273
+ logger.info('themes detected as: disabled');
274
+ }
275
+ clearInterval(dependencies_met_j1_finished);
276
+ }
277
+ }, 25); // END 'dependencies_met_j1_finished'
278
+ }, // END init
279
+
280
+ // -------------------------------------------------------------------------
281
+ // messageHandler
282
+ // Manage messages send from other J1 modules
283
+ // -------------------------------------------------------------------------
284
+ messageHandler: function (sender, message) {
285
+ var json_message = JSON.stringify(message, undefined, 2);
286
+
287
+ logText = 'received message from ' + sender + ': ' + json_message;
288
+ logger.info(logText);
289
+
290
+ // -----------------------------------------------------------------------
291
+ // Process commands|actions
292
+ // -----------------------------------------------------------------------
293
+ if (message.type === 'command' && message.action === 'module_initialized') {
294
+ logger.info(message.text);
295
+ //
296
+ // Place handling of other command|action here
297
+ //
298
+ }
299
+ }, // END messageHandler
300
+
301
+ // -------------------------------------------------------------------------
302
+ // setState()
303
+ // Sets the current (processing) state of the module
304
+ // -------------------------------------------------------------------------
305
+ setState: function (stat) {
306
+ _this.state = stat;
307
+ }, // END setState
308
+
309
+ // -------------------------------------------------------------------------
310
+ // getState()
311
+ // Returns the current (processing) state of the module
312
+ // -------------------------------------------------------------------------
313
+ getState: function () {
314
+ return _this.state;
315
+ } // END getState
316
+
317
+ }; // END return
318
+ })(j1, window);
319
+
320
+ {% endcapture %}
321
+ {% if production %}
322
+ {{cache| minifyJS }}
323
+ {% else %}
324
+ {{cache| strip_empty_lines }}
325
+ {% endif %}
326
+ {% assign cache = nil %}
@@ -201,24 +201,18 @@ j1.adapter['themer'] = (function (j1, window) {
201
201
  });
202
202
  }
203
203
 
204
- // jadams, 2021-01-03: dependency has to be checked in more detail
205
204
  var dependencies_met_j1_finished = setInterval (function () {
206
- if (j1.getState() == 'finished') {
205
+ // jadams, 2021-01-03: dependency has to be checked in more detail
206
+ // if (j1.getState() == 'finished') {
207
+ if (true) {
207
208
  if (themerOptions.enabled) {
208
209
  // enable BS ThemeSwitcher
209
210
  logger.info('themes detected as: enabled');
210
211
  logger.info('theme is being initialized: ' + user_state.theme_name);
211
212
 
212
- // jadams, 2021-02-22: make sure that remote themes are loaded
213
- // max retries = max_count
214
-
215
213
  // load list of remote themes
216
214
  //
217
- if ( $('#remote_themes').length ) {
218
- var themes_count;
219
- var interval_count = 0;
220
- var max_count = themerOptions.retries;
221
-
215
+ if ($('#remote_themes').length) {
222
216
  /* eslint-disable */
223
217
  // initialize Bootswatch Theme Switcher
224
218
  $('#remote_themes').bootstrapThemeSwitcher.defaults = {
@@ -242,24 +236,6 @@ j1.adapter['themer'] = (function (j1, window) {
242
236
  }
243
237
  /* eslint-enable */
244
238
 
245
- var dependencies_met_remote_themes_loaded = setInterval(function() {
246
- interval_count += 1;
247
- themes_count = document.getElementById("remote_themes").getElementsByTagName("li").length;
248
- if ( themes_count > 0 ) {
249
- logger.info('remote themes loaded: successfully');
250
- logger.info('remote themes loaded: successfully after: ' + interval_count * 25 + ' ms');
251
-
252
- clearInterval(dependencies_met_remote_themes_loaded);
253
- } else {
254
- logger.debug('wait for theme to be loaded: ' + user_state.theme_name);
255
- }
256
- if (interval_count > max_count) {
257
- logger.warn('remote themes loading: failed');
258
- logger.warn('continue processing');
259
- clearInterval(dependencies_met_remote_themes_loaded);
260
- }
261
- }, 25);
262
-
263
239
  logger.info('theme loaded: ' + user_state.theme_name);
264
240
  logger.info('theme css file: ' + user_state.theme_css);
265
241
  _this.setState('finished');
@@ -1,286 +1,286 @@
1
- /*
2
- # -----------------------------------------------------------------------------
3
- # ~/assets/themes/j1/modules/cookieConsent/js/cookieConsent.js
4
- # Provides JS Core for J1 Module BS Cookie Consent
5
- #
6
- # Product/Info:
7
- # https://shaack.com
8
- # http://jekyll.one
9
- #
10
- # Copyright (C) 2020 Stefan Haack
11
- # Copyright (C) 2021 Juergen Adams
12
- #
13
- # bootstrap-cookie-banner is licensed under MIT License.
14
- # See: https://github.com/shaack/bootstrap-cookie-banner/blob/master/LICENSE
15
- # J1 Template is licensed under MIT License.
16
- # See: https://github.com/jekyll-one/J1 Template/blob/master/LICENSE
17
- # -----------------------------------------------------------------------------
18
- # TODO:
19
- #
20
- # -----------------------------------------------------------------------------
21
- # NOTE:
22
- # BS Cookie Consent is a MODIFIED version of bootstrap-cookie-banner
23
- # for the use with J1 Template. This modified version cannot be used
24
- # outside of J1 Template!
25
- # -----------------------------------------------------------------------------
26
- */
27
- 'use strict';
28
-
29
- // -----------------------------------------------------------------------------
30
- // ESLint shimming
31
- // -----------------------------------------------------------------------------
32
- /* eslint indent: "off" */
33
- /* eslint no-unused-vars: "off" */
34
- /* eslint no-undef: "off" */
35
- /* eslint no-redeclare: "off" */
36
- /* eslint indent: "off" */
37
- /* eslint JSUnfilteredForInLoop: "off" */
38
- // -----------------------------------------------------------------------------
39
-
40
- function BootstrapCookieConsent(props) {
41
- var logText;
42
- var current_page;
43
- var whitelisted;
44
- var logger = log4javascript.getLogger('j1.core.bsCookieConsent');
45
- var modalId = "bccs-modal"
46
- var self = this
47
- var detailedSettingsShown = false
48
-
49
- this.props = {
50
- autoShowDialog: true, // disable autoShowModal on the privacy policy and legal notice pages, to make these pages readable
51
- language: navigator.language, // the language, in which the modal is shown
52
- languages: ["en", "de"], // supported languages (in ./content/), defaults to first in array
53
- contentURL: "./content", // this URL must contain the dialogs content in the needed languages
54
- cookieName: "cookie-consent-settings", // the name of the cookie in which the configuration is stored as JSON
55
- cookieStorageDays: 365, // the duration the cookie configuration is stored on the client
56
- postSelectionCallback: undefined, // callback function, called after the user has made his selection
57
- whitelisted: [], // pages NO consent modal page is issued
58
- xhr_data_element: "" // container for the language-specific consent modal taken from /assets/data/cookieconsent.html
59
- }
60
-
61
- for (var property in props) {
62
- this.props[property] = props[property];
63
- }
64
-
65
- this.language = this.props.language
66
- if (this.language.indexOf("-") !== -1) {
67
- this.language = this.language.split("-")[0];
68
- }
69
-
70
- if (!this.props.languages.includes(this.language)) {
71
- this.language = this.props.languages[0]; // fallback on default language
72
- }
73
-
74
- var Cookie = {
75
- set: function (name, value, days) {
76
- var value_encoded = window.btoa(value);
77
- var expires = "";
78
- if (days) {
79
- var date = new Date();
80
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
81
- expires = "; expires=" + date.toUTCString();
82
- }
83
- document.cookie = name + "=" + (value_encoded || "") + expires + "; Path=/; SameSite=Strict;";
84
- },
85
- get: function (name) {
86
- var nameEQ = name + "=";
87
- var ca = document.cookie.split(';');
88
- for (var i = 0; i < ca.length; i++) {
89
- var c = ca[i];
90
- while (c.charAt(0) === ' ') {
91
- c = c.substring(1, c.length);
92
- }
93
- if (c.indexOf(nameEQ) === 0) {
94
- var value_encoded = c.substring(nameEQ.length, c.length);
95
- var value = window.atob(value_encoded);
96
- return value;
97
- }
98
- }
99
- return undefined
100
- }
101
- }
102
-
103
- var Events = {
104
- documentReady: function (onDocumentReady) {
105
- if (document.readyState !== 'loading') {
106
- onDocumentReady();
107
- } else {
108
- document.addEventListener('DOMContentLoaded', onDocumentReady);
109
- }
110
- }
111
- }
112
-
113
- function showDialog(options) {
114
- Events.documentReady(function () {
115
- self.modal = document.getElementById(modalId);
116
-
117
- if (!self.modal) {
118
- self.modal = document.createElement("div");
119
- self.modal.id = modalId;
120
- self.modal.setAttribute("class", "modal fade");
121
- self.modal.setAttribute("tabindex", "-1");
122
- self.modal.setAttribute("role", "dialog");
123
- self.modal.setAttribute("aria-labelledby", modalId);
124
- document.body.append(self.modal);
125
- self.$modal = $(self.modal);
126
-
127
- if (self.props.postSelectionCallback) {
128
- self.$modal.on("hidden.bs.modal", function () {
129
- self.props.postSelectionCallback();
130
- });
131
- }
132
-
133
- // load modal content
134
- //
135
- var templateUrl = self.props.contentURL + '/' + 'index.html';
136
- $.get(templateUrl)
137
- .done(function (data) {
138
- self.modal.innerHTML = data;
139
- self.modal.innerHTML = $('#' + self.props.xhr_data_element).eq(0).html();
140
-
141
- $(self.modal).modal({
142
- backdrop: "static",
143
- keyboard: false
144
- });
145
-
146
- self.$buttonDoNotAgree = $("#bccs-buttonDoNotAgree");
147
- self.$buttonAgree = $("#bccs-buttonAgree");
148
- self.$buttonSave = $("#bccs-buttonSave");
149
- self.$buttonAgreeAll = $("#bccs-buttonAgreeAll");
150
-
151
- updateButtons();
152
- updateOptionsFromCookie();
153
-
154
- $("#bccs-options").on("hide.bs.collapse", function () {
155
- detailedSettingsShown = false;
156
- updateButtons();
157
- }).on("show.bs.collapse", function () {
158
- detailedSettingsShown = true;
159
- updateButtons();
160
- });
161
- self.$buttonDoNotAgree.click(function () {
162
- doNotAgree();
163
- });
164
- self.$buttonAgree.click(function () {
165
- agreeAll();
166
- });
167
- self.$buttonSave.click(function () {
168
- $("#bccs-options").collapse('hide');
169
- saveSettings();
170
- updateOptionsFromCookie();
171
- });
172
- self.$buttonAgreeAll.click(function () {
173
- $("#bccs-options").collapse('hide');
174
- agreeAll();
175
- updateOptionsFromCookie();
176
- });
177
- })
178
- .fail(function () {
179
- logger.error('You probably need to set `contentURL` in the props');
180
- })
181
- } else {
182
- self.$modal.modal("show")
183
- }
184
- }.bind(this))
185
- }
186
-
187
- function updateOptionsFromCookie() {
188
- var settings = self.getSettings();
189
- if (settings) {
190
- for (var setting in settings) {
191
- var $checkbox = self.$modal.find("#bccs-options .bccs-option[data-name='" + setting + "'] input[type='checkbox']");
192
- $checkbox.prop("checked", settings[setting]);
193
- }
194
- }
195
- }
196
-
197
- function updateButtons() {
198
- if (detailedSettingsShown) {
199
- self.$buttonDoNotAgree.hide();
200
- self.$buttonAgree.hide();
201
- self.$buttonSave.show();
202
- self.$buttonAgreeAll.show();
203
- } else {
204
- self.$buttonDoNotAgree.show();
205
- self.$buttonAgree.show();
206
- self.$buttonSave.hide();
207
- self.$buttonAgreeAll.hide();
208
- }
209
- }
210
-
211
- function gatherOptions(setAllExceptNecessary) {
212
- var $options = self.$modal.find("#bccs-options .bccs-option");
213
- var options = {};
214
- for (var i = 0; i < $options.length; i++) {
215
- var option = $options[i];
216
- var name = option.getAttribute("data-name");
217
- if (name === "necessary") {
218
- options[name] = true;
219
- } else if (setAllExceptNecessary === undefined) {
220
- var $checkbox = $(option).find("input[type='checkbox']");
221
- options[name] = $checkbox.prop("checked");
222
- } else {
223
- options[name] = !!setAllExceptNecessary;
224
- }
225
- }
226
- return options
227
- }
228
-
229
- function agreeAll() {
230
- Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays);
231
- self.$modal.modal("hide");
232
- }
233
-
234
- function doNotAgree() {
235
- Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays);
236
- logger.warn('delete cookie: j1.user.consent');
237
- // j1.deleteCookie('j1.user.consent');
238
- j1.deleteCookie('all');
239
- self.$modal.modal('hide')
240
- j1.goHome();
241
- }
242
-
243
- function saveSettings() {
244
- Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions()), self.props.cookieStorageDays);
245
- self.$modal.modal("hide");
246
- }
247
-
248
- // call consent dialog if no cookie found (except pages whitelisted)
249
- //
250
- whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1);
251
- if (Cookie.get(this.props.cookieName) === undefined && this.props.autoShowDialog && !whitelisted) {
252
- showDialog();
253
- }
254
-
255
- // API functions
256
- // -------------------------------------------------------------------------
257
-
258
- // show the consent dialog (modal)
259
- // -------------------------------------------------------------------------
260
- this.showDialog = function () {
261
- whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1);
262
- if (!whitelisted) {
263
- showDialog();
264
- }
265
- }
266
-
267
- // collect settings from consent cookie
268
- // -------------------------------------------------------------------------
269
- this.getSettings = function (optionName) {
270
- var cookie = Cookie.get(self.props.cookieName);
271
- if (cookie) {
272
- var settings = JSON.parse(Cookie.get(self.props.cookieName));
273
- if (optionName === undefined) {
274
- return settings;
275
- } else {
276
- if (settings) {
277
- return settings[optionName];
278
- } else {
279
- return false;
280
- }
281
- }
282
- } else {
283
- return undefined;
284
- }
285
- }
286
- }
1
+ /*
2
+ # -----------------------------------------------------------------------------
3
+ # ~/assets/themes/j1/modules/cookieConsent/js/cookieConsent.js
4
+ # Provides JS Core for J1 Module BS Cookie Consent
5
+ #
6
+ # Product/Info:
7
+ # https://shaack.com
8
+ # http://jekyll.one
9
+ #
10
+ # Copyright (C) 2020 Stefan Haack
11
+ # Copyright (C) 2021 Juergen Adams
12
+ #
13
+ # bootstrap-cookie-banner is licensed under MIT License.
14
+ # See: https://github.com/shaack/bootstrap-cookie-banner/blob/master/LICENSE
15
+ # J1 Template is licensed under MIT License.
16
+ # See: https://github.com/jekyll-one/J1 Template/blob/master/LICENSE
17
+ # -----------------------------------------------------------------------------
18
+ # TODO:
19
+ #
20
+ # -----------------------------------------------------------------------------
21
+ # NOTE:
22
+ # BS Cookie Consent is a MODIFIED version of bootstrap-cookie-banner
23
+ # for the use with J1 Template. This modified version cannot be used
24
+ # outside of J1 Template!
25
+ # -----------------------------------------------------------------------------
26
+ */
27
+ 'use strict';
28
+
29
+ // -----------------------------------------------------------------------------
30
+ // ESLint shimming
31
+ // -----------------------------------------------------------------------------
32
+ /* eslint indent: "off" */
33
+ /* eslint no-unused-vars: "off" */
34
+ /* eslint no-undef: "off" */
35
+ /* eslint no-redeclare: "off" */
36
+ /* eslint indent: "off" */
37
+ /* eslint JSUnfilteredForInLoop: "off" */
38
+ // -----------------------------------------------------------------------------
39
+
40
+ function BootstrapCookieConsent(props) {
41
+ var logText;
42
+ var current_page;
43
+ var whitelisted;
44
+ var logger = log4javascript.getLogger('j1.core.bsCookieConsent');
45
+ var modalId = "bccs-modal"
46
+ var self = this
47
+ var detailedSettingsShown = false
48
+
49
+ this.props = {
50
+ autoShowDialog: true, // disable autoShowModal on the privacy policy and legal notice pages, to make these pages readable
51
+ language: navigator.language, // the language, in which the modal is shown
52
+ languages: ["en", "de"], // supported languages (in ./content/), defaults to first in array
53
+ contentURL: "./content", // this URL must contain the dialogs content in the needed languages
54
+ cookieName: "cookie-consent-settings", // the name of the cookie in which the configuration is stored as JSON
55
+ cookieStorageDays: 365, // the duration the cookie configuration is stored on the client
56
+ postSelectionCallback: undefined, // callback function, called after the user has made his selection
57
+ whitelisted: [], // pages NO consent modal page is issued
58
+ xhr_data_element: "" // container for the language-specific consent modal taken from /assets/data/cookieconsent.html
59
+ }
60
+
61
+ for (var property in props) {
62
+ this.props[property] = props[property];
63
+ }
64
+
65
+ this.language = this.props.language
66
+ if (this.language.indexOf("-") !== -1) {
67
+ this.language = this.language.split("-")[0];
68
+ }
69
+
70
+ if (!this.props.languages.includes(this.language)) {
71
+ this.language = this.props.languages[0]; // fallback on default language
72
+ }
73
+
74
+ var Cookie = {
75
+ set: function (name, value, days) {
76
+ var value_encoded = window.btoa(value);
77
+ var expires = "";
78
+ if (days) {
79
+ var date = new Date();
80
+ date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
81
+ expires = "; expires=" + date.toUTCString();
82
+ }
83
+ document.cookie = name + "=" + (value_encoded || "") + expires + "; Path=/; SameSite=Strict;";
84
+ },
85
+ get: function (name) {
86
+ var nameEQ = name + "=";
87
+ var ca = document.cookie.split(';');
88
+ for (var i = 0; i < ca.length; i++) {
89
+ var c = ca[i];
90
+ while (c.charAt(0) === ' ') {
91
+ c = c.substring(1, c.length);
92
+ }
93
+ if (c.indexOf(nameEQ) === 0) {
94
+ var value_encoded = c.substring(nameEQ.length, c.length);
95
+ var value = window.atob(value_encoded);
96
+ return value;
97
+ }
98
+ }
99
+ return undefined
100
+ }
101
+ }
102
+
103
+ var Events = {
104
+ documentReady: function (onDocumentReady) {
105
+ if (document.readyState !== 'loading') {
106
+ onDocumentReady();
107
+ } else {
108
+ document.addEventListener('DOMContentLoaded', onDocumentReady);
109
+ }
110
+ }
111
+ }
112
+
113
+ function showDialog(options) {
114
+ Events.documentReady(function () {
115
+ self.modal = document.getElementById(modalId);
116
+
117
+ if (!self.modal) {
118
+ self.modal = document.createElement("div");
119
+ self.modal.id = modalId;
120
+ self.modal.setAttribute("class", "modal fade");
121
+ self.modal.setAttribute("tabindex", "-1");
122
+ self.modal.setAttribute("role", "dialog");
123
+ self.modal.setAttribute("aria-labelledby", modalId);
124
+ document.body.append(self.modal);
125
+ self.$modal = $(self.modal);
126
+
127
+ if (self.props.postSelectionCallback) {
128
+ self.$modal.on("hidden.bs.modal", function () {
129
+ self.props.postSelectionCallback();
130
+ });
131
+ }
132
+
133
+ // load modal content
134
+ //
135
+ var templateUrl = self.props.contentURL + '/' + 'index.html';
136
+ $.get(templateUrl)
137
+ .done(function (data) {
138
+ self.modal.innerHTML = data;
139
+ self.modal.innerHTML = $('#' + self.props.xhr_data_element).eq(0).html();
140
+
141
+ $(self.modal).modal({
142
+ backdrop: "static",
143
+ keyboard: false
144
+ });
145
+
146
+ self.$buttonDoNotAgree = $("#bccs-buttonDoNotAgree");
147
+ self.$buttonAgree = $("#bccs-buttonAgree");
148
+ self.$buttonSave = $("#bccs-buttonSave");
149
+ self.$buttonAgreeAll = $("#bccs-buttonAgreeAll");
150
+
151
+ updateButtons();
152
+ updateOptionsFromCookie();
153
+
154
+ $("#bccs-options").on("hide.bs.collapse", function () {
155
+ detailedSettingsShown = false;
156
+ updateButtons();
157
+ }).on("show.bs.collapse", function () {
158
+ detailedSettingsShown = true;
159
+ updateButtons();
160
+ });
161
+ self.$buttonDoNotAgree.click(function () {
162
+ doNotAgree();
163
+ });
164
+ self.$buttonAgree.click(function () {
165
+ agreeAll();
166
+ });
167
+ self.$buttonSave.click(function () {
168
+ $("#bccs-options").collapse('hide');
169
+ saveSettings();
170
+ updateOptionsFromCookie();
171
+ });
172
+ self.$buttonAgreeAll.click(function () {
173
+ $("#bccs-options").collapse('hide');
174
+ agreeAll();
175
+ updateOptionsFromCookie();
176
+ });
177
+ })
178
+ .fail(function () {
179
+ logger.error('You probably need to set `contentURL` in the props');
180
+ })
181
+ } else {
182
+ self.$modal.modal("show")
183
+ }
184
+ }.bind(this))
185
+ }
186
+
187
+ function updateOptionsFromCookie() {
188
+ var settings = self.getSettings();
189
+ if (settings) {
190
+ for (var setting in settings) {
191
+ var $checkbox = self.$modal.find("#bccs-options .bccs-option[data-name='" + setting + "'] input[type='checkbox']");
192
+ $checkbox.prop("checked", settings[setting]);
193
+ }
194
+ }
195
+ }
196
+
197
+ function updateButtons() {
198
+ if (detailedSettingsShown) {
199
+ self.$buttonDoNotAgree.hide();
200
+ self.$buttonAgree.hide();
201
+ self.$buttonSave.show();
202
+ self.$buttonAgreeAll.show();
203
+ } else {
204
+ self.$buttonDoNotAgree.show();
205
+ self.$buttonAgree.show();
206
+ self.$buttonSave.hide();
207
+ self.$buttonAgreeAll.hide();
208
+ }
209
+ }
210
+
211
+ function gatherOptions(setAllExceptNecessary) {
212
+ var $options = self.$modal.find("#bccs-options .bccs-option");
213
+ var options = {};
214
+ for (var i = 0; i < $options.length; i++) {
215
+ var option = $options[i];
216
+ var name = option.getAttribute("data-name");
217
+ if (name === "necessary") {
218
+ options[name] = true;
219
+ } else if (setAllExceptNecessary === undefined) {
220
+ var $checkbox = $(option).find("input[type='checkbox']");
221
+ options[name] = $checkbox.prop("checked");
222
+ } else {
223
+ options[name] = !!setAllExceptNecessary;
224
+ }
225
+ }
226
+ return options
227
+ }
228
+
229
+ function agreeAll() {
230
+ Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays);
231
+ self.$modal.modal("hide");
232
+ }
233
+
234
+ function doNotAgree() {
235
+ Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays);
236
+ logger.warn('delete cookie: j1.user.consent');
237
+ // j1.deleteCookie('j1.user.consent');
238
+ j1.deleteCookie('all');
239
+ self.$modal.modal('hide')
240
+ j1.goHome();
241
+ }
242
+
243
+ function saveSettings() {
244
+ Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions()), self.props.cookieStorageDays);
245
+ self.$modal.modal("hide");
246
+ }
247
+
248
+ // call consent dialog if no cookie found (except pages whitelisted)
249
+ //
250
+ whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1);
251
+ if (Cookie.get(this.props.cookieName) === undefined && this.props.autoShowDialog && !whitelisted) {
252
+ showDialog();
253
+ }
254
+
255
+ // API functions
256
+ // -------------------------------------------------------------------------
257
+
258
+ // show the consent dialog (modal)
259
+ // -------------------------------------------------------------------------
260
+ this.showDialog = function () {
261
+ whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1);
262
+ if (!whitelisted) {
263
+ showDialog();
264
+ }
265
+ }
266
+
267
+ // collect settings from consent cookie
268
+ // -------------------------------------------------------------------------
269
+ this.getSettings = function (optionName) {
270
+ var cookie = Cookie.get(self.props.cookieName);
271
+ if (cookie) {
272
+ var settings = JSON.parse(Cookie.get(self.props.cookieName));
273
+ if (optionName === undefined) {
274
+ return settings;
275
+ } else {
276
+ if (settings) {
277
+ return settings[optionName];
278
+ } else {
279
+ return false;
280
+ }
281
+ }
282
+ } else {
283
+ return undefined;
284
+ }
285
+ }
286
+ }