2013-02-19 00:08:56 +01:00
|
|
|
/**
|
|
|
|
* Functionality specific to Twenty Thirteen.
|
|
|
|
*
|
|
|
|
* Provides helper functions to enhance the theme experience.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function( $ ) {
|
2013-06-25 23:09:00 +02:00
|
|
|
var body = $( 'body' ),
|
2015-03-15 21:01:26 +01:00
|
|
|
_window = $( window ),
|
|
|
|
nav, button, menu;
|
|
|
|
|
|
|
|
nav = $( '#site-navigation' );
|
|
|
|
button = nav.find( '.menu-toggle' );
|
|
|
|
menu = nav.find( '.nav-menu' );
|
2013-04-11 18:11:46 +02:00
|
|
|
|
2013-04-16 23:51:07 +02:00
|
|
|
/**
|
2013-06-25 23:09:00 +02:00
|
|
|
* Adds a top margin to the footer if the sidebar widget area is higher
|
|
|
|
* than the rest of the page, to help the footer always visually clear
|
|
|
|
* the sidebar.
|
2013-04-16 23:51:07 +02:00
|
|
|
*/
|
2013-04-03 19:29:59 +02:00
|
|
|
$( function() {
|
2013-06-25 23:09:00 +02:00
|
|
|
if ( body.is( '.sidebar' ) ) {
|
|
|
|
var sidebar = $( '#secondary .widget-area' ),
|
2014-03-19 06:29:29 +01:00
|
|
|
secondary = ( 0 === sidebar.length ) ? -40 : sidebar.height(),
|
2013-06-25 23:09:00 +02:00
|
|
|
margin = $( '#tertiary .widget-area' ).height() - $( '#content' ).height() - secondary;
|
|
|
|
|
2014-03-19 06:29:29 +01:00
|
|
|
if ( margin > 0 && _window.innerWidth() > 999 ) {
|
2013-06-25 23:09:00 +02:00
|
|
|
$( '#colophon' ).css( 'margin-top', margin + 'px' );
|
2014-03-19 06:29:29 +01:00
|
|
|
}
|
2013-06-25 23:09:00 +02:00
|
|
|
}
|
2013-03-12 22:42:53 +01:00
|
|
|
} );
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables menu toggle for small screens.
|
|
|
|
*/
|
|
|
|
( function() {
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! nav.length || ! button.length ) {
|
2013-02-19 00:08:56 +01:00
|
|
|
return;
|
2014-03-19 06:29:29 +01:00
|
|
|
}
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
// Hide button if menu is missing or empty.
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! menu.length || ! menu.children().length ) {
|
2013-02-19 00:08:56 +01:00
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-19 06:29:29 +01:00
|
|
|
button.on( 'click.twentythirteen', function() {
|
2013-02-19 00:08:56 +01:00
|
|
|
nav.toggleClass( 'toggled-on' );
|
2015-03-15 21:01:26 +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-02-19 00:08:56 +01:00
|
|
|
} );
|
2014-03-19 06:29:29 +01:00
|
|
|
|
2014-06-08 20:48:16 +02:00
|
|
|
// Fix sub-menus for touch devices.
|
|
|
|
if ( 'ontouchstart' in window ) {
|
2015-03-30 21:20:27 +02:00
|
|
|
menu.find( '.menu-item-has-children > a, .page_item_has_children > a' ).on( 'touchstart.twentythirteen', function( e ) {
|
2014-06-08 20:48:16 +02:00
|
|
|
var el = $( this ).parent( 'li' );
|
|
|
|
|
|
|
|
if ( ! el.hasClass( 'focus' ) ) {
|
|
|
|
e.preventDefault();
|
|
|
|
el.toggleClass( 'focus' );
|
|
|
|
el.siblings( '.focus' ).removeClass( 'focus' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-03-19 06:29:29 +01:00
|
|
|
// Better focus for hidden submenu items for accessibility.
|
|
|
|
menu.find( 'a' ).on( 'focus.twentythirteen blur.twentythirteen', function() {
|
|
|
|
$( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' );
|
|
|
|
} );
|
2013-02-19 00:08:56 +01:00
|
|
|
} )();
|
|
|
|
|
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.
|
2017-12-18 15:14:53 +01:00
|
|
|
*
|
2015-03-18 19:31:26 +01:00
|
|
|
* @since Twenty Thirteen 1.5
|
|
|
|
*/
|
2015-03-15 21:01:26 +01:00
|
|
|
function onResizeARIA() {
|
|
|
|
if ( 643 > _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.twentythirteen', onResizeARIA )
|
|
|
|
.on( 'resize.twentythirteen', function() {
|
|
|
|
onResizeARIA();
|
|
|
|
} );
|
|
|
|
|
2013-02-19 00:08:56 +01: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/
|
|
|
|
*/
|
2013-04-16 23:51:07 +02:00
|
|
|
_window.on( 'hashchange.twentythirteen', function() {
|
2013-04-23 18:30:03 +02:00
|
|
|
var element = document.getElementById( location.hash.substring( 1 ) );
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
if ( element ) {
|
2014-03-19 06:29:29 +01:00
|
|
|
if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) {
|
2013-04-23 18:30:03 +02:00
|
|
|
element.tabIndex = -1;
|
2014-03-19 06:29:29 +01:00
|
|
|
}
|
2013-02-19 00:08:56 +01:00
|
|
|
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Arranges footer widgets vertically.
|
|
|
|
*/
|
2016-07-17 23:14:29 +02:00
|
|
|
$( function() {
|
|
|
|
var columnWidth, widgetArea;
|
|
|
|
if ( ! $.isFunction( $.fn.masonry ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
columnWidth = body.is( '.sidebar' ) ? 228 : 245;
|
|
|
|
widgetArea = $( '#secondary .widget-area' );
|
2013-02-19 00:08:56 +01:00
|
|
|
|
2016-03-21 22:59:29 +01:00
|
|
|
widgetArea.masonry( {
|
2013-02-19 00:08:56 +01:00
|
|
|
itemSelector: '.widget',
|
2013-03-07 18:57:16 +01:00
|
|
|
columnWidth: columnWidth,
|
|
|
|
gutterWidth: 20,
|
2013-03-07 19:22:58 +01:00
|
|
|
isRTL: body.is( '.rtl' )
|
2013-02-19 00:08:56 +01:00
|
|
|
} );
|
2016-03-21 22:59:29 +01:00
|
|
|
|
|
|
|
if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) {
|
|
|
|
|
|
|
|
// 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 when sidebar is updated via selective refresh in the Customizer.
|
|
|
|
wp.customize.selectiveRefresh.bind( 'sidebar-updated', function( sidebarPartial ) {
|
|
|
|
if ( 'sidebar-1' === sidebarPartial.sidebarId ) {
|
|
|
|
widgetArea.masonry( 'reloadItems' );
|
|
|
|
widgetArea.masonry( 'layout' );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2016-07-17 23:14:29 +02:00
|
|
|
} );
|
2013-02-19 00:08:56 +01:00
|
|
|
} )( jQuery );
|