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('' + menuTitle + ''); 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('' + menuTitle + ''); 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 = ''; productName = jQuery('.product-shop > h1').text(); popupHtml = productImage + ''+productName+' '+al_text.success_msg+'
'+al_text.ok+''+al_text.go_cart+'
'; popupWindow.find('.alanah-popup-content').css('backgroundImage','none').html(popupHtml); jQuery('.cont-shop').one('click',function(){ hidePopup(popupOverlay,popupWindow); }); alanah_add_to_cart_fragments( fragments, cart_hash, this_page, $thisbutton ); } //complete function }); // Ajax }); /* List "add to cart" (add-to-cart.js edit) */ // Ajax add to cart jQuery(document).on( 'click', '.alanah_add_to_cart_button', function() { // AJAX add to cart request var $thisbutton = jQuery(this); if ($thisbutton.is('.product_type_simple, .product_type_downloadable, .product_type_virtual')) { if (!$thisbutton.attr('data-product_id')) return true; $thisbutton.removeClass('added'); $thisbutton.addClass('loading'); var data = { action: 'woocommerce_add_to_cart', product_id: $thisbutton.attr('data-product_id'), quantity: $thisbutton.attr('data-quantity'), security: wc_add_to_cart_params.add_to_cart_nonce }; // Trigger event jQuery('body').trigger( 'adding_to_cart', [ $thisbutton, data ] ); // Ajax action jQuery.post( wc_add_to_cart_params.ajax_url, data, function( response ) { if ( ! response ) return; var this_page = window.location.toString(); fragments = response.fragments; cart_hash = response.cart_hash; if ( response.error && response.product_url ) { window.location = response.product_url; return; } // Redirect to cart option if ( wc_add_to_cart_params.cart_redireal_after_add == 'yes' ) { window.location = wc_add_to_cart_params.cart_url; return; } else { $thisbutton.removeClass('loading'); alanah_add_to_cart_fragments( fragments, cart_hash, this_page, $thisbutton ); } }); return false; } else { return true; } }); //Top bar jQuery( 'a.topexpand' ).on( 'click', function(){ jQuery(this).toggleClass( 'active '); jQuery(this).closest( '.top-elements' ).toggleClass( 'expand' ); }); //Woocommerce Product Qty +/- Buttons jQuery('body').on( 'click', '.qty-block button.plus, .qty-block button.minus', function() { // Get current quantity values var qty = jQuery( this ).closest( '.quantity' ).find( '.qty' ); var val = parseInt( qty.val() ); var max = qty.attr( 'max' ); var min = qty.attr( 'min' ); var step = parseInt( qty.attr( 'step' ) ); if( min == '' ) min = 1; if( max == '' ) max = 100; if( step == '' ) step = 1; // Change the value if plus or minus if ( jQuery( this ).is( '.plus' ) ) { if ( max && ( max <= val ) ) { alert(max); qty.val( max ); } else { qty.val( val + step ); } } else { if ( min && ( min >= val ) ) { qty.val( min ); } else if ( val > 1 ) { qty.val( val - step ); } } qty.trigger( 'change' ); }); //End Click }); // End Ready /* Product Hover -------------------------------------------------------------- */ function hideImage(img){ //Opera fix var block = jQuery(img).parent().parent().parent(); block.height(block.height()); //alert(blockHeight); jQuery(img).animate({ 'opacity' : 0 },300); } function showImage(img){ jQuery(img).animate({ 'opacity' : 1 },300); } function showPopup(){ html = '
' jQuery('body').prepend(html); popupOverlay = jQuery('.alanah-popup-overlay'); popupWindow = jQuery('.alanah-popup'); popupOverlay.one('click',function(){ hidePopup(popupOverlay,popupWindow); }); } function hidePopup(popupOverlay,popupWindow){ popupOverlay.fadeOut(400); popupWindow.fadeOut(400).html(''); }