` } 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 imageContainers = document.querySelectorAll('.images');
const selectedImages = document.querySelectorAll('.image.selected');
imageContainers.forEach(imageContainer => {
let mouseX = 0;
let mouseY = 0;
let translateX = 0;
let translateY = 0;
imageContainer.addEventListener('mousemove', e => {
const boundingBox = imageContainer.getBoundingClientRect();
const containerWidth = boundingBox.width;
const containerHeight = boundingBox.height;
mouseX = e.clientX - boundingBox.left;
mouseY = e.clientY - boundingBox.top;
imageContainer
.querySelectorAll('.image.selected')
.forEach(selectedImage => {
const imageWidth = selectedImage.width;
const imageHeight = selectedImage.height;
const zoomFactor = 1.8; // Adjust the zoom level as needed
const scaleX = zoomFactor;
const scaleY = zoomFactor;
// Calculate translate values to zoom towards the cursor position
const translateX =
-(mouseX * (scaleX - 1)) + containerWidth / 2;
const translateY =
-(mouseY * (scaleY - 1)) + containerHeight / 2;
selectedImage.style.transform = `scale(${scaleX}, ${scaleY}) translate(${translateX}px, ${translateY}px)`;
});
});
imageContainer.addEventListener('mouseleave', () => {
imageContainer
.querySelectorAll('.image.selected')
.forEach(selectedImage => {
selectedImage.style.transform = 'scale(1) translate(0, 0)';
});
});
});
(function () {
'use strict';
let tabsClass = 'tabs';
let tabClass = 'tab';
let tabButtonClass = 'tab-button';
let activeClass = 'active';
/* Activates the chosen tab and deactivates the rest */
function activateTab(chosenTabElement) {
if (chosenTabElement) {
let tabList = chosenTabElement.parentNode.querySelectorAll('.' + tabClass);
for (let i = 0; i < tabList.length; i++) {
let tabElement = tabList[i];
if (tabElement.isEqualNode(chosenTabElement)) {
tabElement.classList.add(activeClass);
} else {
tabElement.classList.remove(activeClass);
}
}
}
}
/* Initialize each tabbed container */
let tabbedContainers = document.body.querySelectorAll('.' + tabsClass);
for (let i = 0; i < tabbedContainers.length; i++) {
let tabbedContainer = tabbedContainers[i];
/* List of tabs for this tabbed container */
let tabList = tabbedContainer.querySelectorAll('.' + tabClass);
/* Make the first tab active when the page loads */
activateTab(tabList[0]);
/* Activate a tab when you click its button */
for (let i = 0; i < tabList.length; i++) {
let tabElement = tabList[i];
let tabButton = tabElement.querySelector('.' + tabButtonClass);
tabButton.addEventListener('click', function (event) {
event.preventDefault();
activateTab(event.target.parentNode);
});
}
}
})();
document.querySelectorAll('#thumbnails a').forEach(thumbnail => {
thumbnail.addEventListener('click', function(e) {
e.preventDefault();
var mainImage = document.getElementById('mainImage');
var mainImageLink = document.getElementById('mainImageLink');
mainImage.src = this.children[0].src;
mainImageLink.href = this.href;
// Optionally update the alt text
mainImage.alt = this.children[0].alt;
});
});
Fancybox.bind("#mainImageLink", {
});
document.addEventListener('DOMContentLoaded', function() {
var firstThumbnail = document.querySelector('#thumbnails a');
if (firstThumbnail) {
firstThumbnail.click();
}
});