function productQuantity(container=document){
container.querySelectorAll('.eab-quantity-input').forEach((input)=> {
input.addEventListener('change', ()=> {
const wrapper=input.closest('.eab-product-cart-wrapper');
if(!wrapper){
return;
}
const button=wrapper.querySelector('.eab-add-to-cart');
if(!button){
return;
}
const quantity=parseInt(input.value, 10)||1;
button.dataset.quantity=quantity;
});
});
}
document.addEventListener('DOMContentLoaded', ()=> {
const tabsBlocks=document.querySelectorAll('.sp-eab-sidebar-tabs');
if(tabsBlocks?.length > 0){
tabsBlocks.forEach((tabAccordion)=> {
const options=tabAccordion.getAttribute('data-tab-settings');
let parsedOptions={};
if(options&&options.trim()){
try {
parsedOptions=JSON.parse(options);
} catch (e){
parsedOptions={};}}
new EabTabAccordion(tabAccordion, parsedOptions);
});
}});
document.addEventListener('DOMContentLoaded', ()=> {
const accordionWrappers=document.querySelectorAll('.sp-eab-regular-accordion,.sp-eab-post-accordion,.sp-eab-product-accordion'
);
if(!accordionWrappers.length){
return;
}
accordionWrappers.forEach((accordionBlock)=> {
const qs=(s)=> accordionBlock.querySelector(s);
const qsa=(s)=> accordionBlock.querySelectorAll(s);
const initAccordion=()=> {
const el=qs('.sp-eab-accordion');
if(!el){
return null;
}
let options={};
const attrOptions=el.getAttribute('data-accordion-settings');
if(attrOptions&&attrOptions.trim()){
try {
options=JSON.parse(attrOptions);
} catch (e){
options={};}}
const accordion=new EabAccordion(el, options);
return accordion;
};
let accordion=initAccordion();
});
});
const applyEffectClasses=(item, isActive)=> {
const effectType=item.dataset.imageEffect;
const hoverGrayScale=item.dataset.hoverGrayScale;
const bgEl=item.querySelector('.sp-eab-accordion-bg,.sp-eab-featured-image-wrapper'
);
if(!effectType||!bgEl){
return;
}
item.classList.remove('eab-zoom-out-active',
'eab-zoom-out-normal',
'eab-zoom-out-onhover'
);
const useHoverGray=hoverGrayScale&&!isActive;
let effectClass='';
switch (effectType){
case 'zoomOut':
if(useHoverGray){
effectClass='eab-zoom-out-normal eab-zoom-out-onhover';
}else if(isActive){
effectClass='eab-zoom-out-active';
}else{
effectClass='eab-zoom-out-normal';
}
break;
default:
effectClass='';
}
if(effectClass){
effectClass.split(' ').forEach((cls)=> item.classList.add(cls));
}};
const getDeviceValuePx=(valueObj, device='Desktop', units=false)=> {
if(!valueObj||!valueObj.device||!valueObj.unit){
return 0;
}
const value=valueObj.device[device];
const unit=valueObj.unit[device];
if(value===null){
return 0;
}
return unit==='%'&&units ? `${value}%`:value;
};
document.addEventListener('DOMContentLoaded', ()=> {
const accordionBlocks=document.querySelectorAll('.sp-easy-accordion-block'
);
if(accordionBlocks.length===0){
return;
}
accordionBlocks?.forEach((accordion)=> {
const preloader=accordion?.querySelector('.sp-eab-preloader');
if(preloader){
setTimeout(()=> {
preloader.classList.remove('sp-d-block');
preloader.classList.add('sp-d-hidden');
accordion.classList.add('sp-eab-preloader-removed');
}, 500);
}});
});
document.addEventListener('DOMContentLoaded', ()=> {
const accordions=Array.from(document.querySelectorAll('.sp-eab-image-accordion,.sp-eab-product-accordion'
)
);
accordions.forEach((accordion)=> {
const items=Array.from(accordion.querySelectorAll('.sp-eab-image-accordion-item')
);
if(!items.length){
return;
}
const defaultOpen=accordion.dataset.defaultOpen||'first-item';
const activeEvent=accordion.dataset.activeEvent||'click';
const selectedIndex =
parseInt(accordion.dataset.selectedAccordion, 10) - 1;
const scrollToActive=accordion.dataset.scrollToActiveItem;
const accessibility=accordion.dataset.eabAccessibility;
const itemToUrl=accordion.dataset.anchorLink;
const autoInterval=accordion.dataset.autoplayDelay;
const animation =
accordion.dataset.animation &&
accordion.dataset.animation!=='none'
? accordion.dataset.animation
: null;
let activeIndex=-1;
let intervalRef=null;
const applyAnimation=(item, isActive)=> {
const content=item.querySelector('.eab-animation');
if(content){
if(animation&&animation!=='none'){
content.classList.remove('animated', animation);
if(isActive){
content.classList.add('animated', animation);
}}
}};
const updateAccessibility=()=> {
if(!accessibility){
return;
}
items.forEach((item, index)=> {
const isActive=index===activeIndex;
const button=item.querySelector('.sp-eab-accordion-bg');
item.setAttribute('role', 'region');
if(button){
button.setAttribute('role', 'button');
button.setAttribute('tabindex', '0');
button.setAttribute('aria-expanded',
isActive ? 'true':'false'
);
button.setAttribute('aria-label',
(
item.querySelector('.sp-eab-image-title')
?.textContent||''
)
.replace(/\s+/g, ' ')
.trim()
);
}});
};
let allowUrlUpdate=false;
const setActiveItem=(index, shouldScroll=false)=> {
items.forEach((item, i)=> {
const isActive=i===index;
if(!(
accordion.classList.contains('sp-eab-accordion-slider'
)||accordion.classList.contains('sp-eab-carousel')
)
){
item.classList.toggle('active', isActive);
}
applyEffectClasses(item, isActive);
applyAnimation(item, isActive);
});
const previousIndex=activeIndex;
activeIndex=index;
updateAccessibility();
const activeItem=items[index];
if(activeItem&&itemToUrl){
const slug=activeItem.getAttribute('data-slug');
if(slug&&allowUrlUpdate&&previousIndex!==index){
const base=window.location.href.split('#')[0];
history.replaceState(null, '', base + slug);
}}
if(shouldScroll&&scrollToActive&&items[index]){
items[index].scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest',
});
}
allowUrlUpdate=true;
};
if(accessibility){
items.forEach((item, index)=> {
const button=item.querySelector('.sp-eab-accordion-bg');
if(!button){
return;
}
button.addEventListener('keydown', (e)=> {
switch (e.key){
case 'ArrowRight':
case 'ArrowDown':
setActiveItem(
(activeIndex + 1) % items.length,
true
);
items[activeIndex % items.length]
.querySelector('.sp-eab-accordion-bg')
?.focus();
e.preventDefault();
break;
case 'ArrowLeft':
case 'ArrowUp':
setActiveItem(
(activeIndex - 1 + items.length) % items.length,
true
);
items[activeIndex % items.length]
.querySelector('.sp-eab-accordion-bg')
?.focus();
e.preventDefault();
break;
case 'Enter':
case ' ':
setActiveItem(index, true);
e.preventDefault();
break;
}});
});
}
let isHashOpen=false;
const currentHash=window.location.hash;
if(currentHash&&itemToUrl){
const matchedIndex=items.findIndex((item)=> item.getAttribute('data-slug')===currentHash
);
if(matchedIndex >=0){
isHashOpen=true;
activeIndex=matchedIndex;
setTimeout(()=> {
setActiveItem(matchedIndex, true);
}, 50);
}}
if(!isHashOpen){
switch (defaultOpen){
case 'first-item':
activeIndex=0;
break;
case 'close-all':
activeIndex=-1;
break;
case 'open-selected-item':
activeIndex =
selectedIndex >=0&&selectedIndex < items.length
? selectedIndex
: 0;
break;
default:
activeIndex=0;
}
if(activeIndex >=0){
setTimeout(()=> setActiveItem(activeIndex, true), 300);
}}
let autoPlayIntervalRef=null;
let isPaused=false;
const startAutoPlay=()=> {
clearInterval(autoPlayIntervalRef);
if(items.length <=1||isPaused){
return;
}
autoPlayIntervalRef=setInterval(()=> {
const nextIndex=(activeIndex + 1) % items.length;
setActiveItem(nextIndex, true);
}, autoInterval);
};
const pauseAutoplay=()=> {
isPaused=true;
clearInterval(autoPlayIntervalRef);
};
const resumeAutoplay=()=> {
if(!isPaused){
return;
}
isPaused=false;
startAutoPlay();
};
if(activeEvent==='auto'){
startAutoPlay();
accordion.addEventListener('mouseenter', pauseAutoplay);
accordion.addEventListener('mouseleave', resumeAutoplay);
}
const eventType=activeEvent==='hover' ? 'mouseenter':'click';
items.forEach((item, index)=> {
item.addEventListener(eventType, ()=> {
if(defaultOpen==='close-all'&&activeIndex===index){
if(!(
accordion.classList.contains('sp-eab-accordion-slider'
)||accordion.classList.contains('sp-eab-carousel')
)
){
item.classList.remove('active');
}
applyEffectClasses(item, false);
activeIndex=-1;
updateAccessibility();
}else{
setActiveItem(index, true);
}
if(activeEvent==='auto'){
startAutoPlay();
}});
});
});
productQuantity();
});
const animateAccordionItemsOnView=(items, animationClass='none')=> {
if(!animationClass||animationClass.toLowerCase()==='none'){
return;
}
if(!('IntersectionObserver' in window)){
items.forEach((item)=> {
item.classList.add('animated', animationClass);
});
return;
}
const observer=new IntersectionObserver(
(entries, obs)=> {
entries.forEach((entry)=> {
if(entry.isIntersecting){
entry.target.classList.add('animated', animationClass);
obs.unobserve(entry.target);
}});
},
{
threshold: 0.2,
}
);
items.forEach((item)=> observer.observe(item));
};
document.addEventListener('DOMContentLoaded', ()=> {
const getDeviceType=()=> {
const width=window.innerWidth;
if(width <=600){
return 'mobile';
}
return 'tablet-or-desktop';
};
let currentDevice=getDeviceType();
window.addEventListener('resize', ()=> {
const newDevice=getDeviceType();
if(newDevice!==currentDevice){
location.reload();
}
currentDevice=newDevice;
});
});