jQuery(document).ready(function(){ /* Refresh Cart Fragments on Ajax add to cart -------------------------------------------------------------- */ function alanah_add_to_cart_fragments( fragments, cart_hash, this_page, $thisbutton ) { //Flush Class this_page = this_page.replace( 'add-to-cart', 'added-to-cart' ); // Block fragments class if ( fragments ) { jQuery.each( fragments, function( key, value ) { jQuery(key).addClass( 'updating' ); }); } // Block widgets and fragments jQuery( '.shop_table.cart, .updating, .cart_totals' ).fadeTo( '400', '0.6' ).block({ message: null, overlayCSS: { background: 'transparent url( ' + wc_add_to_cart_params.ajax_loader_url + ' ) no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } }); // Changes button classes if ( $thisbutton !== null && $thisbutton.parent().find('.added_to_cart').size() == 0 ) $thisbutton.addClass('added').after( ' ' + wc_add_to_cart_params.i18n_view_cart + '' ); // Replace fragments if ( fragments ) { jQuery.each(fragments, function(key, value) { jQuery(key).replaceWith(value); }); } // Unblock jQuery('.widget_shopping_cart, .updating').stop(true).css('opacity', '1').unblock(); // Cart widget load if ( jQuery('.widget_shopping_cart').size() > 0 ) { jQuery( '.widget_shopping_cart:eq(0)' ).load( this_page + ' .widget_shopping_cart:eq(0) > *', function() { // Replace fragments if ( fragments ) { jQuery.each( fragments, function( key, value ) { jQuery(key).replaceWith(value); }); } // Unblock jQuery( '.widget_shopping_cart, .updating' ).stop(true).css( 'opacity', '1' ).unblock(); jQuery( 'body' ).trigger( 'cart_widget_refreshed' ); }); } // Trigger event so themes can refresh other areas jQuery('body').trigger( 'added_to_cart', [ fragments, cart_hash ] ); } /* Hover intent for Desktop's -------------------------------------------------------------- */ if( jQuery(window).width() > 767 ) { jQuery('#top-cart').hoverIntent( function () { jQuery(".cart-popup").stop().slideDown(100); }, function () { jQuery(".cart-popup").stop().slideUp(100); } ); } /* Sticky Header -------------------------------------------------------------- */ jQuery( window ).scroll( function(){ var sticky = jQuery( '.header-sticky' ), scroll = jQuery( window ).scrollTop(); if ( scroll >= 150 ) sticky.css( 'top', '0' ); else sticky.css( 'top', '-80px' ); }); /* jQuery Countdown timer -------------------------------------------------------------- */ if( jQuery( '.expirytimer' ).length ) { jQuery( '.expirytimer' ).each(function(){ var _self = jQuery( this ); var expdate = _self.data( 'date' ); // Set the date we're counting down to var countDownDate = new Date( expdate ).getTime(); // Update the count down every 1 second var x = setInterval(function() { // Get today's date and time var now = new Date().getTime(); // Find the distance between now and the count down date var distance = countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor( distance / ( 1000 * 60 * 60 * 24 ) ); var hours = Math.floor( ( distance % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ); var minutes = Math.floor( ( distance % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ); var seconds = Math.floor( ( distance % ( 1000 * 60 ) ) / 1000 ); // Display the result var counter = ''; if( days > 0 ) { counter = ( days > 1 ) ? days + 'Days : ' : days + 'Day : '; } if( days > 0 || hours > 0 ) { counter += ( hours > 1 ) ? hours + 'Hours : ' : hours + 'Hour : '; } if( days > 0 || hours > 0 || minutes > 0 ) { counter += ( minutes > 1 ) ? minutes + 'Mins : ' : minutes + 'Min : '; } counter += seconds + 'Secs '; _self.html( '' + counter + '' ); // If the count down is finished, write some text if ( distance < 0 ) { clearInterval(x); _self.html( 'EXPIRED' ); } }, 1000); }); } /* Top Cart click Behaviour for mobiles ---------------------------------------------------------------*/ if( jQuery(window).width() < 767 ) { jQuery('#top-cart').on( 'click', function(){ jQuery(this).find( '.cart-popup' ).slideToggle(100); }); } /* Tabs -------------------------------------------------------------- */ jQuery('.product-tabs').each(function(){ var tabs = jQuery(this); tabs.children('li').first().children('a').addClass('active') .next().addClass('is-open').show(); tabs.on('click', 'li > a', function(e) { e.preventDefault(); if (!jQuery(this).hasClass('active')) { tabs.find('.is-open').removeClass('is-open').hide(); jQuery(this).next().toggleClass('is-open').toggle(); tabs.find('.active').removeClass('active'); jQuery(this).addClass('active'); } else { //tabs.find('.is-open').removeClass('is-open').hide(); //jQuery(this).removeClass('active'); } }); }); /* "Top" button -------------------------------------------------------------- */ var scroll_timer; var displayed = false; var $message = jQuery('#back-to-top'); var $window = jQuery(window); var top = jQuery(document.body).children(0).position().top; $window.scroll(function () { window.clearTimeout(scroll_timer); scroll_timer = window.setTimeout(function () { if($window.scrollTop() <= top) { displayed = false; $message.fadeOut(500); } else if(displayed == false) { displayed = true; $message.stop(true, true).fadeIn(500).click(function () { $message.fadeOut(500); }); } }, 400); }); jQuery('#top-link').click(function(e) { jQuery('html, body').animate({scrollTop:0}, 'slow'); return false; }); /* Product Categories Accordion Navigation -------------------------------------------------------------- */ jQuery(function(){ jQuery('.block.cats').addClass('acc_enabled'); jQuery('.categories-group').each(function(){ jQuery(this).has('.al_top_level_categories').addClass('has-subnav'); jQuery(this).has('.current-cat').addClass('current-parent opened'); }); var nav_section = jQuery('.categories-group .al_top_level_categories'); var nav_toggle_element = jQuery('.categories-group .al_category_title .btn-show '); var nav_speed = 150; nav_toggle_element.click(function(){ if(jQuery(this).parent().parent().hasClass('opened')){ hideActiveSection(); }else{ showNext(jQuery(this)); } }); if(jQuery('.categories-group.opened').length > 0) { //jQuery('.categories-group.has-subnav').addClass('opened'); }else{ // If doesnt exitst opened point jQuery('.categories-group.has-subnav:first').addClass('opened').find('ul').show(); } function showNext(element) { hideActiveSection(); element.parent().parent().addClass('opened'); element.parent().next().show(nav_speed); } function hideActiveSection(){ jQuery('.categories-group.opened').removeClass('opened').find('.al_top_level_categories').hide(nav_speed); } }); /* alanahCommentForm -------------------------------------------------------------- */ var alanahCommentForm = jQuery('#commentform'); alanahCommentForm.find('#submit').click(function(e){ jQuery('#commentsMsgs').html(''); var errmsg; errmsg = ''; alanahCommentForm.find('.required-field').each(function(){ if(jQuery(this).val() == '') { errmsg = isRequired; jQuery(this).addClass('validation-failed');; } }); if(errmsg){ e.preventDefault(); jQuery('#commentsMsgs').html('
' + errmsg + '
'); } }); /* Mobile navigation -------------------------------------------------------------- */ var navList = jQuery('#main-nav > ul, div.menu > ul').clone(); var etOpener = '(open)'; navList.removeClass('menu').addClass('et-mobile-menu'); navList.before(''); navList.find('li:has(ul)',this).each(function() { jQuery(this).prepend(etOpener); }) jQuery( 'body' ).on( 'click', '.et-mobile-menu .open-child', function(){ if( jQuery(this).parent().hasClass( 'over' ) ) { jQuery(this).parent().removeClass('over').find('>ul').slideUp(200); } else { jQuery(this).parent().addClass('over').find('>ul').slideDown(200); } }); jQuery('#main-nav, div.menu').after(navList).after(''); jQuery('.et-menu-title').click(function(){ jQuery(this).next().slideToggle(200); }); /* Superfish menu -------------------------------------------------------------- */ jQuery('#main-nav > ul, .menu > ul').superfish({ hoverClass: 'over', shadow: false, delay: 100 }); /* Woo -------------------------------------------------------------- */ // Ajax add to cart jQuery( '.single-product form.cart.ajaxify' ).on( 'submit', function(e) { e.preventDefault(); var form = jQuery(this); var this_page = window.location.toString(); var $thisbutton = form.find( '.single_add_to_cart_button' ); showPopup(); jQuery('#top-cart').addClass('updating'); popupOverlay = jQuery('.alanah-popup-overlay'); popupWindow = jQuery('.alanah-popup'); var formData = new FormData(form[0]); formData.append('add-to-cart', form.find('[name=add-to-cart]').val() ); // Ajax action. jQuery.ajax({ url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'alanah_add_to_cart' ), data: formData, type: 'POST', processData: false, contentType: false, complete: function( response ) { response = response.responseJSON; if ( ! response ) { return; } if ( response.error && response.product_url ) { window.location = response.product_url; return; } $thisbutton = null; fragments = response.fragments; cart_hash = response.cart_hash; // Trigger event so themes can refresh other areas. jQuery( document.body ).trigger( 'added_to_cart', [ fragments, cart_hash, $thisbutton ] ); // Remove existing notices jQuery( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove(); // Add new notices form.closest('.product').before(response.fragments.notices_html); productImageSrc = jQuery('.main-image img').attr('src'); productImage = '