2013-11-22 17:42:09 -05:00
|
|
|
/**
|
2020-01-28 19:45:18 -05:00
|
|
|
* Theme functions file.
|
2013-11-22 17:42:09 -05:00
|
|
|
*
|
|
|
|
* 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' ),
|
2015-03-15 16:00:27 -04:00
|
|
|
_window = $( window ),
|
|
|
|
nav, button, menu;
|
|
|
|
|
|
|
|
nav = $( '#primary-navigation' );
|
|
|
|
button = nav.find( '.menu-toggle' );
|
|
|
|
menu = nav.find( '.nav-menu' );
|
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() {
|
2016-03-15 17:33:28 -04:00
|
|
|
if ( ! nav.length || ! button.length ) {
|
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.
|
2016-03-15 17:33:28 -04:00
|
|
|
if ( ! menu.length || ! menu.children().length ) {
|
2013-10-24 18:58:48 -04:00
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-15 16:00:27 -04:00
|
|
|
button.on( 'click.twentyfourteen', function() {
|
2013-10-24 18:58:48 -04:00
|
|
|
nav.toggleClass( 'toggled-on' );
|
2015-03-15 16:00:27 -04: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-24 18:58:48 -04:00
|
|
|
} );
|
|
|
|
} )();
|
|
|
|
|
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() {
|
2014-05-28 09:36:16 -04:00
|
|
|
var hash = location.hash.substring( 1 ), element;
|
|
|
|
|
|
|
|
if ( ! hash ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element = document.getElementById( hash );
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
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 ),
|
2015-03-16 14:51:29 -04:00
|
|
|
wrapper = $( '#search-container' ),
|
|
|
|
container = that.find( 'a' );
|
2013-10-24 18:58:48 -04:00
|
|
|
|
|
|
|
that.toggleClass( 'active' );
|
|
|
|
wrapper.toggleClass( 'hide' );
|
|
|
|
|
2015-03-16 14:51:29 -04:00
|
|
|
if ( that.hasClass( 'active' ) ) {
|
|
|
|
container.attr( 'aria-expanded', 'true' );
|
|
|
|
} else {
|
|
|
|
container.attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
|
|
|
|
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(),
|
2016-11-14 12:17:31 -05:00
|
|
|
toolbarOffset, mastheadOffset;
|
2013-11-09 10:32:09 -05:00
|
|
|
|
|
|
|
if ( mastheadHeight > 48 ) {
|
|
|
|
body.removeClass( 'masthead-fixed' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( body.is( '.header-image' ) ) {
|
2016-11-14 12:17:31 -05:00
|
|
|
toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
|
|
|
|
mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;
|
2016-10-27 17:51:31 -04:00
|
|
|
|
2013-11-09 10:32:09 -05:00
|
|
|
_window.on( 'scroll.twentyfourteen', function() {
|
2014-06-16 14:22:14 -04:00
|
|
|
if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
|
2013-11-09 10:32:09 -05:00
|
|
|
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' );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-03-18 14:31:26 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Add or remove ARIA attributes.
|
|
|
|
*
|
2015-03-18 14:31:26 -04: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-28 19:45:18 -05:00
|
|
|
*
|
2015-03-18 14:31:26 -04:00
|
|
|
* @since Twenty Fourteen 1.4
|
|
|
|
*/
|
2015-03-15 16:00:27 -04: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 07:32:03 -05:00
|
|
|
_window.on( 'load', function() {
|
2016-03-21 17:59:29 -04:00
|
|
|
var footerSidebar,
|
|
|
|
isCustomizeSelectiveRefresh = ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh );
|
|
|
|
|
2014-03-19 19:08:14 -04:00
|
|
|
// Arrange footer widgets vertically.
|
2021-01-22 07:32:03 -05:00
|
|
|
if ( typeof $.fn.masonry === 'function' ) {
|
2016-03-21 17:59:29 -04:00
|
|
|
footerSidebar = $( '#footer-sidebar' );
|
|
|
|
footerSidebar.masonry( {
|
2014-03-19 19:08:14 -04:00
|
|
|
itemSelector: '.widget',
|
|
|
|
columnWidth: function( containerWidth ) {
|
|
|
|
return containerWidth / 4;
|
|
|
|
},
|
|
|
|
gutterWidth: 0,
|
|
|
|
isResizable: true,
|
|
|
|
isRTL: $( 'body' ).is( '.rtl' )
|
|
|
|
} );
|
2016-03-21 17:59:29 -04: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-19 19:08:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 );
|