PageSourceSearch

https://www.chimuadventures.com/modules/custom/cron_module/js/cookie-consent.js?tltf5q

js chimuadventures.com collected 2026-09-24 20:49:26 UTC 5,265 bytes, 146 lines download raw bytes

1/**
2 * Cookie consent + UTM tracking.
3 * Extracted from modules/custom/cron_module/templates/includes/common-footer.html.twig
4 * (was 3 inline <script> blocks totalling ~120 lines).
5 *
6 * Defines 4 globally-available helpers (getCookie/setCookie/getCurrentURL/setUTMCookie)
7 * and initialises whichever cookie banner is present (#cookieBanner for en-gb,
8 * #cookie-popup for other locales).
9 *
10 * Loaded deferred via cron_module/cookie_consent library; safe at end of body.
11 */
12(function () {
13  'use strict';
14
15  // ---- Global cookie helpers (kept on window for backward compatibility
16  // with any inline event handlers in CMS-authored markup) ----
17  window.getCookie = function (name) {
18    var decodedCookie = decodeURIComponent(document.cookie);
19    var cookies = decodedCookie.split(';');
20    for (var i = 0; i < cookies.length; i++) {
21      var cookie = cookies[i].trim();
22      if (cookie.startsWith(name + '=')) {
23        return cookie.substring(name.length + 1);
24      }
25    }
26    return null;
27  };
28
29  window.setCookie = function (name, value, days) {
30    var date = new Date();
31    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
32    var expires = 'expires=' + date.toUTCString();
33    document.cookie = name + '=' + value + '; ' + expires + '; path=/; SameSite=Strict';
34  };
35
36  window.setUTMCookie = function (cname, cvalue, exdays) {
37    var d = new Date();
38    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
39    var expires = 'expires=' + d.toUTCString();
40    document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
41  };
42
43  window.getCurrentURL = function () {
44    var urlString = window.location.href;
45    if (urlString.indexOf('utm_') !== -1) {
46      window.setUTMCookie('utm_reference_url', urlString, 60);
47    }
48  };
49
50  // ---- AdRoll pixel loader (EU/UK only — when user accepts consent) ----
51  function loadNextRollPixel() {
52    if (window.__adroll_loaded) return;
53    window.__adroll_loaded = true;
54
55    var adroll_adv_id = 'KZKAH7KAKFFGJK34O7OLE6';
56    (function (w, d, e, o, a) {
57      w.adroll = w.adroll || [];
58      w.adroll.f = ['setProperties', 'identify', 'track', 'identify_email', 'get_cookie'];
59      var roundtripUrl = 'https://s.adroll.com/j/' + adroll_adv_id + '/roundtrip.js';
60
61      for (a = 0; a < w.adroll.f.length; a++) {
62        w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function (n) {
63          return function () { w.adroll.push([n, arguments]); };
64        })(w.adroll.f[a]);
65      }
66
67      e = d.createElement('script');
68      o = d.getElementsByTagName('script')[0];
69      e.async = 1;
70      e.src = roundtripUrl;
71      e.onload = function () {
72        if (typeof __adroll !== 'undefined' && typeof __adroll.consent_given === 'function') {
73          __adroll.consent_given();
74        }
75      };
76      o.parentNode.insertBefore(e, o);
77    })(window, document);
78
79    adroll.track('pageView');
80  }
81
82  // ---- DOM-ready initialisation ----
83  document.addEventListener('DOMContentLoaded', function () {
84    // EU/UK consent banner ('#cookieBanner' + Allow/Decline buttons)
85    var euBanner = document.getElementById('cookieBanner');
86    if (euBanner) {
87      var acceptBtn = document.getElementById('acceptCookies');
88      var declineBtn = document.getElementById('declineCookies');
89      var tcDate = euBanner.dataset.tcDate || '';
90      var consent = window.getCookie('addRollConsent');
91
92      if (consent === 'accepted') {
93        euBanner.style.display = 'none';
94        loadNextRollPixel();
95      } else if (consent === 'declined') {
96        if (window.getCookie('addRolltc') === tcDate) {
97          euBanner.style.display = 'none';
98        } else {
99          euBanner.style.display = 'block';
100        }
101      } else {
102        euBanner.style.display = 'block';
103      }
104
105      if (acceptBtn) {
106        acceptBtn.addEventListener('click', function () {
107          window.setCookie('addRollConsent', 'accepted', 365);
108          euBanner.style.display = 'none';
109          loadNextRollPixel();
110        });
111      }
112
113      if (declineBtn) {
114        declineBtn.addEventListener('click', function () {
115          window.setCookie('addRollConsent', 'declined', 180);
116          window.setCookie('addRolltc', tcDate, 180);
117          euBanner.style.display = 'none';
118        });
119      }
120
121      // Read-more toggles inside the EU banner
122      document.querySelectorAll('.read-more').forEach(function (button) {
123        button.addEventListener('click', function (e) {
124          e.preventDefault();
125          var parentDiv = this.parentElement;
126          parentDiv.classList.toggle('expanded');
127          this.textContent = parentDiv.classList.contains('expanded') ? 'Read less' : 'Read more';
128        });
129      });
130    }
131
132    // Non-EU simple cookie popup ('#cookie-popup' + 'x' close)
133    var simplePopup = document.getElementById('cookie-popup');
134    if (simplePopup) {
135      var closeBtn = document.getElementById('accept-cookie');
136      var simpleConsent = window.getCookie('cookiePrompt');
137      simplePopup.style.display = simpleConsent === 'on' ? 'none' : 'block';
138      if (closeBtn) {
139        closeBtn.addEventListener('click', function () {
140          window.setCookie('cookiePrompt', 'on', 365);
141          simplePopup.style.display = 'none';
142        });
143      }
144    }
145  });
146})();

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.