2013-07-29 00:55:10 +02:00
|
|
|
( function( $ ) {
|
|
|
|
|
|
|
|
$( document ).ready( function() {
|
|
|
|
|
|
|
|
var $primaryNaviClone,
|
|
|
|
$secondaryNaviClone,
|
2013-08-20 19:31:08 +02:00
|
|
|
$masthead = $( '#masthead' ),
|
|
|
|
$secondaryTop = $( '#secondary-top' ),
|
|
|
|
$mobileNavigations = $( '#mobile-navigations'),
|
2013-07-29 00:55:10 +02:00
|
|
|
$searchBoxWrapper = $( 'div.search-box-wrapper' ),
|
|
|
|
$searchToggle = $( 'div.search-toggle' ),
|
|
|
|
timeout = false;
|
|
|
|
|
|
|
|
// Toggle function.
|
|
|
|
function menuToggle() {
|
|
|
|
$( 'span#nav-toggle' ).toggleClass( 'active' );
|
2013-08-20 19:31:08 +02:00
|
|
|
$masthead.find( '#mobile-navigations' ).toggleClass( 'hide' );
|
2013-07-29 00:55:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Click event for toggle the search
|
|
|
|
$searchToggle.click( function() {
|
|
|
|
$( this ).toggleClass( 'active' );
|
|
|
|
$searchBoxWrapper.toggleClass( 'hide' );
|
2013-09-02 23:25:10 +02:00
|
|
|
|
2013-08-20 19:46:08 +02:00
|
|
|
if ( $( this ).hasClass( 'active' ) )
|
|
|
|
$searchBoxWrapper.find( '.search-field' ).focus();
|
2013-07-29 00:55:10 +02:00
|
|
|
} );
|
|
|
|
|
2013-08-23 00:01:08 +02:00
|
|
|
// DOM manipulations for mobile header
|
2013-07-29 00:55:10 +02:00
|
|
|
function mobileHeader() {
|
|
|
|
// Check if the toggler exists. If not add it.
|
2013-08-20 19:31:08 +02:00
|
|
|
if ( ! $( '#nav-toggle' ).length )
|
2013-07-29 00:55:10 +02:00
|
|
|
$( '<span id="nav-toggle" class="genericon" />' ).appendTo( $masthead );
|
|
|
|
|
|
|
|
// Clone and detach the primary navigation for use later
|
|
|
|
$primaryNaviClone = $masthead.find( 'nav.primary-navigation' ).detach();
|
|
|
|
|
|
|
|
// Clone and detach the secondary navigation for use later
|
|
|
|
$secondaryNaviClone = $secondaryTop.find( 'nav.secondary-navigation' ).detach();
|
|
|
|
|
|
|
|
// Prepend the primary navigation clone to #mobile-navigations and remove the class and add an id
|
|
|
|
$primaryNaviClone.prependTo( $mobileNavigations ).removeClass( 'primary-navigation' ).addClass( 'mobile-navigation' ).attr( 'id', 'primary-mobile-navigation' );
|
|
|
|
|
|
|
|
// Append the secondary navigation clone to #mobile-navigations and remove the class and add an id
|
|
|
|
$secondaryNaviClone.appendTo( $mobileNavigations ).removeClass( 'secondary-navigation' ).addClass( 'mobile-navigation' ).attr( 'id', 'secondary-mobile-navigation' );
|
|
|
|
|
|
|
|
// Remove the click event first and bind it after to make sure it's invoked once.
|
|
|
|
$( 'span#nav-toggle' ).off( 'click', menuToggle ).click( menuToggle );
|
|
|
|
};
|
|
|
|
|
|
|
|
// DOM manupilations for desktop header
|
|
|
|
function normalHeader() {
|
|
|
|
// Check if the toggler exists. If it does remove it.
|
|
|
|
if ( $( 'span#nav-toggle').length )
|
|
|
|
$( 'span#nav-toggle' ).remove();
|
|
|
|
|
|
|
|
// Clone and detach the primary mobile navigation for use later
|
|
|
|
$primaryNaviClone = $mobileNavigations.find( '#primary-mobile-navigation' ).detach();
|
|
|
|
|
|
|
|
// Clone and detach the secondary mobile navigation for use later
|
|
|
|
$secondaryNaviClone = $mobileNavigations.find( '#secondary-mobile-navigation' ).detach();
|
|
|
|
|
|
|
|
// Append the secondary navigation clone to #mobile-navigations and remove the class and add an id
|
|
|
|
$primaryNaviClone.appendTo( '.header-main' ).removeClass( 'mobile-navigation' ).removeAttr( 'id' ).addClass( 'primary-navigation' );
|
|
|
|
|
|
|
|
// Append the secondary navigation clone to #mobile-navigations and remove the class and add an id
|
|
|
|
$secondaryNaviClone.appendTo( $secondaryTop ).removeClass( 'mobile-navigation' ).removeAttr( 'id' ).addClass( 'secondary-navigation' );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check viewport width when user resizes the browser window.
|
|
|
|
$( window ).resize( function() {
|
|
|
|
if ( false !== timeout )
|
|
|
|
clearTimeout( timeout );
|
|
|
|
|
|
|
|
timeout = setTimeout( function() {
|
|
|
|
if ( $( window ).width() < 770 ) {
|
|
|
|
mobileHeader();
|
|
|
|
} else {
|
|
|
|
normalHeader();
|
|
|
|
}
|
|
|
|
}, 100 );
|
|
|
|
|
|
|
|
} ).resize();
|
|
|
|
|
|
|
|
// Sticky header.
|
|
|
|
var $mastheadOffset = -1,
|
|
|
|
$toolbarOffset = $( 'body' ).is( '.admin-bar' ) ? 32 : 0,
|
2013-08-20 19:31:08 +02:00
|
|
|
$maindiv = $( '#main' );
|
2013-07-29 00:55:10 +02:00
|
|
|
|
|
|
|
$( window ).on( 'scroll', false, function() {
|
|
|
|
if ( $mastheadOffset < 0 )
|
|
|
|
$mastheadOffset = $masthead.offset().top - $toolbarOffset;
|
|
|
|
|
2013-08-20 19:37:10 +02:00
|
|
|
if ( ( window.scrollY > $mastheadOffset ) && ( $( window ).width() > 769 ) ) {
|
2013-07-29 00:55:10 +02:00
|
|
|
$masthead.addClass( 'masthead-fixed' );
|
|
|
|
$maindiv.css( {
|
|
|
|
marginTop: $masthead.height()
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
$masthead.removeClass( 'masthead-fixed' );
|
|
|
|
$maindiv.css( {
|
|
|
|
marginTop: 0
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2013-08-20 19:53:09 +02:00
|
|
|
// Arranges footer widgets vertically.
|
|
|
|
if ( $.isFunction( $.fn.masonry ) ) {
|
|
|
|
|
|
|
|
$( '#footer-sidebar' ).masonry( {
|
|
|
|
itemSelector: '.widget',
|
2013-10-11 05:17:11 +02:00
|
|
|
columnWidth: 315,
|
|
|
|
gutterWidth: 0,
|
2013-08-20 19:53:09 +02:00
|
|
|
isRTL: $( 'body' ).is( '.rtl' )
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2013-07-29 00:55:10 +02:00
|
|
|
} );
|
|
|
|
|
2013-10-10 17:33:10 +02:00
|
|
|
/* Focus styles for primary menu. */
|
|
|
|
$( '.primary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
|
|
|
|
$( this ).parents().toggleClass( 'focus' );
|
|
|
|
});
|
2013-07-29 00:55:10 +02:00
|
|
|
} )( jQuery );
|