PageSourceSearch

https://aytocabanasyepes.es/wp-content/plugins/adapta-rgpd/assets/js/cookies-eu-banner.js?ver=1.3.9

js aytocabanasyepes.es collected 2026-10-02 22:38:23 UTC 6,923 bytes, 224 lines download raw bytes

1; // jshint ignore:line
2/* 
3  Cookies-EU-banner
4  Copyright: Alexandre Demode
5  Resource URI: https://github.com/Alex-D/Cookies-EU-banner 
6  License: MIT
7  License URI: https://github.com/Alex-D/Cookies-EU-banner/blob/master/LICENSE
8*/
9
10(function (root, factory, undefined) {
11  'use strict';
12  if (typeof define === 'function' && define.amd) {
13    define([], factory);
14  } else if (typeof exports === 'object') {
15    module.exports = factory();
16  } else {
17    // root is window
18    root.CookiesEuBanner = factory();
19  }
20}(window, function () {
21  'use strict';
22
23
24  var CookiesEuBanner,
25    document = window.document;
26
27  CookiesEuBanner = function (launchFunction, waitAccept, useLocalStorage, undefined) {
28    if (!(this instanceof CookiesEuBanner)) {
29      return new CookiesEuBanner(launchFunction);
30    }
31
32    this.cookieTimeout = 33696000000; // 13 months in milliseconds
33    this.bots = /bot|crawler|spider|crawling/i;
34    this.cookieName = 'hasConsent';
35    this.trackingCookiesNames = ['__utma', '__utmb', '__utmc', '__utmt', '__utmv', '__utmz', '_ga', '_gat', '_gid', '_fbp'];
36    this.launchFunction = launchFunction;
37    this.waitAccept = waitAccept || false;
38    this.useLocalStorage = useLocalStorage || false;
39    this.init();
40  };
41
42  CookiesEuBanner.prototype = {
43    init: function () {
44      // Detect if the visitor is a bot or not
45      // Prevent for search engine take the cookie alert message as main content of the page
46      var isBot = this.bots.test(navigator.userAgent);
47
48      // Check if DoNotTrack is activated
49      var dnt = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack;
50      var isToTrack = (dnt !== null && dnt !== undefined) ? (dnt && dnt !== 'yes' && dnt !== 1 && dnt !== '1') : true;
51
52      this.customEvents();
53      // Do nothing if it is a bot
54      // If DoNotTrack is activated, do nothing too
55      // if (isBot || !isToTrack || this.hasConsent() === false) {
56      if (isBot || this.hasConsent() === false) {
57        this.removeBanner(0);
58        return false;
59      }
60
61      // User has already consent to use cookies to tracking
62      if (this.hasConsent() === true) {
63        // Launch user custom function
64        this.launchFunction();
65        return true;
66      }
67
68      // If it's not a bot, no DoNotTrack and not already accept, so show banner
69      this.showBanner();
70
71      if (!this.waitAccept) {
72        // Accept cookies by default for the next page
73        this.setConsent(true);
74      }
75    },
76
77    customEvents: function () {
78      var _this = this,
79        getElementById = document.getElementById.bind(document),
80        addClickListener = this.addClickListener,
81        customRejectButton = getElementById('custom-cookies-eu-reject'),
82        customAcceptButton = getElementById('custom-cookies-eu-accept');
83
84      if (customAcceptButton) {
85        addClickListener(customAcceptButton, function () {
86          _this.setConsent(true);
87          _this.launchFunction();
88          setTimeout( function(){ window.location.reload(); }, 100 );
89        });
90      }      
91
92      if (customRejectButton) {
93        addClickListener(customRejectButton, function () {
94          _this.setConsent(false);
95
96          // Delete existing tracking cookies
97          _this.trackingCookiesNames.map(_this.deleteCookie);
98          setTimeout( function(){ window.location.reload(); }, 100 );
99        });
100      }
101    },
102    /*
103     * Show banner at the top of the page
104     */
105    showBanner: function () {
106      var _this = this,
107        getElementById = document.getElementById.bind(document),
108        banner = getElementById('cookies-eu-wrapper'),
109        rejectButton = getElementById('cookies-eu-reject'),
110        
111        acceptButton = getElementById('cookies-eu-accept'),
112        
113        moreLink = getElementById('cookies-eu-more'),
114        waitRemove = (banner.dataset.waitRemove === undefined) ? 0 : parseInt(banner.dataset.waitRemove),
115        // Variables for minification optimization
116        addClickListener = this.addClickListener,
117        removeBanner = _this.removeBanner.bind(_this, waitRemove);
118
119      banner.style.display = 'block';
120
121      if (moreLink) {
122        addClickListener(moreLink, function () {
123          _this.deleteCookie(_this.cookieName);
124        });
125      }
126
127      if (acceptButton) {
128        addClickListener(acceptButton, function () {
129          removeBanner();
130          _this.setConsent(true);
131          _this.launchFunction(true);
132        });
133      }
134
135      if (rejectButton) {
136        addClickListener(rejectButton, function () {
137          removeBanner();
138          _this.setConsent(false);
139
140          // Delete existing tracking cookies
141          _this.trackingCookiesNames.map(_this.deleteCookie);
142        });
143      }
144    },
145
146    /*
147     * Set consent cookie or localStorage
148     */
149    setConsent: function (consent) {
150      if (this.useLocalStorage) {
151        return localStorage.setItem(this.cookieName, consent);
152      }
153
154      this.setCookie(this.cookieName, consent);
155
156      var consents = (consent)?["ANLTCS", "SCLS"]:[];
157      this.setCookie('hasConsents', consents.join('+'));      
158    },
159
160    /*
161     * Check if user already consent
162     */
163    hasConsent: function () {
164      var cookieName = this.cookieName;
165      var isCookieSetTo = function (value) {
166        return document.cookie.indexOf(cookieName + '=' + value) > -1 || localStorage.getItem(cookieName) === value;
167      };
168
169      if (isCookieSetTo('true')) {
170        return true;
171      } else if (isCookieSetTo('false')) {
172        return false;
173      }
174
175      return null;
176    },
177
178    /*
179     * Create/update cookie
180     */
181    setCookie: function (name, value) {
182      var date = new Date();
183      date.setTime(date.getTime() + this.cookieTimeout);
184
185      document.cookie = name + '=' + value + ';expires=' + date.toUTCString() + ';path=/';
186    },
187
188    /*
189     * Delete cookie by changing expire
190     */
191    deleteCookie: function (name) {
192      var hostname = document.location.hostname.replace(/^www\./, ''),
193          commonSuffix = '; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
194
195      document.cookie = name + '=; domain=.' + hostname + commonSuffix;
196      document.cookie = name + '=' + commonSuffix;
197    },
198
199    addClickListener: function (DOMElement, callback) {
200      if (DOMElement.attachEvent) { // For IE 8 and earlier versions
201        return DOMElement.attachEvent('onclick', callback);
202      }
203
204      // For all major browsers, except IE 8 and earlier
205      DOMElement.addEventListener('click', callback);
206    },
207
208    /*
209     * Delays removal of banner allowing developers
210     * to specify their own transition effects
211     */
212    removeBanner: function (wait) {
213      setTimeout (function() {
214        var banner = document.getElementById('cookies-eu-wrapper');
215        if (banner && banner.parentNode) {
216          banner.parentNode.removeChild(banner);
217        }
218      }, wait);
219    }
220  };
221
222  return CookiesEuBanner;
223}));
224

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.