2013-11-22 23:42:09 +01:00
|
|
|
/**
|
2020-01-29 01:45:18 +01:00
|
|
|
* Theme functions file.
|
2013-11-22 23:42:09 +01:00
|
|
|
*
|
|
|
|
* 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' ),
|
2015-03-15 21:00:27 +01:00
|
|
|
_window = $( window ),
|
|
|
|
nav, button, menu;
|
|
|
|
|
|
|
|
nav = $( '#primary-navigation' );
|
|
|
|
button = nav.find( '.menu-toggle' );
|
|
|
|
menu = nav.find( '.nav-menu' );
|
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() {
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! nav.length || ! button.length ) {
|
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.
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! menu.length || ! menu.children().length ) {
|
2013-10-25 00:58:48 +02:00
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-15 21:00:27 +01:00
|
|
|
button.on( 'click.twentyfourteen', function() {
|
2013-10-25 00:58:48 +02:00
|
|
|
nav.toggleClass( 'toggled-on' );
|
2015-03-15 21:00:27 +01:00
|
|
|
if ( nav.hasClass( 'toggled-on' ) ) {
|
|
|
|
$( this ).attr( 'aria-expanded', 'true' );
|
|
|
|
menu.attr( 'aria-expanded', 'true' );
|
|
|
|
} else {
|
|
|
|
$( this ).attr( 'aria-expanded', 'false' );
|
|
|
|
menu.attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
2013-10-25 00:58:48 +02:00
|
|
|
} );
|
|
|
|
} )();
|
|
|
|
|
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 ),
|
2015-03-16 19:51:29 +01:00
|
|
|
wrapper = $( '#search-container' ),
|
|
|
|
container = that.find( 'a' );
|
2013-10-25 00:58:48 +02:00
|
|
|
|
|
|
|
that.toggleClass( 'active' );
|
|
|
|
wrapper.toggleClass( 'hide' );
|
|
|
|
|
2015-03-16 19:51:29 +01:00
|
|
|
if ( that.hasClass( 'active' ) ) {
|
|
|
|
container.attr( 'aria-expanded', 'true' );
|
|
|
|
} else {
|
|
|
|
container.attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
|
|
|
|
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(),
|
2016-11-14 18:17:31 +01:00
|
|
|
toolbarOffset, mastheadOffset;
|
2013-11-09 16:32:09 +01:00
|
|
|
|
|
|
|
if ( mastheadHeight > 48 ) {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( body.is( '.header-image' ) ) {
|
2016-11-14 18:17:31 +01:00
|
|
|
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
|
|
|
|
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
2016-10-27 23:51:31 +02:00
|
|
|
|
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' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-03-18 19:31:26 +01:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Add or remove ARIA attributes.
|
|
|
|
*
|
2015-03-18 19:31:26 +01:00
|
|
|
* Uses jQuery's width() function to determine the size of the window and add
|
|
|
|
* the default ARIA attributes for the menu toggle if it's visible.
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2015-03-18 19:31:26 +01:00
|
|
|
* @since Twenty Fourteen 1.4
|
|
|
|
*/
|
2015-03-15 21:00:27 +01:00
|
|
|
function onResizeARIA() {
|
|
|
|
if ( 781 > _window.width() ) {
|
|
|
|
button.attr( 'aria-expanded', 'false' );
|
|
|
|
menu.attr( 'aria-expanded', 'false' );
|
|
|
|
button.attr( 'aria-controls', 'primary-menu' );
|
|
|
|
} else {
|
|
|
|
button.removeAttr( 'aria-expanded' );
|
|
|
|
menu.removeAttr( 'aria-expanded' );
|
|
|
|
button.removeAttr( 'aria-controls' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_window
|
|
|
|
.on( 'load.twentyfourteen', onResizeARIA )
|
|
|
|
.on( 'resize.twentyfourteen', function() {
|
|
|
|
onResizeARIA();
|
|
|
|
} );
|
|
|
|
|
2021-01-22 13:32:03 +01:00
|
|
|
_window.on( 'load', function() {
|
2016-03-21 22:59:29 +01:00
|
|
|
var footerSidebar,
|
|
|
|
isCustomizeSelectiveRefresh = ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh );
|
|
|
|
|
2014-03-20 00:08:14 +01:00
|
|
|
// Arrange footer widgets vertically.
|
2021-01-22 13:32:03 +01:00
|
|
|
if ( typeof $.fn.masonry === 'function' ) {
|
2016-03-21 22:59:29 +01:00
|
|
|
footerSidebar = $( '#footer-sidebar' );
|
|
|
|
footerSidebar.masonry( {
|
2014-03-20 00:08:14 +01:00
|
|
|
itemSelector: '.widget',
|
|
|
|
columnWidth: function( containerWidth ) {
|
|
|
|
return containerWidth / 4;
|
|
|
|
},
|
|
|
|
gutterWidth: 0,
|
|
|
|
isResizable: true,
|
|
|
|
isRTL: $( 'body' ).is( '.rtl' )
|
|
|
|
} );
|
2016-03-21 22:59:29 +01:00
|
|
|
|
|
|
|
if ( isCustomizeSelectiveRefresh ) {
|
|
|
|
|
|
|
|
// Retain previous masonry-brick initial position.
|
|
|
|
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {
|
|
|
|
var copyPosition = (
|
|
|
|
placement.partial.extended( wp.customize.widgetsPreview.WidgetPartial ) &&
|
|
|
|
placement.removedNodes instanceof jQuery &&
|
|
|
|
placement.removedNodes.is( '.masonry-brick' ) &&
|
|
|
|
placement.container instanceof jQuery
|
|
|
|
);
|
|
|
|
if ( copyPosition ) {
|
|
|
|
placement.container.css( {
|
|
|
|
position: placement.removedNodes.css( 'position' ),
|
|
|
|
top: placement.removedNodes.css( 'top' ),
|
|
|
|
left: placement.removedNodes.css( 'left' )
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Re-arrange footer widgets after selective refresh event.
|
|
|
|
wp.customize.selectiveRefresh.bind( 'sidebar-updated', function( sidebarPartial ) {
|
|
|
|
if ( 'sidebar-3' === sidebarPartial.sidebarId ) {
|
|
|
|
footerSidebar.masonry( 'reloadItems' );
|
|
|
|
footerSidebar.masonry( 'layout' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize audio and video players in Twenty_Fourteen_Ephemera_Widget widget when selectively refreshed in Customizer.
|
|
|
|
if ( isCustomizeSelectiveRefresh && wp.mediaelement ) {
|
|
|
|
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
|
|
|
|
wp.mediaelement.initialize();
|
|
|
|
} );
|
2014-03-20 00:08:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 );
|