(function (){
function initStickyAddToCart(){
var body=document.body;
if(!body||!body.classList.contains('single-product')){
return;
}
var cartForm=document.querySelector('div.nectar-prod-wrap > div.summary.entry-summary.force-contained-rows > form.cart'
);
if(!cartForm){
cartForm=document.querySelector('form.cart');
}
if(!cartForm){
return;
}
var isVariableProduct=cartForm.classList.contains('variations_form');
var resetVariationsLink=isVariableProduct
? cartForm.querySelector('a.reset_variations')
: null;
var variationIdInput=isVariableProduct
? cartForm.querySelector('input.variation_id')
: null;
var addToCartButton=cartForm.querySelector('button.single_add_to_cart_button'
);
function hasActiveVariation(){
return (
isVariableProduct &&
variationIdInput &&
variationIdInput.value &&
variationIdInput.value!=='0'
);
}
function resetVariations(){
if(!isVariableProduct){
return;
}
if(resetVariationsLink){
resetVariationsLink.click();
}else{
var attributeSelects=cartForm.querySelectorAll('select[name^="attribute_"]'
);
attributeSelects.forEach(function (select){
select.value='';
var evt;
if(typeof Event==='function'){
evt=new Event('change', { bubbles: true });
}else{
evt=document.createEvent('HTMLEvents');
evt.initEvent('change', true, false);
}
select.dispatchEvent(evt);
});
if(variationIdInput){
variationIdInput.value='';
}}
}
var mobileMq=window.matchMedia('(max-width: 768px)');
var HAS_STICKY_CLASS='has-sticky-atc';
var VISIBLE_CLASS='sticky-atc-visible';
var triggerPoint=null;
var ticking=false;
function computeTriggerPoint(){
if(body.classList.contains(HAS_STICKY_CLASS)){
return;
}
var scrollTop =
window.scrollY ||
window.pageYOffset ||
document.documentElement.scrollTop ||
0;
var rect=cartForm.getBoundingClientRect();
triggerPoint=rect.bottom + scrollTop;
}
function updateStickyState(){
ticking=false;
if(!mobileMq.matches){
body.classList.remove(HAS_STICKY_CLASS);
body.classList.remove(VISIBLE_CLASS);
return;
}
if(triggerPoint===null){
computeTriggerPoint();
}
var currentScroll =
window.scrollY ||
window.pageYOffset ||
document.documentElement.scrollTop ||
0;
if(currentScroll > triggerPoint){
if(!body.classList.contains(HAS_STICKY_CLASS)){
body.classList.add(HAS_STICKY_CLASS);
}
if(!body.classList.contains(VISIBLE_CLASS)){
body.classList.add(VISIBLE_CLASS);
}}else{
if(body.classList.contains(VISIBLE_CLASS)){
body.classList.remove(VISIBLE_CLASS);
}
if(body.classList.contains(HAS_STICKY_CLASS)){
body.classList.remove(HAS_STICKY_CLASS);
}}
}
function onScroll(){
if(!ticking){
ticking=true;
window.requestAnimationFrame(updateStickyState);
}}
function onResizeOrMqChange(){
if(!body.classList.contains(HAS_STICKY_CLASS)){
computeTriggerPoint();
}
updateStickyState();
}
function onDocumentClick(event){
if(!isVariableProduct) return;
if(!mobileMq.matches) return;
if(!body.classList.contains(HAS_STICKY_CLASS) ||
!body.classList.contains(VISIBLE_CLASS)
){
return;
}
if(!hasActiveVariation()) return;
if(cartForm.contains(event.target)){
return;
}
resetVariations();
}
document.addEventListener('click', onDocumentClick);
if(isVariableProduct&&addToCartButton){
addToCartButton.addEventListener('click', function (){
if(!hasActiveVariation()) return;
setTimeout(resetVariations, 400);
});
}
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onResizeOrMqChange);
if(typeof mobileMq.addEventListener==='function'){
mobileMq.addEventListener('change', onResizeOrMqChange);
}else if(typeof mobileMq.addListener==='function'){
mobileMq.addListener(onResizeOrMqChange);
}
computeTriggerPoint();
updateStickyState();
}
if(document.readyState==='complete'){
initStickyAddToCart();
}else{
window.addEventListener('load', initStickyAddToCart);
}})();
jQuery(function($){
if(!$('body').hasClass('woocommerce-cart')){
return;
}
var $body=$('body');
var $button=$('.cart_totals .wc-proceed-to-checkout .checkout-button').first();
var triggerBottom=null;
var stickyVisible=false;
if(!$button.length){
return;
}
function computeTrigger(){
$body.removeClass('has-sticky-checkout sticky-checkout-visible');
var off=$button.offset();
if(!off){
triggerBottom=null;
return;
}
triggerBottom=off.top + $button.outerHeight();
}
function showSticky(){
if(stickyVisible) return;
stickyVisible=true;
$body.addClass('has-sticky-checkout');
var fn=function(){
$body.addClass('sticky-checkout-visible');
};
if(window.requestAnimationFrame){
requestAnimationFrame(fn);
}else{
setTimeout(fn, 0);
}}
function hideSticky(){
if(!stickyVisible) return;
stickyVisible=false;
$body.removeClass('sticky-checkout-visible');
setTimeout(function(){
if(!$body.hasClass('sticky-checkout-visible')){
$body.removeClass('has-sticky-checkout');
}}, 360);
}
function updateStickyCheckout(){
var isMobile=window.innerWidth <=768;
if(!isMobile||triggerBottom===null){
hideSticky();
return;
}
var scrollTop=$(window).scrollTop();
if(scrollTop > triggerBottom){
showSticky();
}else{
hideSticky();
}}
$(window).on('scroll', updateStickyCheckout);
$(window).on('resize', function(){
computeTrigger();
updateStickyCheckout();
});
$(window).on('load', function(){
computeTrigger();
updateStickyCheckout();
});
$(document.body).on('updated_wc_div', function(){
$button=$('.cart_totals .wc-proceed-to-checkout .checkout-button').first();
computeTrigger();
updateStickyCheckout();
});
});