1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var CookieLanguages = [
|
13 | 'ca',
|
14 | 'cs',
|
15 | 'da',
|
16 | 'de',
|
17 | 'en',
|
18 | 'es',
|
19 | 'fr',
|
20 | 'hu',
|
21 | 'it',
|
22 | 'nl',
|
23 | 'pl',
|
24 | 'pt',
|
25 | 'ro',
|
26 | 'ru',
|
27 | 'se',
|
28 | 'sk',
|
29 | 'sl'
|
30 | ];
|
31 |
|
32 | var cookieLawStates = [
|
33 | 'AT',
|
34 | 'BE',
|
35 | 'BG',
|
36 | 'CY',
|
37 | 'CZ',
|
38 | 'DE',
|
39 | 'DK',
|
40 | 'EE',
|
41 | 'EL',
|
42 | 'ES',
|
43 | 'FI',
|
44 | 'FR',
|
45 | 'GB',
|
46 | 'HR',
|
47 | 'HU',
|
48 | 'IE',
|
49 | 'IT',
|
50 | 'LT',
|
51 | 'LU',
|
52 | 'LV',
|
53 | 'MT',
|
54 | 'NL',
|
55 | 'PL',
|
56 | 'PT',
|
57 | 'RO',
|
58 | 'SE',
|
59 | 'SI',
|
60 | 'SK'
|
61 | ];
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function setupCookieBar() {
|
72 | var scriptPath = getScriptPath();
|
73 | var cookieBar;
|
74 | var button;
|
75 | var buttonNo;
|
76 | var prompt;
|
77 | var promptBtn;
|
78 | var promptClose;
|
79 | var promptContent;
|
80 | var promptNoConsent;
|
81 | var cookiesListDiv;
|
82 | var detailsLinkText;
|
83 | var detailsLinkUrl;
|
84 | var startup = false;
|
85 | var shutup = false;
|
86 |
|
87 |
|
88 | var currentCookieSelection = getCookie();
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 | if (currentCookieSelection == 'CookieDisallowed') {
|
96 | removeCookies();
|
97 | setCookie('cookiebar', 'CookieDisallowed');
|
98 | }
|
99 |
|
100 |
|
101 |
|
102 | if (currentCookieSelection !== undefined) {
|
103 | return;
|
104 | }
|
105 |
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | if (getURLParameter('noGeoIp')) {
|
117 | startup = true;
|
118 | initCookieBar();
|
119 | }
|
120 |
|
121 |
|
122 | else {
|
123 |
|
124 | var checkEurope = new XMLHttpRequest();
|
125 | checkEurope.open('GET', '//freegeoip.net/json/', true);
|
126 | checkEurope.onreadystatechange = function() {
|
127 |
|
128 | if (checkEurope.readyState !== 4) {
|
129 | return;
|
130 | }
|
131 |
|
132 |
|
133 | clearTimeout(xmlHttpTimeout);
|
134 |
|
135 |
|
136 | if (checkEurope.status === 200) {
|
137 | var country = JSON.parse(checkEurope.responseText).country_code;
|
138 | if (cookieLawStates.indexOf(country) > -1) {
|
139 | startup = true;
|
140 | } else {
|
141 | shutup = true;
|
142 | }
|
143 | }
|
144 |
|
145 |
|
146 | else {
|
147 | startup = true;
|
148 | }
|
149 |
|
150 |
|
151 | initCookieBar();
|
152 | };
|
153 |
|
154 | |
155 |
|
156 |
|
157 |
|
158 | var xmlHttpTimeout = setTimeout(function () {
|
159 | console.log('cookieBAR - Timeout for ip geolocation');
|
160 |
|
161 |
|
162 |
|
163 | checkEurope.onreadystatechange = function() {};
|
164 |
|
165 |
|
166 | checkEurope.abort();
|
167 |
|
168 |
|
169 | startup = true;
|
170 | initCookieBar();
|
171 | }, 1500);
|
172 |
|
173 | checkEurope.send();
|
174 | }
|
175 |
|
176 |
|
177 | |
178 |
|
179 |
|
180 |
|
181 | function initCookieBar() {
|
182 |
|
183 | if (document.cookie.length > 0 || window.localStorage.length > 0) {
|
184 | var accepted = getCookie();
|
185 | if (accepted === undefined) {
|
186 | startup = true;
|
187 | } else {
|
188 | shutup = true;
|
189 | }
|
190 | }
|
191 |
|
192 |
|
193 | if (getURLParameter('always')) {
|
194 | startup = true;
|
195 | }
|
196 |
|
197 | if (startup === true && shutup === false) {
|
198 | startCookieBar();
|
199 | }
|
200 | }
|
201 |
|
202 | |
203 |
|
204 |
|
205 |
|
206 | function startCookieBar() {
|
207 | var userLang = detectLang();
|
208 |
|
209 |
|
210 | var theme = '';
|
211 | if (getURLParameter('theme')) {
|
212 | theme = '-' + getURLParameter('theme');
|
213 | }
|
214 | var path = scriptPath.replace(/[^\/]*$/, '');
|
215 | var minified = (scriptPath.indexOf('.min') > -1) ? '.min' : '';
|
216 | var stylesheet = document.createElement('link');
|
217 | stylesheet.setAttribute('rel', 'stylesheet');
|
218 | stylesheet.setAttribute('href', path + 'cookiebar' + theme + minified + '.css');
|
219 | document.head.appendChild(stylesheet);
|
220 |
|
221 |
|
222 | var request = new XMLHttpRequest();
|
223 | request.open('GET', path + 'lang/' + userLang + '.html', true);
|
224 | request.onreadystatechange = function() {
|
225 | if (request.readyState === 4 && request.status === 200) {
|
226 | var element = document.createElement('div');
|
227 | element.innerHTML = request.responseText;
|
228 | document.getElementsByTagName('body')[0].appendChild(element);
|
229 |
|
230 | cookieBar = document.getElementById('cookie-bar');
|
231 | button = document.getElementById('cookie-bar-button');
|
232 | buttonNo = document.getElementById('cookie-bar-button-no');
|
233 | prompt = document.getElementById('cookie-bar-prompt');
|
234 |
|
235 | promptBtn = document.getElementById('cookie-bar-prompt-button');
|
236 | promptClose = document.getElementById('cookie-bar-prompt-close');
|
237 | promptContent = document.getElementById('cookie-bar-prompt-content');
|
238 | promptNoConsent = document.getElementById('cookie-bar-no-consent');
|
239 |
|
240 | thirdparty = document.getElementById('cookie-bar-thirdparty');
|
241 | tracking = document.getElementById('cookie-bar-tracking');
|
242 |
|
243 | scrolling = document.getElementById('cookie-bar-scrolling');
|
244 | privacyPage = document.getElementById('cookie-bar-privacy-page');
|
245 | privacyLink = document.getElementById('cookie-bar-privacy-link');
|
246 |
|
247 | if (!getURLParameter('showNoConsent')) {
|
248 | promptNoConsent.style.display = 'none';
|
249 | buttonNo.style.display = 'none';
|
250 | }
|
251 |
|
252 | if (getURLParameter('blocking')) {
|
253 | fadeIn(prompt, 500);
|
254 | promptClose.style.display = 'none';
|
255 | }
|
256 |
|
257 | if (getURLParameter('thirdparty')) {
|
258 | thirdparty.style.display = 'block';
|
259 | }
|
260 |
|
261 | if (getURLParameter('tracking')) {
|
262 | tracking.style.display = 'block';
|
263 | }
|
264 |
|
265 | if (getURLParameter('hideDetailsBtn')) {
|
266 | promptBtn.style.display = 'none';
|
267 | }
|
268 |
|
269 | if (getURLParameter('scrolling')) {
|
270 | scrolling.style.display = 'inline-block';
|
271 | }
|
272 |
|
273 | if (getURLParameter('top')) {
|
274 | cookieBar.style.top = 0;
|
275 | setBodyMargin('top');
|
276 | } else {
|
277 | cookieBar.style.bottom = 0;
|
278 | setBodyMargin('bottom');
|
279 | }
|
280 |
|
281 | if (getURLParameter('privacyPage')) {
|
282 | var url = decodeURIComponent(getURLParameter('privacyPage'));
|
283 | privacyLink.href = url;
|
284 | privacyPage.style.display = 'inline-block';
|
285 | }
|
286 |
|
287 | setEventListeners();
|
288 | fadeIn(cookieBar, 250);
|
289 | setBodyMargin();
|
290 | }
|
291 | };
|
292 | request.send();
|
293 | }
|
294 |
|
295 |
|
296 | jQuery(document).ready(function () {
|
297 | jQuery("a").click(function () {
|
298 |
|
299 | var href = jQuery(this).attr('href');
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | });
|
335 | });
|
336 |
|
337 | |
338 |
|
339 |
|
340 |
|
341 | function getScriptPath() {
|
342 | var scripts = document.getElementsByTagName('script');
|
343 |
|
344 | for (i = 0; i < scripts.length; i += 1) {
|
345 | if (scripts[i].hasAttribute('src')) {
|
346 | path = scripts[i].src;
|
347 | if (path.indexOf('cookiebar') > -1) {
|
348 | return path;
|
349 | }
|
350 | }
|
351 | }
|
352 | }
|
353 |
|
354 | |
355 |
|
356 |
|
357 |
|
358 | function detectLang() {
|
359 | var userLang = getURLParameter('forceLang');
|
360 | if (userLang === false) {
|
361 | userLang = navigator.language || navigator.userLanguage;
|
362 | }
|
363 | userLang = userLang.substr(0, 2);
|
364 | if (CookieLanguages.indexOf(userLang) < 0) {
|
365 | userLang = 'en';
|
366 | }
|
367 | return userLang;
|
368 | }
|
369 |
|
370 | |
371 |
|
372 |
|
373 |
|
374 |
|
375 | function listCookies(cookiesListDiv) {
|
376 | var cookies = [];
|
377 | var i, x, y, ARRcookies = document.cookie.split(';');
|
378 | for (i = 0; i < ARRcookies.length; i += 1) {
|
379 | x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
|
380 | y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
|
381 | x = x.replace(/^\s+|\s+$/g, '');
|
382 | cookies.push(x);
|
383 | }
|
384 | cookiesListDiv.innerHTML = cookies.join(', ');
|
385 | }
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 | function getCookie() {
|
392 | var cookieValue = document.cookie.match(/(;)?cookiebar=([^;]*);?/);
|
393 |
|
394 | if (cookieValue == null) {
|
395 | return undefined;
|
396 | } else {
|
397 | return decodeURI(cookieValue[2]);
|
398 | }
|
399 | }
|
400 |
|
401 | |
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 | function setCookie(name, value) {
|
408 | var exdays = 30;
|
409 | if (getURLParameter('remember')) {
|
410 | exdays = getURLParameter('remember');
|
411 | }
|
412 |
|
413 | var exdate = new Date();
|
414 | exdate.setDate(exdate.getDate() + parseInt(exdays));
|
415 | var cValue = encodeURI(value) + ((exdays === null) ? '' : '; expires=' + exdate.toUTCString() + ';path=/');
|
416 | document.cookie = name + '=' + cValue;
|
417 | }
|
418 |
|
419 | |
420 |
|
421 |
|
422 |
|
423 | function removeCookies() {
|
424 |
|
425 | document.cookie.split(';').forEach(function(c) {
|
426 | document.cookie = c.replace(/^\ +/, '').replace(/\=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
|
427 | });
|
428 |
|
429 |
|
430 | localStorage.clear();
|
431 | }
|
432 |
|
433 |
|
434 | |
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | function fadeIn(el, speed) {
|
441 | var s = el.style;
|
442 | s.opacity = 0;
|
443 | s.display = 'block';
|
444 | (function fade() {
|
445 | (s.opacity -= -0.1) > 0.9 ? null : setTimeout(fade, (speed / 10));
|
446 | })();
|
447 | }
|
448 |
|
449 |
|
450 | |
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 | function fadeOut(el, speed) {
|
457 | var s = el.style;
|
458 | s.opacity = 1;
|
459 | (function fade() {
|
460 | (s.opacity -= 0.1) < 0.1 ? s.display = 'none' : setTimeout(fade, (speed / 10));
|
461 | })();
|
462 | }
|
463 |
|
464 | |
465 |
|
466 |
|
467 |
|
468 |
|
469 | function setBodyMargin(where) {
|
470 | setTimeout(function () {
|
471 |
|
472 | var height = document.getElementById('cookie-bar').clientHeight;
|
473 |
|
474 | var bodyEl = document.getElementsByTagName('body')[0];
|
475 | var bodyStyle = bodyEl.currentStyle || window.getComputedStyle(bodyEl);
|
476 |
|
477 | switch (where) {
|
478 | case 'top':
|
479 | bodyEl.style.marginTop = (parseInt(bodyStyle.marginTop) + height) + 'px';
|
480 | break;
|
481 | case 'bottom':
|
482 | bodyEl.style.marginBottom = (parseInt(bodyStyle.marginBottom) + height) + 'px';
|
483 | break;
|
484 | }
|
485 | }, 300);
|
486 | }
|
487 |
|
488 | |
489 |
|
490 |
|
491 |
|
492 | function clearBodyMargin() {
|
493 | var height = document.getElementById('cookie-bar').clientHeight;
|
494 |
|
495 | if (getURLParameter('top')) {
|
496 | var currentTop = parseInt(document.getElementsByTagName('body')[0].style.marginTop);
|
497 | document.getElementsByTagName('body')[0].style.marginTop = currentTop - height + 'px';
|
498 | } else {
|
499 | var currentBottom = parseInt(document.getElementsByTagName('body')[0].style.marginBottom);
|
500 | document.getElementsByTagName('body')[0].style.marginBottom = currentBottom -height + 'px';
|
501 | }
|
502 | }
|
503 |
|
504 | |
505 |
|
506 |
|
507 |
|
508 |
|
509 | function getURLParameter(name) {
|
510 | var set = scriptPath.split(name + '=');
|
511 | if (set[1]) {
|
512 | return set[1].split(/[&?]+/)[0];
|
513 | } else {
|
514 | return false;
|
515 | }
|
516 | }
|
517 |
|
518 | |
519 |
|
520 |
|
521 |
|
522 | function setEventListeners() {
|
523 | button.addEventListener('click', function() {
|
524 | setCookie('cookiebar', 'CookieAllowed');
|
525 | clearBodyMargin();
|
526 | fadeOut(prompt, 250);
|
527 | fadeOut(cookieBar, 250);
|
528 | if (getURLParameter('refreshPage')) {
|
529 | window.location.reload();
|
530 | }
|
531 | });
|
532 |
|
533 | buttonNo.addEventListener('click', function() {
|
534 | var txt = promptNoConsent.textContent.trim();
|
535 | var confirm = window.confirm(txt);
|
536 | if (confirm === true) {
|
537 | removeCookies();
|
538 | setCookie('cookiebar', 'CookieDisallowed');
|
539 | clearBodyMargin();
|
540 | fadeOut(prompt, 250);
|
541 | fadeOut(cookieBar, 250);
|
542 | }
|
543 | });
|
544 |
|
545 | promptBtn.addEventListener('click', function() {
|
546 | fadeIn(prompt, 250);
|
547 | });
|
548 |
|
549 | promptClose.addEventListener('click', function() {
|
550 | fadeOut(prompt, 250);
|
551 | });
|
552 |
|
553 | if (getURLParameter('scrolling')) {
|
554 | var scrollPos = document.body.getBoundingClientRect().top;
|
555 | var scrolled = false;
|
556 | window.addEventListener('scroll', function() {
|
557 | if (scrolled === false) {
|
558 | if (document.body.getBoundingClientRect().top - scrollPos > 250 || document.body.getBoundingClientRect().top - scrollPos < -250) {
|
559 | setCookie('cookiebar', 'CookieAllowed');
|
560 | clearBodyMargin();
|
561 | fadeOut(prompt, 250);
|
562 | fadeOut(cookieBar, 250);
|
563 | scrolled = true;
|
564 | if (getURLParameter('refreshPage')) {
|
565 | window.location.reload();
|
566 | }
|
567 | }
|
568 | }
|
569 | });
|
570 | }
|
571 | }
|
572 | }
|
573 |
|
574 |
|
575 | document.addEventListener('DOMContentLoaded', function() {
|
576 | setupCookieBar();
|
577 | });
|