2013-11-22 23:42:09 +01:00
|
|
|
/**
|
|
|
|
* Theme functions file
|
|
|
|
*
|
|
|
|
* Contains handlers for navigation, accessibility, header sizing
|
|
|
|
* footer widgets and Featured Content slider
|
|
|
|
*
|
|
|
|
*/
|
2013-10-25 00:58:48 +02:00
|
|
|
( function( $ ) {
|
|
|
|
var body = $( 'body' ),
|
2013-11-19 04:49:09 +01:00
|
|
|
_window = $( window );
|
2013-10-25 00:58:48 +02:00
|
|
|
|
2013-10-30 15:39:10 +01:00
|
|
|
// Enable menu toggle for small screens.
|
2013-10-25 00:58:48 +02:00
|
|
|
( function() {
|
|
|
|
var nav = $( '#primary-navigation' ), button, menu;
|
2013-10-30 19:53:10 +01:00
|
|
|
if ( ! nav ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
return;
|
2013-10-30 19:53:10 +01:00
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
|
|
|
|
button = nav.find( '.menu-toggle' );
|
2013-10-30 19:53:10 +01:00
|
|
|
if ( ! button ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
return;
|
2013-10-30 19:53:10 +01:00
|
|
|
}
|
2013-10-25 00:58:48 +02: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 15:39:10 +01:00
|
|
|
/*
|
2013-10-25 00:58:48 +02: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() {
|
2014-05-28 15:36:16 +02:00
|
|
|
var hash = location.hash.substring( 1 ), element;
|
|
|
|
|
|
|
|
if ( ! hash ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = document.getElementById( hash );
|
2013-10-25 00:58:48 +02:00
|
|
|
|
|
|
|
if ( element ) {
|
2013-10-30 19:53:10 +01:00
|
|
|
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
element.tabIndex = -1;
|
2013-10-30 19:53:10 +01:00
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
|
|
|
|
element.focus();
|
2013-12-03 19:35:10 +01:00
|
|
|
|
|
|
|
// Repositions the window on jump-to-anchor to account for header height.
|
|
|
|
window.scrollBy( 0, -80 );
|
2013-10-30 19:53:10 +01:00
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
} );
|
|
|
|
|
|
|
|
$( function() {
|
2013-10-30 15:39:10 +01:00
|
|
|
// Search toggle.
|
2013-12-05 22:28:11 +01:00
|
|
|
$( '.search-toggle' ).on( 'click.twentyfourteen', function( event ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
var that = $( this ),
|
2013-11-19 04:49:09 +01:00
|
|
|
wrapper = $( '.search-box-wrapper' );
|
2013-10-25 00:58:48 +02:00
|
|
|
|
|
|
|
that.toggleClass( 'active' );
|
|
|
|
wrapper.toggleClass( 'hide' );
|
|
|
|
|
2013-12-09 21:38:12 +01:00
|
|
|
if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
wrapper.find( '.search-field' ).focus();
|
2013-10-30 19:53:10 +01:00
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
} );
|
|
|
|
|
2013-10-30 15:39:10 +01:00
|
|
|
/*
|
2013-11-09 16:32:09 +01:00
|
|
|
* Fixed header for large screen.
|
|
|
|
* If the header becomes more than 48px tall, unfix the header.
|
2013-10-25 00:58:48 +02:00
|
|
|
*
|
|
|
|
* The callback on the scroll event is only added if there is a header
|
|
|
|
* image and we are not on mobile.
|
|
|
|
*/
|
2013-11-19 04:49:09 +01:00
|
|
|
if ( _window.width() > 781 ) {
|
2013-11-11 18:27:11 +01:00
|
|
|
var mastheadHeight = $( '#masthead' ).height(),
|
|
|
|
toolbarOffset, mastheadOffset;
|
2013-11-09 16:32:09 +01:00
|
|
|
|
|
|
|
if ( mastheadHeight > 48 ) {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( body.is( '.header-image' ) ) {
|
2013-11-11 18:27:11 +01:00
|
|
|
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
|
|
|
|
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
2013-11-09 16:32:09 +01:00
|
|
|
|
|
|
|
_window.on( 'scroll.twentyfourteen', function() {
|
2014-06-16 20:22:14 +02:00
|
|
|
if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
|
2013-11-09 16:32:09 +01:00
|
|
|
body.addClass( 'masthead-fixed' );
|
|
|
|
} else {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
}
|
|
|
|
|
2013-11-02 05:36:12 +01:00
|
|
|
// Focus styles for menus.
|
|
|
|
$( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
|
2013-10-25 00:58:48 +02:00
|
|
|
$( this ).parents().toggleClass( 'focus' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2013-10-30 15:39:10 +01:00
|
|
|
_window.load( function() {
|
2014-03-20 00:08:14 +01: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 15:39:10 +01:00
|
|
|
if ( body.is( '.slider' ) ) {
|
|
|
|
$( '.featured-content' ).featuredslider( {
|
2013-11-15 22:20:09 +01:00
|
|
|
selector: '.featured-content-inner > article',
|
2013-10-30 15:39:10 +01:00
|
|
|
controlsContainer: '.featured-content'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} )( jQuery );
|