j1-template 2021.1.5 → 2021.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/data/themes.json +6 -6
- data/assets/themes/j1/adapter/js/cookieConsent.js +54 -28
- data/assets/themes/j1/adapter/js/j1.js +119 -150
- data/assets/themes/j1/adapter/js/themer.js +37 -29
- data/assets/themes/j1/adapter/js/toccer.js +4 -45
- data/assets/themes/j1/modules/cookieConsent/js/cookieConsent.js +286 -286
- data/assets/themes/j1/modules/cookieConsent/js/cookieConsent.min.js +3 -3
- data/assets/themes/j1/modules/fam/css/{uno → theme/uno}/fam.css +0 -0
- data/assets/themes/j1/modules/fam/css/theme/uno/fam.min.css +15 -0
- data/assets/themes/j1/modules/fam/js/fam.js +1 -6
- data/assets/themes/j1/modules/mmenuLight/css/{mmenu.css → mmenu-light.css} +0 -0
- data/assets/themes/j1/modules/mmenuLight/css/{mmenu.min.css → mmenu-light.min.css} +0 -0
- data/assets/themes/j1/modules/mmenuLight/css/theme/{uno.css → uno/mmenu.css} +0 -0
- data/assets/themes/j1/modules/mmenuLight/css/theme/{uno.min.css → uno/mmenu.min.css} +0 -0
- data/assets/themes/j1/modules/rtable/css/theme/{uno.css → uno/rtable.css} +0 -0
- data/assets/themes/j1/modules/rtable/css/theme/{uno.min.css → uno/rtable.min.css} +0 -0
- data/assets/themes/j1/modules/themeSwitcher/js/switcher.js +33 -47
- data/assets/themes/j1/modules/themeSwitcher/js/switcher.min.js +410 -2
- data/lib/j1/version.rb +1 -1
- data/lib/j1_app/j1_auth_manager/auth_manager.rb +2 -3
- data/lib/starter_web/Gemfile +1 -1
- data/lib/starter_web/_config.yml +1 -1
- data/lib/starter_web/_data/j1_config.yml +20 -17
- data/lib/starter_web/_data/modules/defaults/themer.yml +2 -1
- data/lib/starter_web/_data/private.default.yml +119 -0
- data/lib/starter_web/_data/resources.yml +6 -7
- data/lib/starter_web/_includes/attributes.asciidoc +1 -1
- data/lib/starter_web/_plugins/lunr_index.rb +1 -1
- data/lib/starter_web/dot.gitignore +1 -1
- data/lib/starter_web/package.json +1 -1
- data/lib/starter_web/pages/public/blog/navigator/archive.html +3 -2
- data/lib/starter_web/pages/public/blog/navigator/archive/categoryview.html +3 -2
- data/lib/starter_web/pages/public/blog/navigator/archive/dateview.html +3 -2
- data/lib/starter_web/pages/public/blog/navigator/archive/tagview.html +3 -2
- data/lib/starter_web/utilsrv/_defaults/package.json +1 -1
- data/lib/starter_web/utilsrv/package.json +1 -1
- metadata +11 -9
@@ -101,32 +101,34 @@ j1.adapter['themer'] = (function (j1, window) {
|
|
101
101
|
// ---------------------------------------------------------------------------
|
102
102
|
// globals
|
103
103
|
// ---------------------------------------------------------------------------
|
104
|
-
var environment
|
105
|
-
var themerOptions
|
106
|
-
var user_state
|
107
|
-
var
|
108
|
-
var
|
109
|
-
var user_state_detected
|
110
|
-
var styleLoaded
|
111
|
-
var id
|
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
112
|
var user_state_cookie;
|
113
113
|
var theme_css_html;
|
114
114
|
var _this;
|
115
115
|
var logger;
|
116
116
|
var logText;
|
117
117
|
|
118
|
+
var cssExtension = (environment === 'production')
|
119
|
+
? '.min.css'
|
120
|
+
: '.css';
|
121
|
+
|
118
122
|
var default_theme_name = '{{default_theme.name}}';
|
119
123
|
var default_theme_author = '{{default_theme.author}}';
|
120
|
-
var default_theme_author_url = '{{default_theme.
|
124
|
+
var default_theme_author_url = '{{default_theme.author_url}}';
|
121
125
|
var default_theme_css_name = default_theme_name.toLowerCase().replace(' ', '-');
|
122
|
-
var default_theme_css =
|
123
|
-
? '{{asset_path}}/{{theme_base}}/' +default_theme_css_name+ '/bootstrap.min.css'
|
124
|
-
: '{{asset_path}}/{{theme_base}}/' +default_theme_css_name+ '/bootstrap.css';
|
126
|
+
var default_theme_css = '{{asset_path}}/{{theme_base}}/' + default_theme_css_name + '/bootstrap' + cssExtension;
|
125
127
|
|
126
128
|
// ---------------------------------------------------------------------------
|
127
129
|
// helper functions
|
128
130
|
// ---------------------------------------------------------------------------
|
129
|
-
|
131
|
+
|
130
132
|
function styleSheetLoaded(styleSheet) {
|
131
133
|
var sheets = document.styleSheets, stylesheet = sheets[(sheets.length - 1)];
|
132
134
|
|
@@ -157,15 +159,15 @@ j1.adapter['themer'] = (function (j1, window) {
|
|
157
159
|
_this.state = 'started';
|
158
160
|
logger.info('state: ' + _this.getState());
|
159
161
|
|
160
|
-
//
|
161
|
-
user_state_detected = j1.existsCookie(
|
162
|
+
// detect|set user state cookie
|
163
|
+
user_state_detected = j1.existsCookie(cookie_names.user_state);
|
162
164
|
if (user_state_detected) {
|
163
|
-
user_state
|
165
|
+
user_state = j1.readCookie(cookie_names.user_state);
|
166
|
+
user_consent = j1.readCookie(cookie_names.user_consent);
|
164
167
|
}
|
165
168
|
|
166
|
-
// initial
|
167
|
-
|
168
|
-
if ( user_state.theme_name == '') {
|
169
|
+
// initial theme data
|
170
|
+
if (user_state.theme_css === '') {
|
169
171
|
user_state.theme_name = default_theme_name;
|
170
172
|
user_state.theme_css = default_theme_css;
|
171
173
|
user_state.theme_author = default_theme_author;
|
@@ -175,29 +177,35 @@ j1.adapter['themer'] = (function (j1, window) {
|
|
175
177
|
styleLoaded = styleSheetLoaded(user_state.theme_css);
|
176
178
|
theme_css_html = '<link rel="stylesheet" id="' + id + '" href="' + user_state.theme_css + '" type="text/css" />';
|
177
179
|
|
178
|
-
// skip loading UNO
|
179
|
-
//
|
180
|
+
// skip loading theme UNO css file except NOT loaded
|
180
181
|
if (!user_state.theme_name.includes('Uno') || !styleLoaded) {
|
181
182
|
$('head').append(theme_css_html);
|
182
183
|
}
|
183
184
|
|
184
185
|
// store if theme_switcher is enabled
|
185
|
-
//
|
186
186
|
user_state.theme_switcher = themerOptions.enabled;
|
187
187
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
+
}
|
193
203
|
|
194
204
|
// jadams, 2021-01-03: dependency has to be checked in more detail
|
195
|
-
//
|
196
205
|
var dependencies_met_j1_finished = setInterval (function () {
|
197
206
|
if (j1.getState() == 'finished') {
|
198
207
|
if (themerOptions.enabled) {
|
199
208
|
// enable BS ThemeSwitcher
|
200
|
-
//
|
201
209
|
logger.info('themes detected as: enabled');
|
202
210
|
logger.info('theme is being initialized: ' + user_state.theme_name);
|
203
211
|
|
@@ -156,65 +156,25 @@ j1.adapter['toccer'] = (function () {
|
|
156
156
|
/* eslint-enable */
|
157
157
|
|
158
158
|
// save config settings into the toccer object for global access
|
159
|
-
//
|
160
159
|
_this['moduleOptions'] = moduleOptions;
|
161
160
|
|
162
|
-
// if (options !== undefined) {
|
163
|
-
// var settings = $.extend({}, options);
|
164
|
-
// } else {
|
165
|
-
// var settings = false;
|
166
|
-
// }
|
167
|
-
|
168
161
|
// cast text-based booleans
|
169
|
-
var
|
170
|
-
var
|
162
|
+
var isToc = (moduleOptions.toc === 'true');
|
163
|
+
var isComments = (moduleOptions.comments === 'true');
|
171
164
|
|
172
|
-
if (moduleOptions.collapseDepth === undefined) {
|
165
|
+
if ( typeof moduleOptions.collapseDepth === 'undefined') {
|
173
166
|
moduleOptions.collapseDepth = 3;
|
174
167
|
}
|
175
168
|
|
176
|
-
// if (settings.scrollSmoothOffset === undefined) {
|
177
|
-
// settings.scrollSmoothOffset = {{toccer_options.scrollSmoothOffset}};
|
178
|
-
// }
|
179
|
-
//
|
180
|
-
// if (settings.enabled === undefined) {
|
181
|
-
// settings.enabled = true;
|
182
|
-
// }
|
183
|
-
|
184
|
-
// save config settings into the toccer object for global|later access
|
185
|
-
//
|
186
|
-
// _this['moduleOptions'] = settings;
|
187
|
-
|
188
169
|
if (isToc) {
|
189
170
|
var dependencies_met_navigator = setInterval(function() {
|
190
171
|
// if ( j1.adapter.navigator.getState() == 'finished' ) {
|
191
172
|
if ( j1.getState() == 'finished' ) {
|
192
173
|
var settings = j1.adapter.toccer.moduleOptions;
|
193
174
|
|
194
|
-
// calculate (tocbot page) offset DYMICALLY for correct
|
195
|
-
// smoothscroll position
|
196
|
-
//
|
197
|
-
// var $pagehead = $('.attic');
|
198
|
-
// var $navbar = $('nav.navbar');
|
199
|
-
// var $adblock = $('#adblock');
|
200
|
-
//
|
201
|
-
// var navbarType = $navbar.hasClass('navbar-fixed') ? 'fixed' : 'scrolled';
|
202
|
-
// var fontSize = $('body').css('font-size').replace('px','');
|
203
|
-
// var start = window.pageYOffset;
|
204
|
-
//
|
205
|
-
// var l = parseInt(fontSize);
|
206
|
-
//
|
207
|
-
// var h = $pagehead.length ? $pagehead.height() : 0;
|
208
|
-
// var n = $navbar.length ? $navbar.height() : 0;
|
209
|
-
// var a = $adblock.length ? $adblock.height() : 0;
|
210
|
-
//
|
211
|
-
// var o = navbarType == 'fixed' ? -1*(n + a + l) : -1*(h + n + a + l);
|
212
|
-
//
|
213
|
-
// settings.scrollSmoothOffset = o;
|
214
|
-
|
215
175
|
_this.initToccerCore(settings);
|
216
|
-
|
217
176
|
_this.setState('finished');
|
177
|
+
|
218
178
|
logger.info('state: ' + _this.getState());
|
219
179
|
logger.info('module initialized successfully');
|
220
180
|
logger.info('met dependencies for: j1');
|
@@ -322,7 +282,6 @@ j1.adapter['toccer'] = (function () {
|
|
322
282
|
scrollOffset = navbarType == 'fixed' ? -1*(n + a + l) : -1*(h + n + a + l);
|
323
283
|
|
324
284
|
// static offset, to be checked why this is needed
|
325
|
-
//
|
326
285
|
scrollOffset = scrollOffset + moduleOptions.scrollSmoothOffset
|
327
286
|
|
328
287
|
tocbot.refresh({
|
@@ -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
|
23
|
-
# for the use with J1 Template. This
|
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
|
+
}
|