4 * Contains handlers for navigation, accessibility, header sizing
5 * footer widgets and Featured Content slider
9 var body = $( 'body' ),
10 _window = $( window ),
13 nav = $( '#primary-navigation' );
14 button = nav.find( '.menu-toggle' );
15 menu = nav.find( '.nav-menu' );
17 // Enable menu toggle for small screens.
19 if ( ! nav || ! button ) {
23 // Hide button if menu is missing or empty.
24 if ( ! menu || ! menu.children().length ) {
29 button.on( 'click.twentyfourteen', function() {
30 nav.toggleClass( 'toggled-on' );
31 if ( nav.hasClass( 'toggled-on' ) ) {
32 $( this ).attr( 'aria-expanded', 'true' );
33 menu.attr( 'aria-expanded', 'true' );
35 $( this ).attr( 'aria-expanded', 'false' );
36 menu.attr( 'aria-expanded', 'false' );
42 * Makes "skip to content" link work correctly in IE9 and Chrome for better
45 * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
47 _window.on( 'hashchange.twentyfourteen', function() {
48 var hash = location.hash.substring( 1 ), element;
54 element = document.getElementById( hash );
57 if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
58 element.tabIndex = -1;
63 // Repositions the window on jump-to-anchor to account for header height.
64 window.scrollBy( 0, -80 );
70 $( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
72 wrapper = $( '#search-container' ),
73 container = that.find( 'a' );
75 that.toggleClass( 'active' );
76 wrapper.toggleClass( 'hide' );
78 if ( that.hasClass( 'active' ) ) {
79 container.attr( 'aria-expanded', 'true' );
81 container.attr( 'aria-expanded', 'false' );
84 if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
85 wrapper.find( '.search-field' ).focus();
90 * Fixed header for large screen.
91 * If the header becomes more than 48px tall, unfix the header.
93 * The callback on the scroll event is only added if there is a header
94 * image and we are not on mobile.
96 if ( _window.width() > 781 ) {
97 var mastheadHeight = $( '#masthead' ).height(),
98 toolbarOffset, mastheadOffset;
100 if ( mastheadHeight > 48 ) {
101 body.removeClass( 'masthead-fixed' );
104 if ( body.is( '.header-image' ) ) {
105 toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
106 mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
108 _window.on( 'scroll.twentyfourteen', function() {
109 if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
110 body.addClass( 'masthead-fixed' );
112 body.removeClass( 'masthead-fixed' );
118 // Focus styles for menus.
119 $( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
120 $( this ).parents().toggleClass( 'focus' );
125 * @summary Add or remove ARIA attributes.
126 * Uses jQuery's width() function to determine the size of the window and add
127 * the default ARIA attributes for the menu toggle if it's visible.
128 * @since Twenty Fourteen 1.4
130 function onResizeARIA() {
131 if ( 781 > _window.width() ) {
132 button.attr( 'aria-expanded', 'false' );
133 menu.attr( 'aria-expanded', 'false' );
134 button.attr( 'aria-controls', 'primary-menu' );
136 button.removeAttr( 'aria-expanded' );
137 menu.removeAttr( 'aria-expanded' );
138 button.removeAttr( 'aria-controls' );
143 .on( 'load.twentyfourteen', onResizeARIA )
144 .on( 'resize.twentyfourteen', function() {
148 _window.load( function() {
149 // Arrange footer widgets vertically.
150 if ( $.isFunction( $.fn.masonry ) ) {
151 $( '#footer-sidebar' ).masonry( {
152 itemSelector: '.widget',
153 columnWidth: function( containerWidth ) {
154 return containerWidth / 4;
158 isRTL: $( 'body' ).is( '.rtl' )
162 // Initialize Featured Content slider.
163 if ( body.is( '.slider' ) ) {
164 $( '.featured-content' ).featuredslider( {
165 selector: '.featured-content-inner > article',
166 controlsContainer: '.featured-content'