( function( $ ) { $( window ).load( function() { $( '.page-template-template-frontpage .front-page' ).css( { 'opacity' : 1, 'position' : 'static' }); $( '.page-template-template-frontpage' ).addClass( 'loaded' ); } ); /** Show header menu top-fixed as you scroll up the page. */ var lastScrollTop = 0; $( window ).scroll( function( evnt ) { var scrollTop = $( window ).scrollTop() || document.documentElement.scrollTop; if ( $( window ).width() > 786 ) { if ( lastScrollTop > scrollTop ) { $( '.header-menu' ).addClass( 'header-menu-fixed' ); if ( scrollTop < $( '.header-cover' ).height() ) { $( '.header-menu' ).css( { 'top' : '0' } ); $( '.header-menu' ).removeClass( 'header-menu-fixed' ); } } else { if ( scrollTop > $( '.header-cover' ).height() ) { $( '.header-menu' ).css( { 'top' : '-60px' } ); $( '.header-menu' ).removeClass( 'header-menu-fixed' ); } } lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; } } ); /** Site brand & main menu reset states for primary & mobile. */ if ( $( window ).width() < 786 ) { $( '.header-brand' ).addClass( 'header-brand-full' ); } else { $( '.header-brand' ).removeClass( 'header-brand-full' ); } $( window ).scroll( function( evnt ) { if ( $( window ).scrollTop() > 60 && $( window ).width() > 786 ) { $( '.header-brand' ).addClass( 'header-brand-small' ); } else { $( '.header-brand' ).removeClass( 'header-brand-small' ); } } ); $( window ).resize( function( evnt ) { if ( $( window ).width() < 786 ) { $( '.header-brand' ).addClass( 'header-brand-full' ); $( '.header-menu' ).css( { 'top' : '0' } ); $( '.header-menu' ).removeClass( 'header-menu-fixed' ); } else { $( '.header-brand' ).removeClass( 'header-brand-full' ); } if ( $( window ).width() > 786 ) { $( '.primary-menu' ).css( { 'display' : 'flex' } ); } else { $( '.primary-menu' ).hide(); $( '.primary-menu-toggle' ).addClass( 'fa-icon-bars' ).removeClass( 'fa-icon-close' ); $( '.primary-menu-toggle small' ).text( 'Menu' ); } } ); /** Search bar toggle. */ $( document ).on( 'click', '.menu-item-type-search a', function( evnt ) { evnt.preventDefault(); $( this ).next().fadeToggle( 400 ).css( { 'display' : 'flex' } ); $( this ).toggleClass( 'fa-icon-search' ).toggleClass( 'fa-icon-close' ); } ); /** Header & footer menus. */ $( document ).on( 'click', '.menu-item-has-children > a, .page_item_has_children > a', function( evnt ) { evnt.preventDefault(); if ( $( this ).hasClass( 'current-menu-item' ) ) { // Close (toggle) top level items. $( this ).removeClass( 'current-menu-item' ); $( this ).parent().find( '> ul, > .menu > ul' ).slideUp().removeClass( 'sub-menu-open' ); } else { if ( $( this ).closest( '.sub-menu-open' ).length ) { // Toggle all sub level items. $( this ).addClass( 'current-menu-item' ); $( this ).parent().find( '> ul, > .menu > ul' ).slideDown().addClass( 'sub-menu-open' ); } else { // Reset all level items. $( this ).closest( '.menu' ).find( '.menu-item-has-children > ul, .menu-item-has-children > .menu > ul, .page_item_has_children > ul, .page_item_has_children > .menu > ul' ).slideUp().removeClass( 'sub-menu-open' ); $( this ).closest( '.menu' ).find( '.menu-item-has-children > a, .menu-item-has-children > .menu > a, .page_item_has_children > a, .page_item_has_children > .menu > a' ).removeClass( 'current-menu-item' ); // Open (toggle) top level items. $( this ).addClass( 'current-menu-item' ); $( this ).parent().find( '> ul, > .menu > ul' ).slideDown().addClass( 'sub-menu-open' ); } } // Check sub-menu is offscreen. if ( $( this ).parent().find( '> ul, > .menu > ul' ).visible() === false ) { if ( $( this ).parent().parent().hasClass( 'primary-menu' ) ) { $( this ).parent().find( '> ul, > .menu > ul' ).css( { 'left' : parseInt( $( this ).parent().find( '> ul, > .menu > ul' ).width() - $( this ).parent().width() ) * -1 + 'px' } ); } else { $( this ).parent().find( '> ul, > .menu > ul' ).css( { 'left' : parseInt( $( this ).parent().find( '> ul, > .menu > ul' ).width() + 1 ) * -1 + 'px' } ); } } } ); /** Mobile menu icon toggle. */ $( document ).on( 'click', 'a.primary-menu-toggle', function( evnt ) { evnt.preventDefault(); $( '.primary-menu' ).slideToggle(); $( this ).toggleClass( 'fa-icon-bars' ).toggleClass( 'fa-icon-close' ); $( 'small', this ).toggleText( 'Close', 'Menu' ); } ); $( document ).on( 'click', 'a.mobile-menu-toggle', function( evnt ) { evnt.preventDefault(); $( '.mobile-menu' ).animate( { 'width' : 'toggle', 'opacity' : 'toggle' }, 400 ); // $( this ).toggleClass( 'fa-icon-bars' ).toggleClass( 'fa-icon-close' ); if ( $( '.body-overlay' ).length ) { $( '.body-overlay' ).remove(); } else { $( 'body' ).append( '
' ); } } ); $( document ).on( 'click', '.body-overlay', function( evnt ) { $( '.mobile-menu' ).animate( { 'width' : 'toggle', 'opacity' : 'toggle' }, 400 ); // $( '.mobile-menu-toggle' ).toggleClass( 'fa-icon-bars' ).toggleClass( 'fa-icon-close' ); $( this ).remove(); } ); /** Re-align footer widgets containers. */ $( '.footer-widgets .widgets' ).each( function( idx, elem ) { var widgetCount = $( elem ).find( '.widgets-container' ).length; $( elem ).children( '.widgets-container' ).css( { 'flex' : '0 0 calc(' + 100 / widgetCount + '% - 2rem)' } ); } ); /** Footer gallery (sponsors) slider. */ var counter = 1; var sliderWidth = 0; var containerWidth = $( '.footer-gallery .container' ).width(); $( '.footer-gallery .gallery .gallery-item' ).each( function( idx, elem ) { sliderWidth += $( elem ).outerWidth( true ); } ); $( '.footer-gallery .gallery' ).width( sliderWidth ); setInterval( function() { if ( counter > sliderWidth / containerWidth ) { $( '.footer-gallery .gallery' ).animate( { 'margin-left' : '0' } ); } else { $( '.footer-gallery .gallery' ).animate( { 'margin-left' : '-=' + containerWidth + 'px' } ); } counter++; }, 4000 ); /** Masonry style CSS grid. */ setTimeout( function() { $( '.grid-loading' ).hide(); $( '.grid' ).animate( { 'opacity' : 1, 'max-height' : '100%' }, 800 ); gridBuilder(); }, 1600 ); $( window ).resize( function( evnt ) { gridBuilder(); } ); function gridBuilder() { $( '.grid-item' ).each( function( idx, elem ) { var $grid = $( '.grid' ); var $gridItem = $( this ); var $gridContent = $( '.grid-item-body', this ); // Row var rHeight = parseInt( $grid.css( 'grid-auto-rows').replace( 'px', '' ) ); var rGap = parseInt( $grid.css( 'grid-row-gap').replace( 'px', '' ) ); var rSpan = Math.ceil( ( $gridContent.height() + rGap ) / ( rHeight + rGap ) ); $gridItem.css( 'grid-row-end', 'span ' + rSpan ); }); } /** Comments content toggle. */ $( document ).on( 'click', '.post-comments-list .comment-content', function( evnt ) { if ( $( this ).css( 'max-height' ) === '240px' ) { $( this ).css( { 'max-height' : 'unset', 'overflow-y' : 'none' } ); $( this ).addClass( 'comment-content-open' ); } else { $( this ).css( { 'max-height' : '240px', 'overflow-y' : 'hidden' } ); $( this ).removeClass( 'comment-content-open' ); } } ); /** Scroll down to main content area for blog pagination. */ $( '.pagination-button-prev a' ).attr( 'href', $( '.pagination-button-prev a' ).attr( 'href' ) + '#main-content' ); $( '.pagination-button-next a' ).attr( 'href', $( '.pagination-button-next a' ).attr( 'href' ) + '#main-content' ); /** Scroll smoothly to top. */ $( document ).on( 'click', 'a.to-the-top', function( evnt ) { evnt.preventDefault(); window.scrollTo( { 'top' : 0, 'behavior' : 'smooth' } ); } ); /** Scroll smoothly to section based on window hash. */ if ( window.location.hash ) { $( 'html, body' ).animate( { scrollTop: $( window.location.hash ).offset().top }, 1200 ); } /** Initialize and add parallax effect with parallax.js. */ var scene = document.getElementById( 'header-parallax' ); if ( scene !== null ) { var parallaxInstance = new Parallax( scene ); } var scene2 = document.getElementById( 'product-parallax' ); if ( scene2 !== null ) { var parallaxInstance = new Parallax( scene2 ); } } ) ( jQuery );