PageSourceSearch

https://headlam.com/scripts/owner/core/CookieManagement.js?d=c4572589b4fd4063552e7bf1ad0e1c537c5d7ef9

js headlam.com collected 2026-10-03 22:16:15 UTC 8,021 bytes, 239 lines download raw bytes

1// Default settings
2var settings = {
3  functional: false,
4  performance: false,
5};
6
7_cookieBar = {
8  initilizeCookieBar: function () {
9    // Checks that we don't already have a preference saved
10    if (!_cookie.exists("cmp")) {
11      // Makes an async call to our controller to get the HTML for our cookie bar
12      $.get(
13        "/umbraco/surface/jpcookiemanagementsurface/gethtml",
14        { component: "CookieBar" },
15        function (data) {
16          // Parses the data into a JSON object
17          var obj = JSON.parse(data);
18
19          // Appends the cookie bar to the document
20          //! UNCOMMENT LINE BELOW
21          // $("body").prepend(obj.element);
22
23          // Waits for page transitions to complete
24          setTimeout(function () {
25            // Activates the cookie disclaimer
26            $("#cookie-banner-container").addClass("active");
27            $(".page-tint.main").addClass("active");
28          }, 500);
29
30          // Listens for a click on the accept button
31          $("body").on("click", "#banner-button-accept", function () {
32            // Updates settings to accept all
33            settings.functional = true;
34            settings.performance = true;
35
36            // Runs the save preference function
37            _cookieBar.savePreference(settings);
38          });
39
40          // Listens for a click on the preferences button
41          $("body").on("click", "#banner-button-settings", function (e) {
42            // Prevents browser from performing default link behaviour
43            e.preventDefault();
44
45            // Runs the preferences function
46            _cookieBar.preferencesModal();
47          });
48        }
49      );
50    }
51  },
52
53  preferencesModal: function () {
54    // Downloads the preferences modal via AJAX
55    $.get(
56      "/umbraco/surface/jpcookiemanagementsurface/gethtml",
57      { component: "CookiePreferences" },
58      function (data) {
59        // Parses the data into a JSON object
60        var obj = JSON.parse(data);
61
62        // Appends the cookie bar to the document
63        $("#cookie-banner-container").append(obj.element);
64
65        setTimeout(function () {
66          // Activates the modal
67          $("#modal-settings-wrapper").addClass("active");
68        }, 350);
69
70        // Listens a click on a preference category accordion
71        $("body").on("click", ".csm-tab", function () {
72          var accordion = $(this);
73
74          accordion.toggleClass("active");
75
76          // Finds the accordion content element and toggles the visibility
77          accordion.parent().next().find(".csm-description").toggle();
78        });
79
80        // Listens for the save button click
81        $("body").on("click", "#modal-button-accept", function () {
82          // Finds all toggle switch elements
83          var switches = $(".csm-switch");
84
85          switches.each(function () {
86            // Finds the checkbox element for each toggle
87            var checkbox = $(this).find('input[type="checkbox"]');
88
89            // Retrieves category from data attribute
90            var cookieCategory = $(this).attr("data-type");
91
92            // Checks if checbox is currently checked
93            if (checkbox.is(":checked")) {
94              // Checks which category the checkbox matches and updates settings accordingly
95              if (cookieCategory === "functional") settings.functional = true;
96              if (cookieCategory === "performance") settings.performance = true;
97            }
98          });
99
100          // Saves preferences
101          _cookieBar.savePreference(settings);
102
103          // Hides the preferences modal
104          $("#modal-settings-wrapper").removeClass("active");
105          $(".page-tint.main").removeClass("active");
106        });
107      }
108    );
109  },
110
111  savePreference: function (settings) {
112    // Sets default preference (decline all but strictly necessary)
113    var consent = 0;
114
115    // Checks which settings have been applied to decide consent cookie value
116    if (settings.performance && settings.functional) {
117      consent = 3;
118    } else if (settings.functional) {
119      consent = 2;
120    } else if (settings.performance) {
121      consent = 1;
122    }
123
124    // Sets a new preference cookie
125    _cookie.add("cmp", consent, "90");
126    _cookieBar.applyPreference();
127    // Hides cookie consent bar
128    $("#cookie-banner-container").removeClass("active");
129    $(".page-tint.main").removeClass("active");
130  },
131
132  applyPreference: function () {
133    var cookieData = _cookie.read("cmp");
134    // Performs and AJAX function to retrieve the Functional and Performance scripts in json format
135    $.get(
136      "/Umbraco/Surface/JpCookieManagementSurface/GetScripts",
137      function (data) {
138        // depending on user selection dynamically add back in the javascript
139
140        // all cookies on
141        if (cookieData == 3) {
142          //console.log('Test log cookie option 3');
143          $("head")
144            .append(data.headPerformanceScripts)
145            .append(data.headFunctionalScripts);
146          $("body")
147            .append(data.footerPerformanceScripts)
148            .append(data.footerFunctionalScripts);
149          $("body")
150            .prepend(data.bodyTopPerformanceScripts)
151            .prepend(data.bodyTopFunctionalScripts);
152        }
153        // Performance cookies off
154        if (cookieData == 2) {
155          //console.log('Test log cookie option 2');
156          $("head").append(data.headFunctionalScripts);
157          $("body").append(data.footerFunctionalScripts);
158          $("body").prepend(data.bodyTopFunctionalScripts);
159        }
160        // Functional cookies off
161        if (cookieData == 1) {
162          //console.log('Test log cookie option 1');
163          $("head").append(data.headPerformanceScripts);
164          $("body").append(data.footerPerformanceScripts);
165          $("body").prepend(data.bodyTopPerformanceScripts);
166        }
167        // only strictly required cookies
168        if (cookieData == 0) {
169          //console.log('Test log cookie option 0');
170        }
171      },
172      "json"
173    );
174  },
175};
176
177_cookie = {
178  add: function (name, value, days) {
179    if (days) {
180      var date = new Date();
181      date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
182      var expires = "; expires=" + date.toGMTString();
183    } else var expires = "";
184    document.cookie = name + "=" + value + expires + "; path=/";
185    if (days < 1) {
186      host_name = window.location.hostname;
187      document.cookie =
188        name + "=" + value + expires + "; path=/; domain=." + host_name + ";";
189      if (host_name.indexOf("www") != 1) {
190        var host_name_withoutwww = host_name.replace("www", "");
191        document.cookie =
192          name +
193          "=" +
194          value +
195          expires +
196          "; path=/; domain=" +
197          host_name_withoutwww +
198          ";";
199      }
200      host_name = host_name.substring(
201        host_name.lastIndexOf(".", host_name.lastIndexOf(".") - 1)
202      );
203      document.cookie =
204        name + "=" + value + expires + "; path=/; domain=" + host_name + ";";
205    }
206  },
207  read: function (name) {
208    var nameEQ = name + "=";
209    var ca = document.cookie.split(";");
210    for (var i = 0; i < ca.length; i++) {
211      var c = ca[i];
212      while (c.charAt(0) == " ") {
213        c = c.substring(1, c.length);
214      }
215      if (c.indexOf(nameEQ) === 0) {
216        return c.substring(nameEQ.length, c.length);
217      }
218    }
219    return null;
220  },
221  erase: function (name) {
222    this.add(name, "", -10);
223  },
224  exists: function (name) {
225    return this.read(name) !== null;
226  },
227};
228
229$(document).ready(function () {
230  if (!_cookie.exists("cmp")) {
231    _cookieBar.initilizeCookieBar();
232  }
233  _cookieBar.applyPreference();
234  $("body").on("click", 'a[title="Cookie preferences"]', function (e) {
235    e.preventDefault();
236    _cookie.erase("cmp");
237    location.reload();
238  });
239});

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.