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