Hi,
we have a shop (https://www.mcsuk.org/shop) and currently the cookie bar does not want to stay hidden. If you press ‘got it’ it disappears but then you go to another page and it pops back up again. I think it used to work but not 100% sure as i didn’t implement it and i am now trying to fix it.
There is a cookie A3prompt that is set but the code does not seem to take this into account. Can you see anything obvious i am missing, i’m not very good with JS. (source - https://www.mcsuk.org/shop/catalog/view/javascript/cookiebar.js or as below)
(function e(t, n, r) { function s(o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require == "function" && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); var f = new Error("Cannot find module '" + o + "'");
throw f.code = "MODULE_NOT_FOUND", f } var l = n[o] = {exports: {}}; t[o][0].call(l.exports, function (e) { var n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } var i = typeof require == "function" && require;
for (var o = 0; o < r.length; o++) s(r[o]); return s })({ 1: [function (require, module, exports) { function CookieBar() { "use strict"; var bOptIn; var bOptOut; var container; var xhr;
var eventListenersSet = false; function initialise() { findContainer(); createXhr(); loadPanel() } function addEventListeners() { bOptIn.addEventListener("click", onOptIn);
bOptOut.addEventListener("click", onOptOut); eventListenersSet = true } function removeEventListeners() { if (eventListenersSet) { bOptIn.removeEventListener("click", onOptIn);
bOptOut.removeEventListener("click", onOptOut); eventListenersSet = false } } function findContainer() { container = document.querySelector("#a3prompt") } function findButtons() { bOptIn = document.querySelector("#cookie-opt-in");
bOptOut = document.querySelector("#cookie-opt-out") } function createXhr() { xhr = new XMLHttpRequest } function loadPanel() { xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { container.innerHTML = xhr.responseText;
findButtons(); addEventListeners(); window.setTimeout(showPanel, 2e3) } }; xhr.open("GET", "/ajax/cookies/prompt"); xhr.send() } function showPanel() { container.classList.remove("hide") } function hidePanel() { removeEventListeners();
container.classList.add("hide") } function onOptIn() { xhr.onreadystatechange = function () { }; xhr.open("GET", "/ajax/cookies/opt-in"); xhr.send(); hidePanel() } function onOptOut() { xhr.onreadystatechange = function () { };
xhr.open("GET", "/ajax/cookies/opt-out"); xhr.send(); hidePanel() } initialise() } module.exports = CookieBar }, {}], 2: [function (require, module, exports) { "use strict";
var CookieBar = require("./CookieBar"); document.addEventListener("DOMContentLoaded", function () { if (document.getElementById("a3prompt")) { CookieBar() } }) }, {"./CookieBar": 1}] }, {}, [2]);
any ideas?
many thanks.
p.s. I know the styling is awful on the cookie bar but i’ll sort that once this is working.