1; // jshint ignore:line 2(function (root, factory, undefined) { 3 'use strict'; 4 if (typeof define === 'function' && define.amd) { 5 define([], factory); 6 } else if (typeof exports === 'object') { 7 module.exports = factory(); 8 } else { 9 // root is window 10 root.CookiesEuBanner = factory(); 11 } 12}(window, function () { 13 'use strict'; 14 15 var CookiesEuBanner, 16 document = window.document; 17 18 CookiesEuBanner = function (launchFunction, waitAccept, useLocalStorage, undefined) { 19 if (!(this instanceof CookiesEuBanner)) { 20 return new CookiesEuBanner(launchFunction); 21 } 22 23 this.cookieTimeout = 31104000000; // 12 months in milliseconds 24 this.bots = /bot|crawler|spider|crawling/i; 25 this.cookieName = 'hasConsent'; 26 this.trackingCookiesNames = ['__utma', '__utmb', '__utmc', '__utmt', '__utmv', '__utmz', '_ga', '_gat', '_gid']; 27 this.launchFunction = launchFunction; 28 this.waitAccept = waitAccept || false; 29 this.useLocalStorage = useLocalStorage || false; 30 this.init(); 31 }; 32 33 CookiesEuBanner.prototype = { 34 init: function () { 35 // Detect if the visitor is a bot or not 36 // Prevent for search engine take the cookie alert message as main content of the page 37 var isBot = this.bots.test(navigator.userAgent); 38 39 // Check if DoNotTrack is activated 40 var dnt = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack; 41 var isToTrack = (dnt !== null && dnt !== undefined) ? (dnt && dnt !== 'yes' && dnt !== 1 && dnt !== '1') : true; 42 43 // Do nothing if it is a bot 44 // If DoNotTrack is activated, do nothing too 45 if (isBot || !isToTrack || this.hasConsent() === false) { 46 this.removeBanner(0); 47 return false; 48 } 49 50 // User has already consent to use cookies to tracking 51 if (this.hasConsent() === true) { 52 // Launch user custom function 53 this.launchFunction(); 54 return true; 55 } 56 57 // If it's not a bot, no DoNotTrack and not already accept, so show banner 58 this.showBanner(); 59 60 if (!this.waitAccept) { 61 // Accept cookies by default for the next page 62 this.setConsent(true); 63 } 64 }, 65 66 /* 67 * Show banner at the top of the page 68 */ 69 showBanner: function () { 70 var _this = this, 71 getElementById = document.getElementById.bind(document), 72 banner = getElementById('cookies-eu-banner'), 73 rejectButton = getElementById('cookies-eu-reject'), 74 acceptButton = getElementById('cookies-eu-accept'), 75 moreLink = getElementById('cookies-eu-more'), 76 waitRemove = (banner.dataset.waitRemove === undefined) ? 0 : parseInt(banner.dataset.waitRemove), 77 // Variables for minification optimization 78 addClickListener = this.addClickListener, 79 removeBanner = _this.removeBanner.bind(_this, waitRemove); 80 81 banner.style.display = 'block'; 82 83 if (moreLink) { 84 addClickListener(moreLink, function () { 85 _this.deleteCookie(_this.cookieName); 86 }); 87 } 88 89 if (acceptButton) { 90 addClickListener(acceptButton, function () { 91 removeBanner(); 92 _this.setConsent(true); 93 _this.launchFunction(); 94 }); 95 } 96 97 if (rejectButton) { 98 addClickListener(rejectButton, function () { 99 removeBanner(); 100 _this.setConsent(false); 101 102 // Delete existing tracking cookies 103 _this.trackingCookiesNames.map(_this.deleteCookie); 104 }); 105 } 106 }, 107 108 /* 109 * Set consent cookie or localStorage 110 */ 111 setConsent: function (consent) { 112 if (this.useLocalStorage) { 113 return localStorage.setItem(this.cookieName, consent); 114 } 115 116 this.setCookie(this.cookieName, consent); 117 }, 118 119 /* 120 * Check if user already consent 121 */ 122 hasConsent: function () { 123 var cookieName = this.cookieName; 124 var isCookieSetTo = function (value) { 125 return document.cookie.indexOf(cookieName + '=' + value) > -1 || localStorage.getItem(cookieName) === value; 126 }; 127 128 if (isCookieSetTo('true')) { 129 return true; 130 } else if (isCookieSetTo('false')) { 131 return false;
132 } 133 134 return null; 135 }, 136 137 /* 138 * Create/update cookie 139 */ 140 setCookie: function (name, value) { 141 var date = new Date(); 142 date.setTime(date.getTime() + this.cookieTimeout); 143 144 document.cookie = name + '=' + value + ';expires=' + date.toGMTString() + ';path=/'; 145 }, 146 147 /* 148 * Delete cookie by changing expire 149 */ 150 deleteCookie: function (name) { 151 var hostname = document.location.hostname.replace(/^www\./, ''), 152 commonSuffix = '; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/'; 153 154 document.cookie = name + '=; domain=.' + hostname + commonSuffix; 155 document.cookie = name + '=' + commonSuffix; 156 }, 157 158 addClickListener: function (DOMElement, callback) { 159 if (DOMElement.attachEvent) { // For IE 8 and earlier versions 160 return DOMElement.attachEvent('onclick', callback); 161 } 162 163 // For all major browsers, except IE 8 and earlier 164 DOMElement.addEventListener('click', callback); 165 }, 166 167 /* 168 * Delays removal of banner allowing developers 169 * to specify their own transition effects 170 */ 171 removeBanner: function (wait) { 172 var banner = document.getElementById('cookies-eu-banner'); 173 banner.classList.add('cookies-eu-banner--before-remove'); 174 setTimeout (function() { 175 if (banner && banner.parentNode) { 176 banner.parentNode.removeChild(banner); 177 } 178 }, wait); 179 } 180 }; 181 182 return CookiesEuBanner; 183}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.