4 * Contains handlers for navigation, accessibility, header sizing
5 * footer widgets and Featured Content slider
9 var body = $( 'body' ),
10 _window = $( window );
12 // Enable menu toggle for small screens.
14 var nav = $( '#primary-navigation' ), button, menu;
19 button = nav.find( '.menu-toggle' );
24 // Hide button if menu is missing or empty.
25 menu = nav.find( '.nav-menu' );
26 if ( ! menu || ! menu.children().length ) {
31 $( '.menu-toggle' ).on( 'click.twentyfourteen', function() {
32 nav.toggleClass( 'toggled-on' );
37 * Makes "skip to content" link work correctly in IE9 and Chrome for better
40 * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
42 _window.on( 'hashchange.twentyfourteen', function() {
43 var element = document.getElementById( location.hash.substring( 1 ) );
46 if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
47 element.tabIndex = -1;
52 // Repositions the window on jump-to-anchor to account for header height.
53 window.scrollBy( 0, -80 );
59 $( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
61 wrapper = $( '.search-box-wrapper' );
63 that.toggleClass( 'active' );
64 wrapper.toggleClass( 'hide' );
66 if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
67 wrapper.find( '.search-field' ).focus();
72 * Fixed header for large screen.
73 * If the header becomes more than 48px tall, unfix the header.
75 * The callback on the scroll event is only added if there is a header
76 * image and we are not on mobile.
78 if ( _window.width() > 781 ) {
79 var mastheadHeight = $( '#masthead' ).height(),
80 toolbarOffset, mastheadOffset;
82 if ( mastheadHeight > 48 ) {
83 body.removeClass( 'masthead-fixed' );
86 if ( body.is( '.header-image' ) ) {
87 toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
88 mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
90 _window.on( 'scroll.twentyfourteen', function() {
91 if ( ( window.scrollY > mastheadOffset ) && ( mastheadHeight < 49 ) ) {
92 body.addClass( 'masthead-fixed' );
94 body.removeClass( 'masthead-fixed' );
100 // Focus styles for menus.
101 $( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
102 $( this ).parents().toggleClass( 'focus' );
106 // Arrange footer widgets vertically.
107 if ( $.isFunction( $.fn.masonry ) ) {
108 $( '#footer-sidebar' ).masonry( {
109 itemSelector: '.widget',
110 columnWidth: function( containerWidth ) {
111 return containerWidth / 4;
115 isRTL: $( 'body' ).is( '.rtl' )
119 // Initialize Featured Content slider.
120 _window.load( function() {
121 if ( body.is( '.slider' ) ) {
122 $( '.featured-content' ).featuredslider( {
123 selector: '.featured-content-inner > article',
124 controlsContainer: '.featured-content'