2013-11-22 17:42:09 -05:00
|
|
|
/**
|
|
|
|
* Theme functions file
|
|
|
|
*
|
|
|
|
* Contains handlers for navigation, accessibility, header sizing
|
|
|
|
* footer widgets and Featured Content slider
|
|
|
|
*
|
|
|
|
*/
|
2013-10-24 18:58:48 -04:00
|
|
|
( function( $ ) {
|
|
|
|
var body = $( 'body' ),
|
2013-11-18 22:49:09 -05:00
|
|
|
_window = $( window );
|
2013-10-24 18:58:48 -04:00
|
|
|
|
2013-10-30 10:39:10 -04:00
|
|
|
// Enable menu toggle for small screens.
|
2013-10-24 18:58:48 -04:00
|
|
|
( function() {
|
|
|
|
var nav = $( '#primary-navigation' ), button, menu;
|
2013-10-30 14:53:10 -04:00
|
|
|
if ( ! nav ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
return;
|
2013-10-30 14:53:10 -04:00
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
button = nav.find( '.menu-toggle' );
|
2013-10-30 14:53:10 -04:00
|
|
|
if ( ! button ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
return;
|
2013-10-30 14:53:10 -04:00
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
// Hide button if menu is missing or empty.
|
|
|
|
menu = nav.find( '.nav-menu' );
|
|
|
|
if ( ! menu || ! menu.children().length ) {
|
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$( '.menu-toggle' ).on( 'click.twentyfourteen', function() {
|
|
|
|
nav.toggleClass( 'toggled-on' );
|
|
|
|
} );
|
|
|
|
} )();
|
|
|
|
|
2013-10-30 10:39:10 -04:00
|
|
|
/*
|
2013-10-24 18:58:48 -04:00
|
|
|
* Makes "skip to content" link work correctly in IE9 and Chrome for better
|
|
|
|
* accessibility.
|
|
|
|
*
|
|
|
|
* @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
|
|
|
|
*/
|
|
|
|
_window.on( 'hashchange.twentyfourteen', function() {
|
|
|
|
var element = document.getElementById( location.hash.substring( 1 ) );
|
|
|
|
|
|
|
|
if ( element ) {
|
2013-10-30 14:53:10 -04:00
|
|
|
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
element.tabIndex = -1;
|
2013-10-30 14:53:10 -04:00
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
element.focus();
|
2013-12-03 13:35:10 -05:00
|
|
|
|
|
|
|
// Repositions the window on jump-to-anchor to account for header height.
|
|
|
|
window.scrollBy( 0, -80 );
|
2013-10-30 14:53:10 -04:00
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( function() {
|
2013-10-30 10:39:10 -04:00
|
|
|
// Search toggle.
|
2013-12-05 16:28:11 -05:00
|
|
|
$( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
var that = $( this ),
|
2013-11-18 22:49:09 -05:00
|
|
|
wrapper = $( '.search-box-wrapper' );
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
that.toggleClass( 'active' );
|
|
|
|
wrapper.toggleClass( 'hide' );
|
|
|
|
|
2013-12-09 15:38:12 -05:00
|
|
|
if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
wrapper.find( '.search-field' ).focus();
|
2013-10-30 14:53:10 -04:00
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
} );
|
|
|
|
|
2013-10-30 10:39:10 -04:00
|
|
|
/*
|
2013-11-09 10:32:09 -05:00
|
|
|
* Fixed header for large screen.
|
|
|
|
* If the header becomes more than 48px tall, unfix the header.
|
2013-10-24 18:58:48 -04:00
|
|
|
*
|
|
|
|
* The callback on the scroll event is only added if there is a header
|
|
|
|
* image and we are not on mobile.
|
|
|
|
*/
|
2013-11-18 22:49:09 -05:00
|
|
|
if ( _window.width() > 781 ) {
|
2013-11-11 12:27:11 -05:00
|
|
|
var mastheadHeight = $( '#masthead' ).height(),
|
|
|
|
toolbarOffset, mastheadOffset;
|
2013-11-09 10:32:09 -05:00
|
|
|
|
|
|
|
if ( mastheadHeight > 48 ) {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( body.is( '.header-image' ) ) {
|
2013-11-11 12:27:11 -05:00
|
|
|
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
|
|
|
|
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
2013-11-09 10:32:09 -05:00
|
|
|
|
|
|
|
_window.on( 'scroll.twentyfourteen', function() {
|
|
|
|
if ( ( window.scrollY > mastheadOffset ) && ( mastheadHeight < 49 ) ) {
|
|
|
|
body.addClass( 'masthead-fixed' );
|
|
|
|
} else {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2013-10-24 18:58:48 -04:00
|
|
|
}
|
|
|
|
|
2013-11-02 00:36:12 -04:00
|
|
|
// Focus styles for menus.
|
|
|
|
$( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
|
2013-10-24 18:58:48 -04:00
|
|
|
$( this ).parents().toggleClass( 'focus' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2013-10-30 10:39:10 -04:00
|
|
|
_window.load( function() {
|
2014-03-19 19:08:14 -04:00
|
|
|
// Arrange footer widgets vertically.
|
|
|
|
if ( $.isFunction( $.fn.masonry ) ) {
|
|
|
|
$( '#footer-sidebar' ).masonry( {
|
|
|
|
itemSelector: '.widget',
|
|
|
|
columnWidth: function( containerWidth ) {
|
|
|
|
return containerWidth / 4;
|
|
|
|
},
|
|
|
|
gutterWidth: 0,
|
|
|
|
isResizable: true,
|
|
|
|
isRTL: $( 'body' ).is( '.rtl' )
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize Featured Content slider.
|
2013-10-30 10:39:10 -04:00
|
|
|
if ( body.is( '.slider' ) ) {
|
|
|
|
$( '.featured-content' ).featuredslider( {
|
2013-11-15 16:20:09 -05:00
|
|
|
selector: '.featured-content-inner > article',
|
2013-10-30 10:39:10 -04:00
|
|
|
controlsContainer: '.featured-content'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} )( jQuery );
|