` } 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');
let spaceFromTop = headerSpacer.getBoundingClientRect().top;
window.onscroll = function() {
let headerEl = document.querySelector('.header');
// if(window.innerWidth > 767) {
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;
}
}
// };
}
});
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
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); // older FF
window.addEventListener(wheelEvent, preventDefault, wheelOpt); // modern desktop
window.addEventListener('touchmove', preventDefault, wheelOpt); // mobile
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);
};
// user icons
(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);
}
});
})();