` } else { imgString = `` }; let titleString = ''; if(result.name) { titleString = articleNameReplace(result.name); }; let descriptionString = ''; if(result.summary) { descriptionString = result.summary; } else if(result.description) { descriptionString = result.description; }; if (descriptionString.length > 50) { descriptionString = descriptionString.slice(0, 50) + '...'; }; let markup = ` ${imgString} ${titleString}
${descriptionString}
`; resultsContainer.insertAdjacentHTML('beforeend', markup); }); } else { let markup = "No results found."; resultsContainer.insertAdjacentHTML('beforeend', markup); } } let prevScrollpos = window.pageYOffset;
window.addEventListener('scroll', (e) => {
let headerSpacer = document.querySelector('.header-spacer');
if(headerSpacer) {
let spaceFromTop = headerSpacer.getBoundingClientRect().top;
window.onscroll = function() {
let headerEl = document.querySelector('.header');
if(spaceFromTop < -300) {
let menucheckbox = document.querySelector('.side-menu');
if(!menucheckbox.checked) {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
headerEl.style.top = "0";
} else {
headerEl.style.top = "-80px";
}
prevScrollpos = currentScrollPos;
}
}
}
};
});
var keys = {37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e.preventDefault();
};
function preventDefaultForScrollKeys(e) {
if (keys[e.keyCode]) {
preventDefault(e);
return false;
};
};
/* modern Chrome requires { passive: false } when adding event */
var supportsPassive = false;
try {
window.addEventListener("test", null, Object.defineProperty({}, 'passive', {
get: function () { supportsPassive = true; }
}));
} catch(e) {};
var wheelOpt = supportsPassive ? { passive: false } : false;
var wheelEvent = 'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel';
const toggleScroll = () => {
let menucheckbox = document.querySelector('.side-menu');
if(menucheckbox.checked) {
disableScroll();
} else {
enableScroll();
};
};
/* call this to Disable */
function disableScroll() {
window.addEventListener('DOMMouseScroll', preventDefault, false);
window.addEventListener(wheelEvent, preventDefault, wheelOpt);
window.addEventListener('touchmove', preventDefault, wheelOpt);
window.addEventListener('keydown', preventDefaultForScrollKeys, false);
};
/* call this to Enable */
function enableScroll() {
window.removeEventListener('DOMMouseScroll', preventDefault, false);
window.removeEventListener(wheelEvent, preventDefault, wheelOpt);
window.removeEventListener('touchmove', preventDefault, wheelOpt);
window.removeEventListener('keydown', preventDefaultForScrollKeys, false);
};
(function () {
const cartNote = document.querySelector(".cartNote");
function updateCartNote(value) {
if (value) {
cartNote.textContent = value;
} else {
}
}
updateCartNote(localStorage.getItem("ubx_basketItems"));
const localStorageSetItem = localStorage.setItem;
localStorage.setItem = function (key, value) {
const event = new Event("localStorageSetItem");
event.key = key;
event.newValue = value;
window.dispatchEvent(event);
localStorageSetItem.apply(this, arguments);
};
window.addEventListener("localStorageSetItem", function (event) {
if (event.key === "ubx_basketItems") {
updateCartNote(event.newValue);
}
});
})();
;
const links = document.getElementsByTagName('a');
for (let i = 0; i < links.length; i++) {
const link = links[i];
if (link.getAttribute('href') === '') {
link.removeAttribute('href');
link.removeEventListener('click', preventClick);
}
}
function preventClick(event) {
event.preventDefault();
}; function generateSessionID() { return Math.random().toString(36).substring(2, 15); } function setSessionIDCookie(sessionID) { const expirationDate = new Date(); expirationDate.setDate(expirationDate.getDate() + 7); document.cookie = `sessionID=${sessionID}; expires=${expirationDate.toUTCString()}; path=/; domain=brightwayz.co.uk`; } function getSessionID() { const cookieString = document.cookie; const cookieArray = cookieString.split('; '); for (const cookie of cookieArray) { const [name, value] = cookie.split('='); if (name === 'sessionID') { return value; } } return null; } const sessionID = generateSessionID(); setSessionIDCookie(sessionID); const retrievedSessionID = getSessionID(); document.addEventListener('DOMContentLoaded', function() { var cookieDismissed = localStorage.getItem('cookieDismissed'); if (cookieDismissed) { var cookiePopup = document.querySelector('#cookie-popup'); cookiePopup.style.display = 'none'; } var okButton = document.querySelector('#cookie-popup button'); okButton.addEventListener('click', function() { var cookiePopup = document.querySelector('#cookie-popup'); cookiePopup.style.display = 'none'; localStorage.setItem('cookieDismissed', true); }); });