jQuery( function( $ ) { // Fixed header when scrolling var billowHeaderFixed = function() { if ( $( '.site-header' ).length ) { var headerFix = $( '.site-header' ).offset().top; $( window ).scroll( function() { var y = $( this ).scrollTop(); if ( y >= headerFix ) { $( '.site-header' ).addClass( 'fixed' ); $( 'body' ).addClass( 'siteScrolled' ); } else { $( '.site-header' ).removeClass( 'fixed' ); $( 'body' ).removeClass( 'siteScrolled' ); } if ( y >= 10 ) { $( '.site-header' ).addClass( 'float-header' ); } else { $( '.site-header' ).removeClass( 'float-header' ); } }); } }; // Dom Ready $( function() { return billowHeaderFixed(); }); // Scrolling $( function() { $( 'a.button-slider[href*="#"]' ).on( 'click',function ( e ) { var target = this.hash; var $target = $( target) ; if ( $target.length ) { e.preventDefault(); $( 'html, body' ).stop().animate( { 'scrollTop': $target.offset().top - 100 }, 900, 'swing' ); } }); } ); // Scroll to top $( function() { $( window ).scroll( function () { if ( $( this ).scrollTop () > 500) { $( '#scroll-to-top' ).fadeIn (); } else { $( '#scroll-to-top' ).fadeOut (); } }); $( '#scroll-to-top' ).click( function () { $( 'html, body' ).animate( { scrollTop: 0 }, 1000 ); }); } ); function addQuantityBoxes() { // Quantity buttons $( '.cart div.quantity:not(.buttons_added), .woocommerce-cart-form td.quantity:not(.buttons_added)' ) .addClass( 'buttons_added' ) .append( '
' ); $( '.quantity' ).unbind( 'click' ).on( 'click', '.plus, .minus', function() { // Get values var $qty = $( this ).closest( '.quantity' ).find( '.qty' ), currentVal = parseFloat( $qty.val() ), max = parseFloat( $qty.attr( 'max' ) ), min = parseFloat( $qty.attr( 'min' ) ), step = $qty.attr( 'step' ); // Format values if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0; if ( max === '' || max === 'NaN' ) max = ''; if ( min === '' || min === 'NaN' ) min = 0; if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) === 'NaN' ) step = 1; // Change the value if ( $( this ).is( '.plus' ) ) { if ( max && ( max == currentVal || currentVal > max ) ) { $qty.val( max ); } else { $qty.val( currentVal + parseFloat( step ) ); } } else { if ( min && ( min == currentVal || currentVal < min ) ) { $qty.val( min ); } else if ( currentVal > 0 ) { $qty.val( currentVal - parseFloat( step ) ); } } // Trigger change event $qty.trigger( 'change' ); }); $('.woocommerce-ordering .drop li a').on('click', function(e) { var form = $(this).closest('form'); form.find('[name=orderby]').val($(this).parent().data('value')); form.submit(); e.preventDefault(); }); $('.woocommerce .related > h2, .woocommerce .upsells > h2') .addClass('section-head').wrapInner(''); } $( document ).ready( addQuantityBoxes ); $( document ).ajaxComplete( addQuantityBoxes ); // Control product thumbs $( function() { if( $( "ol" ).is( ".flex-control-thumbs" ) ) { $( '.product.type-product' ).addClass( 'thumbs-left' ); } } ); // Menu open handler $( '.header-wrap .main-navigation .menu-toggle' ).on( 'click', function() { $( '.mobile-menu' ).addClass( 'active' ); $( 'body' ).toggleClass( 'mobile-menu-active' ); } ); // Setup the mobile menu click handlers $( '.mobile-menu li > a' ).each( function() { if ( $( this ).parent().children( 'ul' ).length ) { $( '' ).insertAfter( $( this ) ); } }); $( '.mobile-menu li .chevron' ).on( 'click', function() { $( this ).closest( 'li' ).find( 'ul' ).first().parent().toggleClass( 'active item-active' ); return false; } ); // Open my account menu in the mobile view $( document ).on( 'click', 'a.push-my-account-nav', function ( event ) { event.preventDefault(); var self = $( this ); var navContainer = $( this ).closest( '.woocommerce-MyAccount-navigation' ); navContainer.find( 'ul.woocommerce-MyAccount-menu' ).slideToggle(); } ); // Set focus on the close button after the last element in the menu list $('#mobile-menu #primary-menu li a').last().on('focus', function() { // "last" focus guard got focus: set focus to the first field $('#primary-mobile-menu').focus(); }); });