$(document).ready(function() {
document.body.classList.add('smoothload');
initializeModal();
initializeQuantityControls();
initializeContentSwitching();
initializeMobileSearch();
wcqib_refresh_quantity_increments();
});
function initializeModal() {
if ($.cookie("no_thanks") == null) {
$('#myModal').modal('show');
document.body.classList.remove('loaded');
}
$(".nothanks").click(function() {
document.cookie = "no_thanks=true; expires=Fri, 31 Dec 9999 23:59:59 UTC";
document.body.classList.add('loaded');
});
}
function initializeContentSwitching() {
document.querySelectorAll('.button').forEach(button => {
button.addEventListener('click', function() {
document.querySelectorAll('.button').forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
document.getElementById('content-a').style.display = 'none';
document.getElementById('content-b').style.display = 'none';
const target = this.getAttribute('data-rel');
document.querySelector(target).style.display = 'block';
});
});
$('.button').click(function(e) {
e.preventDefault();
setContent($(this));
});
$('.button.active').length && setContent($('.button.active'));
}
function initializeQuantityControls() {
$('.pluss').click(function() {
var currentVal = parseInt($('#Quantity').val());
$('#Quantity').val(currentVal + 1);
});
$('.minuss').click(function() {
var currentVal = parseInt($('#Quantity').val());
var minVal = parseInt($('#Quantity').attr('min'));
if (currentVal > minVal) {
$('#Quantity').val(currentVal - 1);
}
});
}
function initializeMobileSearch() {
const mobileSearchInput = document.getElementById('mobileSearchInput');
const mobileSearchBtn = document.getElementById('mobileSearchBtn');
if (mobileSearchInput) {
mobileSearchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
performMobileSearch();
}
});
}
if (mobileSearchBtn) {
mobileSearchBtn.addEventListener('click', performMobileSearch);
}
}
let searchActive = false;
let mouseDownTarget = null;
function toggleSearch() {
const navlist = document.getElementById('navlist');
const searchContainer = document.getElementById('searchContainer');
const searchInput = document.getElementById('searchInput');
if (!navlist || !searchContainer || !searchInput) {
console.error('Search elements not found');
return;
}
if (!searchActive) {
navlist.classList.add('hidden');
setTimeout(() => {
searchContainer.classList.add('active');
setTimeout(() => {
searchInput.focus();
}, 100);
}, 150);
searchActive = true;
} else {
closeSearch();
}
}
function closeSearch() {
const navlist = document.getElementById('navlist');
const searchContainer = document.getElementById('searchContainer');
if (!navlist || !searchContainer) {
return;
}
searchContainer.classList.remove('active');
setTimeout(() => {
navlist.classList.remove('hidden');
}, 150);
searchActive = false;
}
document.addEventListener('mousedown', function(event) {
mouseDownTarget = event.target;
});
document.addEventListener('click', function(event) {
const searchContainer = document.getElementById('searchContainer');
const searchToggle = document.getElementById('searchToggle');
if (searchActive &&
!searchContainer.contains(event.target) &&
!searchToggle.contains(event.target) &&
!searchContainer.contains(mouseDownTarget)) {
closeSearch();
}
});
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape' && searchActive) {
closeSearch();
}
});
function openMenu() {
document.getElementById('menu').style.maxHeight = '635px';
document.getElementById('nav').style.boxShadow = 'none';
document.getElementById('menu').style.boxShadow = 'rgba(0, 0, 0, 0.3) 2px 0px 10px -2px';
document.getElementById('closeicon').style.display = 'inline';
document.getElementById('menuicon').style.display = 'none';
document.getElementById('overlay').style.visibility = 'visible';
document.getElementById('overlay').style.opacity = '1';
}
function closeMenu() {
document.getElementById('menu').style.maxHeight = '0';
document.getElementById('nav').style.boxShadow = '0 2px 5px rgb(0 0 0 / 10%)';
document.getElementById('menu').style.boxShadow = 'none';
document.getElementById('closeicon').style.display = 'none';
document.getElementById('menuicon').style.display = 'inline';
}
var overlay = document.getElementById('overlay');
function opencart() {
document.getElementById('body').style.overflow = "hidden";
document.getElementById('sidebar').style.transform = 'translateX(0%)';
overlay.classList.add('visible');
}
function closecart() {
document.getElementById('body').style.overflow = "inherit";
document.getElementById('sidebar').style.transform = 'translateX(105%)';
document.getElementById('sidebar').style.boxShadow = 'none';
overlay.classList.remove('visible');
}
var cart = document.querySelector('.cart');
var fullHeight = cart ? cart.scrollHeight : 0;
function opensummary() {
const cartElement = document.getElementById('cart');
if (cartElement && cart) {
cartElement.classList.add('show');
cart.style.maxHeight = fullHeight + 'px';
cartElement.style.marginBottom = '0px';
}
const hideElement = document.getElementById('hide');
const showElement = document.getElementById('show');
if (hideElement) hideElement.style.display = 'inherit';
if (showElement) showElement.style.display = 'none';
const arrowInfo = document.getElementsByClassName('arrowinfo')[0];
if (arrowInfo) arrowInfo.style.display = 'none';
}
function hidesummary() {
const cartElement = document.getElementById('cart');
if (cartElement && cart) {
cartElement.classList.remove('show');
cart.style.maxHeight = '0px';
}
const hideElement = document.getElementById('hide');
const showElement = document.getElementById('show');
if (hideElement) hideElement.style.display = 'none';
if (showElement) showElement.style.display = 'inherit';
}
function notify() {
document.getElementById('notify').style.display = 'flex';
document.getElementById('overlay').style.visibility = 'visible';
}
function closenotify() {
document.getElementById('notify').style.display = 'none';
document.getElementById('overlay').style.visibility = 'hidden';
}
function notifyme() {
document.getElementById('notify').style.display = 'flex';
overlay.classList.add('visible');
}
function closenotifyme() {
document.getElementById('notify').style.display = 'none';
overlay.classList.remove('visible');
}
function toggleSubmenu(submenuName) {
const allSubmenus = document.querySelectorAll('.submenu');
const allArrows = document.querySelectorAll('.arrow-icon');
const allMenuDivs = document.querySelectorAll('.menudiv');
const mobileSearchSubmenu = document.querySelector('.mobile-search-submenu');
const currentSubmenu = document.getElementById(`submenu${submenuName}`);
const currentArrow = document.getElementById(`arrow${submenuName}`);
const currentMenuDiv = document.querySelector(`[id="brands${submenuName}"]`);
const isActive = currentSubmenu.classList.contains('active');
allSubmenus.forEach(submenu => submenu.classList.remove('active'));
allArrows.forEach(arrow => arrow.classList.remove('active'));
allMenuDivs.forEach(menuDiv => menuDiv.classList.remove('active'));
if (mobileSearchSubmenu) {
mobileSearchSubmenu.classList.remove('active');
}
if (!isActive) {
currentSubmenu.classList.add('active');
currentArrow.classList.add('active');
currentMenuDiv.classList.add('active');
}
}
function toggleMobileSearch() {
const allSubmenus = document.querySelectorAll('.submenu');
const allArrows = document.querySelectorAll('.arrow-icon');
const allMenuDivs = document.querySelectorAll('.menudiv');
const mobileSearchSubmenu = document.querySelector('.mobile-search-submenu');
const mobileSearchArrow = document.getElementById('arrowMobileSearch');
const mobileSearchMenuDiv = document.getElementById('brandsMobileSearch');
if (!mobileSearchSubmenu || !mobileSearchArrow || !mobileSearchMenuDiv) {
console.error('Mobile search elements not found');
return;
}
const isActive = mobileSearchSubmenu.classList.contains('active');
allSubmenus.forEach(submenu => submenu.classList.remove('active'));
allArrows.forEach(arrow => arrow.classList.remove('active'));
allMenuDivs.forEach(menuDiv => menuDiv.classList.remove('active'));
mobileSearchSubmenu.classList.remove('active');
mobileSearchArrow.classList.remove('active');
mobileSearchMenuDiv.classList.remove('active');
if (!isActive) {
mobileSearchSubmenu.classList.add('active');
mobileSearchArrow.classList.add('active');
mobileSearchMenuDiv.classList.add('active');
setTimeout(() => {
const mobileSearchInput = document.getElementById('mobileSearchInput');
if (mobileSearchInput) {
mobileSearchInput.focus();
}
}, 300);
}
}
function performMobileSearch() {
const searchValue = document.getElementById('mobileSearchInput').value.trim();
if (searchValue) {
console.log('Searching for:', searchValue);
}
}
function setContent($el) {
$('.button').removeClass('active');
$('.container').hide();
$el.addClass('active');
$($el.data('rel')).show();
}
function wcqib_refresh_quantity_increments() {
jQuery("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").each(function(a, b) {
var c = jQuery(b);
c.addClass("buttons_added"), c.children().first().before(''), c.children().last().after('');
c.addClass("number");
});
jQuery("div.quantitynew:not(.buttons_added)").each(function() {
var container = jQuery(this);
container.addClass("buttons_added");
var qtyInput = container.find(".qty");
qtyInput.before('');
qtyInput.after('');
});
}
String.prototype.getDecimals || (String.prototype.getDecimals = function() {
var a = this,
b = ("" + a).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
return b ? Math.max(0, (b[1] ? b[1].length : 0) - (b[2] ? +b[2] : 0)) : 0
}), jQuery(document).on("updated_wc_div", function() {
wcqib_refresh_quantity_increments()
}), jQuery(document).on("click", ".plus, .minus", function() {
var a = jQuery(this).closest(".quantity").find(".qty"),
b = parseFloat(a.val()),
c = parseFloat(a.attr("max")),
d = parseFloat(a.attr("min")),
e = a.attr("step");
b && "" !== b && "NaN" !== b || (b = 0), "" !== c && "NaN" !== c || (c = ""), "" !== d && "NaN" !== d || (d = 0), "any" !== e && "" !== e && void 0 !== e && "NaN" !== parseFloat(e) || (e = 1), jQuery(this).is(".plus") ? c && b >= c ? a.val(c) : a.val((b + parseFloat(e)).toFixed(e.getDecimals())) : d && b <= d ? a.val(d) : b > 0 && a.val((b - parseFloat(e)).toFixed(e.getDecimals())), a.trigger("change")
});
jQuery(document).on("click", ".pluss, .minuss", function() {
var qtyInput = jQuery(this).closest(".quantitynew").find(".qty");
var currentValue = parseFloat(qtyInput.val());
var max = parseFloat(qtyInput.attr("max"));
var min = parseFloat(qtyInput.attr("min"));
var step = qtyInput.attr("step");
currentValue = currentValue || 0;
max = max || "";
min = min || 0;
step = (step === "any") ? 1 : parseFloat(step) || 1;
if (jQuery(this).hasClass("pluss")) {
if (max === "" || currentValue < max) {
qtyInput.val((currentValue + step).toFixed(step.toString().getDecimals()));
}
} else {
if (min === "" || currentValue > min) {
qtyInput.val((currentValue - step).toFixed(step.toString().getDecimals()));
}
}
qtyInput.trigger("change");
});
function offsite() {
document.getElementById('offsite').classList.add('expand');
document.getElementById('offsiteb').classList.remove('expand');
}
function offsiteb() {
document.getElementById('offsiteb').classList.add('expand');
document.getElementById('offsite').classList.remove('expand');
}
var offsc = document.getElementById('offsitec');
var ofullHeight = offsc ? offsc.scrollHeight : 0;
function offsitec() {
const element = document.getElementById('offsitec');
if (element) {
element.classList.add('expand');
element.style.maxHeight = ofullHeight + 'px';
}
}
function hideoffsitec() {
const element = document.getElementById('offsitec');
if (element) {
element.classList.remove('expand');
element.style.maxHeight = '0px';
}
}
document.querySelectorAll('.submenu').forEach(submenu => submenu.classList.remove('active'));
document.querySelectorAll('.arrowinfo').forEach(arrow => arrow.classList.remove('active'));
document.querySelectorAll('.menudiv').forEach(menuDiv => menuDiv.classList.remove('active'));