$(function() { var navFixedDefault = 'none'; var lastNavFixedState = null; $(window).on( "navFixed", function( event, fixed ) { if ( lastNavFixedState == null ) { lastNavFixedState = !fixed; } if ( lastNavFixedState === false && fixed === true ) { $(window).trigger( "navEnterFixed" ); $(window).trigger( "navLeaveHead" ); } else if ( lastNavFixedState === true && fixed === false ) { $(window).trigger( "navEnterHead" ); $(window).trigger( "navLeaveFixed" ); } lastNavFixedState = fixed; }); $( "#searchicon" ).click(function() { if ( lastNavFixedState || getNavHeadDefault() == 'none' ) { $( "#searchbar" ).toggle(); } if ( $( "#searchbar" ).is(":visible") ) { $( "#fsearchphrase_1" ).focus(); } return false; }); $(window).on( "navEnterFixed", function( event ) { //console.log( 'Enter fixed' ); //$('#searchbar').css('position', "fixed" ); $('#searchbar').addClass('head__search--fixed'); $('#searchbar').css('top', $('#mainbar').height() ); //$('#searchbar').css('left', 0 ); if ($('#searchbar .ui-autocomplete').hasClass( 'ui-autocomplete--active' )) { $('#searchbar').css( 'display', 'block' ); } else { $('#searchbar').css( 'display', navFixedDefault ); } if ( getNavHeadDefault() != 'none' ) { $('#searchicon').fadeIn( "slow", function() {}); } }); $(window).on( "navLeaveFixed", function( event ) { //console.log( 'Leave fixed' ); }); $(window).on( "navEnterHead", function( event ) { //console.log( 'Enter head' ); $('#searchbar').removeClass('head__search--fixed'); $('#searchbar').css( 'display', getNavHeadDefault() ); //$('#searchbar').css('position', "relative" ); //$('#searchbar').css('top', 0 ); var getOffCanvas = $(".navBar").css('overflow-y'); if ( getNavHeadDefault() != 'none' ) { $('#searchicon').fadeOut( "slow", function() {}); } }); $(window).on( "navLeaveHead", function( event ) { //console.log( 'Leave head' ); }); $(window).scroll(); });