jQuery( function( $ ) { var headerFixed = 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 headerFixed(); }); // 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 ); }); } ); /**s * Plus/minus polyfill for numbers - used in WooCommerce * */ function wcProductQty() { $( 'form.cart .blw-quantity' ).each( function () { var spinner = $( this ), input = spinner.find( 'input[type="number"]' ), btnUp = spinner.find( '.quantity-up' ), btnDown = spinner.find( '.quantity-down' ), min = input.attr( 'min' ), max = input.attr( 'max' ); btnUp.click( function () { var oldValue = parseFloat( input.val() ); if ( max.length === 0 ) { var newVal = oldValue + 1; } else { if ( oldValue >= max ) { var newVal = oldValue; } else { var newVal = oldValue + 1; } } spinner.find( "input" ).val( newVal ); spinner.find( "input" ).trigger( "change" ); } ); btnDown.click( function () { var oldValue = parseFloat( input.val() ); if ( oldValue <= min ) { var newVal = oldValue; } else { var newVal = oldValue - 1; } spinner.find( "input" ).val( newVal ); spinner.find( "input" ).trigger( "change" ); } ); } ); } function wcCartQty() { $( '.woocommerce-cart-form .blw-quantity' ).each( function () { var spinner = $( this ), input = spinner.find( 'input[type="number"]' ), btnUp = spinner.find( '.quantity-up' ), btnDown = spinner.find( '.quantity-down' ), min = input.attr( 'min' ), max = input.attr( 'max' ), curValue = parseFloat( input.val() ); if ( curValue == 0 ) { btnDown.addClass( 'limit' ); } btnUp.click( function () { var oldValue = parseFloat( input.val() ); btnDown.removeClass( 'limit' ); if ( oldValue == max - 1 ) { btnUp.addClass( 'limit' ); } if ( max.length === 0 ) { var newVal = oldValue + 1; } else { if ( oldValue >= max ) { var newVal = oldValue; } else { var newVal = oldValue + 1; } } spinner.find( "input" ).val( newVal ); spinner.find( "input" ).trigger( "change" ); } ); btnDown.click( function () { var oldValue = parseFloat( input.val() ); if ( oldValue == min + 1 ) { btnDown.addClass( 'limit' ); } if ( oldValue <= min ) { var newVal = oldValue; } else { var newVal = oldValue - 1; btnUp.removeClass( 'limit' ); } spinner.find( "input" ).val( newVal ); spinner.find( "input" ).trigger( "change" ); } ); } ); } wcProductQty(); wcCartQty(); // 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' ); } ); // Off close $( '.mobile-menu-container.off .close' ).on( 'click', function() { $( 'body' ).toggleClass( 'mobile-menu-active' ); } ); // Setup 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 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(); } ); });