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 hash = location.hash.substring( 1 ), element;
49
element = document.getElementById( hash );
52
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
53
element.tabIndex = -1;
58
// Repositions the window on jump-to-anchor to account for header height.
59
window.scrollBy( 0, -80 );
65
$( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
67
wrapper = $( '.search-box-wrapper' );
69
that.toggleClass( 'active' );
70
wrapper.toggleClass( 'hide' );
72
if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
73
wrapper.find( '.search-field' ).focus();
78
* Fixed header for large screen.
79
* If the header becomes more than 48px tall, unfix the header.
81
* The callback on the scroll event is only added if there is a header
82
* image and we are not on mobile.
84
if ( _window.width() > 781 ) {
85
var mastheadHeight = $( '#masthead' ).height(),
86
toolbarOffset, mastheadOffset;
88
if ( mastheadHeight > 48 ) {
89
body.removeClass( 'masthead-fixed' );
92
if ( body.is( '.header-image' ) ) {
93
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
94
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
96
_window.on( 'scroll.twentyfourteen', function() {
97
if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
98
body.addClass( 'masthead-fixed' );
100
body.removeClass( 'masthead-fixed' );
106
// Focus styles for menus.
107
$( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
108
$( this ).parents().toggleClass( 'focus' );
112
_window.load( function() {
113
// Arrange footer widgets vertically.
114
if ( $.isFunction( $.fn.masonry ) ) {
115
$( '#footer-sidebar' ).masonry( {
116
itemSelector: '.widget',
117
columnWidth: function( containerWidth ) {
118
return containerWidth / 4;
122
isRTL: $( 'body' ).is( '.rtl' )
126
// Initialize Featured Content slider.
127
if ( body.is( '.slider' ) ) {
128
$( '.featured-content' ).featuredslider( {
129
selector: '.featured-content-inner > article',
130
controlsContainer: '.featured-content'