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