/** * app.js * * Contain all handlers for JavaScript applications. */ ( function() { var lastTime = 0, vendors = [ 'ms', 'moz', 'webkit', 'o' ]; for ( var x = 0; x < vendors.length && ! window.requestAnimationFrame; x++ ) { window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ]; window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ]; } if ( ! window.requestAnimationFrame ) { window.requestAnimationFrame = function( callback, element ) { var currTime = new Date().getTime(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime) ); id = window.setTimeout( function() { callback( currTime + timeToCall ); }, timeToCall ); lastTime = currTime + timeToCall; return id; }; } if ( ! window.cancelAnimationFrame ) { window.cancelAnimationFrame = function( id ) { clearTimeout( id ); }; } } )(); var BE_APP = BE_APP || {}; ( function( $ ) { var $window = $( window ), $html = $( 'html' ), $body = $( 'body' ), $header = $( '#masthead' ), $nav = $( '#site-navigation' ), $anchorMenuItem = $( "ul.menu a[href^='#']:not([href='#'])" ), $mobileMenu = $( '#mobile-menu' ), $section = $( 'section' ), $fullScreen = $( '.full-screen' ), $goToTop = $( '#go-to-top' ); BE_APP.initialize = { init: function() { BE_APP.initialize.bootstrap(); BE_APP.initialize.responsiveClasses(); BE_APP.initialize.imageFade(); BE_APP.initialize.fullScreen(); BE_APP.initialize.topScrollOffset(); BE_APP.initialize.goToTop(); }, bootstrap: function() { $( 'table' ).addClass( 'table' ); $( 'form' ).addClass( 'clearfix' ); $( 'label input' ).addClass( 'form-control' ); $( 'input[type=submit]' ).addClass( 'btn btn-light btn-md' ); $( 'select' ).addClass( 'btn dropdown-toggle' ).wrap( '
' ); }, responsiveClasses: function() { var jRes = jRespond( [ { label: 'smallest', enter: 0, exit: 479 }, { label: 'handheld', enter: 480, exit: 767 }, { label: 'tablet', enter: 768, exit: 991 }, { label: 'laptop', enter: 992, exit: 1199 }, { label: 'desktop', enter: 1200, exit: 10000 } ] ); jRes.addFunc( [ { breakpoint: 'desktop', enter: function() { $body.addClass( 'device-lg' ); }, exit: function() { $body.removeClass( 'device-lg' ); } }, { breakpoint: 'laptop', enter: function() { $body.addClass( 'device-md' ); }, exit: function() { $body.removeClass( 'device-md' ); } }, { breakpoint: 'tablet', enter: function() { $body.addClass( 'device-sm' ); }, exit: function() { $body.removeClass( 'device-sm' ); } }, { breakpoint: 'handheld', enter: function() { $body.addClass( 'device-xs' ); }, exit: function() { $body.removeClass( 'device-xs' ); } }, { breakpoint: 'smallest', enter: function() { $body.addClass( 'device-xxs' ); }, exit: function() { $body.removeClass( 'device-xxs' ); } } ] ); if ( BE_APP.isMobile.any() ) { $body.addClass( 'device-touch' ); } }, imageFade: function() { $( '.image-fade' ).hover( function() { $( this ).animate( { opacity: 0.8 }, 500 ); }, function() { $( this ).animate( { opacity: 1 }, 500 ); } ) }, fullScreen: function() { var headerHeight = 0, wpAdminBarHeight = BE_APP.initialize.wpAdminBar(); if ( $body.hasClass( 'device-sm' ) || $body.hasClass( 'device-xs' ) || $body.hasClass( 'device-xxs' ) ) { headerHeight = 70; } if ( $fullScreen.length > 0 ) { $fullScreen.each( function() { var scrHeight = $window.height() - headerHeight - wpAdminBarHeight; $( this ).css( 'height', scrHeight ); } ); } }, topScrollOffset: function() { var topOffsetScroll = 0, adminBarHeight = BE_APP.initialize.wpAdminBar(); if ( $header.hasClass( 'sticky' ) ) { topOffsetScroll = adminBarHeight + 70; } else { topOffsetScroll = adminBarHeight; } return topOffsetScroll; }, wpAdminBar: function() { var wpAdminBarHeight = 0; if ( $body.hasClass( 'admin-bar' ) ) { wpAdminBarHeight = $( '#wpadminbar' ).height(); } return wpAdminBarHeight; }, goToTop: function() { $goToTop.click( function( e ) { $( 'body, html' ).stop( true ).animate( { scrollTop: 0 }, 500, 'easeInOutExpo' ); e.preventDefault(); } ); }, goToTopScroll: function() { if ( $body.hasClass( 'device-lg' ) || $body.hasClass( 'device-md' ) || $body.hasClass( 'device-sm' ) ) { if ( $window.scrollTop() > 450 ) { $goToTop.fadeIn(); } else { $goToTop.fadeOut(); } } } } BE_APP.header = { init: function() { BE_APP.header.anchorMenu(); BE_APP.header.headerMenu(); BE_APP.header.menuInvert(); BE_APP.header.mobileMenu(); }, anchorMenu : function() { $( "ul.menu a[href='#']" ).click( function( e ) { e.preventDefault(); } ); if ( $anchorMenuItem.length > 0 && befold_app_vars.current_page_url != befold_app_vars.home_url ) { $anchorMenuItem.each( function() { $( this ).attr( 'href', befold_app_vars.home_url + this.hash ); } ); } }, headerMenu: function() { var wpAdminBarHeight = BE_APP.initialize.wpAdminBar(), jRes = jRespond( [ { label: 'wpadminbar_600', enter: 0, exit: 600 }, { label: 'wpadminbar_782', enter: 601, exit: 782 } ] ); if ( $body.hasClass( 'admin-bar' ) ) { if ( jRes.getBreakpoint() != 'wpadminbar_600' ) { $header.css( 'margin-top', wpAdminBarHeight + 'px' ); } else { $header.css( 'padding-top', wpAdminBarHeight + 'px' ); } } if ( $body.hasClass( 'device-md' ) || $body.hasClass( 'device-lg' ) ) { if ( $window.scrollTop() > 0 ) { if ( $header.hasClass( 'sticky' ) && ! $header.hasClass( 'no-sticky' ) ) { $header.addClass( 'sticky-header' ); if ( $body.hasClass( 'admin-bar' ) ) { $header.css( 'margin-top', 0 ); } } } else { if ( $header.hasClass( 'sticky-header' ) ) { $header.removeClass( 'sticky-header' ); $header.css( 'top', 0 ); } } } else { $( '#masthead:not(.no-sticky)' ).addClass( 'sticky-header' ); } if ( $body.hasClass( 'device-sm' ) || $body.hasClass( 'device-xs' ) || $body.hasClass( 'device-xxs' ) ) { if ( $header.hasClass( 'sticky-header' ) ) { $( '.page-header' ).css( { 'top': 70 + wpAdminBarHeight + 'px', 'margin-bottom': 70 + wpAdminBarHeight + 'px' } ); if ( $body.hasClass( 'admin-bar' ) ) { $header.css( { 'margin-top': 0, 'padding-top': 0 } ); } } else { $( '.page-header' ).css( { 'top': 0, 'margin-bottom': 0 } ); } } else { $( '.page-header' ).css( { 'top': '-85px', 'margin-bottom': '-85px' } ); } if ( $header.hasClass( 'sticky-header' ) ) { if ( wpAdminBarHeight == 32 || ( jRes.getBreakpoint() == 'wpadminbar_782' && wpAdminBarHeight == 46 ) ) { $header.css( 'top', wpAdminBarHeight + 'px' ); } if ( $body.hasClass( 'device-sm' ) || $body.hasClass( 'device-xs' ) || $body.hasClass( 'device-xxs' ) ) { if ( jRes.getBreakpoint() == 'wpadminbar_600' ) { if ( $window.scrollTop() > wpAdminBarHeight ) { $header.css( 'top', 0 ); } else { $header.css( 'top', wpAdminBarHeight - $window.scrollTop() + 'px' ); } } } } }, menuInvert: function() { $( '.main-navigation ul ul' ).each( function( index, element ) { var $menuChildElement = $( element ), windowWidth = $window.width(), menuChildOffset = $menuChildElement.offset(), menuChildWidth = $menuChildElement.width(), menuChildLeft = menuChildOffset.left; if ( windowWidth - ( menuChildWidth + menuChildLeft ) < 0 ) { $menuChildElement.addClass( 'menu-pos-invert' ); } } ); }, mobileMenu: function() { $mobileMenu.click( function() { $mobileMenu.toggleClass( 'closed' ); if ( $mobileMenu.hasClass( 'closed' ) ) { var wpAdminBarHeight = BE_APP.initialize.wpAdminBar(); $nav.slideDown(); setTimeout( function() { if ( $nav.height() + $nav.offset().top > $window.height() ) { $nav.css( 'height', $window.height() - 70 - wpAdminBarHeight + 'px' ); } }, 500 ); } else { $nav.slideUp(); } } ); }, activateCurrentMenu: function() { $anchorMenuItem.each( function() { var sectionContainer = $( 'section' + this.hash ), windowScrollTop = $window.scrollTop(), topOffsetScroll = BE_APP.initialize.topScrollOffset(); if ( sectionContainer.length > 0 ) { var sectionOffset = sectionContainer.offset().top; if ( sectionOffset - windowScrollTop - topOffsetScroll <= 5 ) { $( this ).closest( 'ul' ).children().removeClass( 'current-menu-item' ); $( this ).parent().addClass( 'current-menu-item' ); } else { $( this ).parent().removeClass( 'current-menu-item' ); } } } ); } } BE_APP.isMobile = { Android: function() { return navigator.userAgent.match( /Android/i ); }, BlackBerry: function() { return navigator.userAgent.match( /BlackBerry/i ); }, iOS: function() { return navigator.userAgent.match( /iPhone|iPad|iPod/i ); }, Opera: function() { return navigator.userAgent.match( /Opera Mini/i ); }, Windows: function() { return navigator.userAgent.match( /IEMobile/i ); }, any: function() { return ( BE_APP.isMobile.Android() || BE_APP.isMobile.BlackBerry() || BE_APP.isMobile.iOS() || BE_APP.isMobile.Opera() || BE_APP.isMobile.Windows() ); } } BE_APP.documentOnReady = { init: function() { BE_APP.initialize.init(); BE_APP.header.init(); } } BE_APP.documentOnScroll = { init: function() { BE_APP.initialize.goToTopScroll(); BE_APP.header.activateCurrentMenu(); BE_APP.header.headerMenu(); } } BE_APP.documentOnResize = { init: function() { setTimeout( function() { BE_APP.header.headerMenu(); BE_APP.header.menuInvert(); if ( ! BE_APP.isMobile.any() ) { BE_APP.initialize.fullScreen(); } }, 500 ); } } $( document ).ready( BE_APP.documentOnReady.init ); $window.on( 'scroll', BE_APP.documentOnScroll.init ); $window.on( 'resize', BE_APP.documentOnResize.init ); } )( jQuery );