2014-10-14 21:48:19 +02:00
|
|
|
/* global screenReaderText */
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
/**
|
2014-11-04 21:26:23 +01:00
|
|
|
* Theme functions file.
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
*
|
|
|
|
* Contains handlers for navigation and widget area.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function( $ ) {
|
2019-09-25 23:38:58 +02:00
|
|
|
var $body, $window, $sidebar, resizeTimer,
|
|
|
|
secondary, button;
|
2015-06-17 00:18:24 +02:00
|
|
|
|
2015-07-29 20:13:24 +02:00
|
|
|
function initMainNavigation( container ) {
|
2015-06-17 00:18:24 +02:00
|
|
|
// Add dropdown toggle that display child menu items.
|
2015-07-29 20:13:24 +02:00
|
|
|
container.find( '.menu-item-has-children > a' ).after( '<button class="dropdown-toggle" aria-expanded="false">' + screenReaderText.expand + '</button>' );
|
2015-06-17 00:18:24 +02:00
|
|
|
|
|
|
|
// Toggle buttons and submenu items with active children menu items.
|
2015-07-29 20:13:24 +02:00
|
|
|
container.find( '.current-menu-ancestor > button' ).addClass( 'toggle-on' );
|
|
|
|
container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' );
|
2015-06-17 00:18:24 +02:00
|
|
|
|
2021-01-22 13:32:03 +01:00
|
|
|
container.find( '.dropdown-toggle' ).on( 'click', function( e ) {
|
2015-06-17 00:18:24 +02:00
|
|
|
var _this = $( this );
|
|
|
|
e.preventDefault();
|
|
|
|
_this.toggleClass( 'toggle-on' );
|
|
|
|
_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
|
|
|
|
_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
|
|
|
|
_this.html( _this.html() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
|
|
|
|
} );
|
|
|
|
}
|
2015-07-29 20:13:24 +02:00
|
|
|
initMainNavigation( $( '.main-navigation' ) );
|
|
|
|
|
|
|
|
// Re-initialize the main navigation when it is updated, persisting any existing submenu expanded states.
|
|
|
|
$( document ).on( 'customize-preview-menu-refreshed', function( e, params ) {
|
|
|
|
if ( 'primary' === params.wpNavMenuArgs.theme_location ) {
|
|
|
|
initMainNavigation( params.newContainer );
|
|
|
|
|
|
|
|
// Re-sync expanded states from oldContainer.
|
|
|
|
params.oldContainer.find( '.dropdown-toggle.toggle-on' ).each(function() {
|
|
|
|
var containerId = $( this ).parent().prop( 'id' );
|
|
|
|
$( params.newContainer ).find( '#' + containerId + ' > .dropdown-toggle' ).triggerHandler( 'click' );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
|
2015-03-06 18:34:26 +01:00
|
|
|
secondary = $( '#secondary' );
|
|
|
|
button = $( '.site-branding' ).find( '.secondary-toggle' );
|
|
|
|
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
// Enable menu toggle for small screens.
|
|
|
|
( function() {
|
2015-03-06 18:34:26 +01:00
|
|
|
var menu, widgets, social;
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! secondary.length || ! button.length ) {
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-19 19:23:21 +01:00
|
|
|
// Hide button if there are no widgets and the menus are missing or empty.
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
menu = secondary.find( '.nav-menu' );
|
|
|
|
widgets = secondary.find( '#widget-area' );
|
|
|
|
social = secondary.find( '#social-navigation' );
|
2016-03-15 22:33:28 +01:00
|
|
|
if ( ! widgets.length && ! social.length && ( ! menu.length || ! menu.children().length ) ) {
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
button.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
button.on( 'click.twentyfifteen', function() {
|
|
|
|
secondary.toggleClass( 'toggled-on' );
|
|
|
|
secondary.trigger( 'resize' );
|
|
|
|
$( this ).toggleClass( 'toggled-on' );
|
2015-03-06 18:34:26 +01:00
|
|
|
if ( $( this, secondary ).hasClass( 'toggled-on' ) ) {
|
|
|
|
$( this ).attr( 'aria-expanded', 'true' );
|
|
|
|
secondary.attr( 'aria-expanded', 'true' );
|
|
|
|
} else {
|
|
|
|
$( this ).attr( 'aria-expanded', 'false' );
|
|
|
|
secondary.attr( 'aria-expanded', 'false' );
|
|
|
|
}
|
Importing Twenty Fifteen, first pass at our new default theme for 2015, set for 4.1.
It's good for posts, it's good for pages, it might be good for you. Development will occur in trunk. Have at it.
Props matt, iandstewart, iamtakashi, obenland, cainm, kristastevens, karmatosed, chellycat, lancewillett, kwight, davidakennedy. See #29799
Built from https://develop.svn.wordpress.org/trunk@29892
git-svn-id: http://core.svn.wordpress.org/trunk@29648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-14 21:28:18 +02:00
|
|
|
} );
|
|
|
|
} )();
|
2014-10-26 16:04:21 +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.
|
2020-01-29 01:45:18 +01:00
|
|
|
*
|
2015-03-18 19:31:26 +01:00
|
|
|
* @since Twenty Fifteen 1.1
|
|
|
|
*/
|
2015-03-06 18:34:26 +01:00
|
|
|
function onResizeARIA() {
|
|
|
|
if ( 955 > $window.width() ) {
|
|
|
|
button.attr( 'aria-expanded', 'false' );
|
|
|
|
secondary.attr( 'aria-expanded', 'false' );
|
|
|
|
button.attr( 'aria-controls', 'secondary' );
|
|
|
|
} else {
|
|
|
|
button.removeAttr( 'aria-expanded' );
|
|
|
|
secondary.removeAttr( 'aria-expanded' );
|
|
|
|
button.removeAttr( 'aria-controls' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 19:23:21 +01:00
|
|
|
// Sidebar scrolling.
|
|
|
|
function resizeAndScroll() {
|
2019-09-25 23:38:58 +02:00
|
|
|
var windowPos = $window.scrollTop(),
|
|
|
|
windowHeight = $window.height(),
|
|
|
|
sidebarHeight = $sidebar.height(),
|
|
|
|
bodyHeight = $body.height();
|
|
|
|
|
2019-09-26 00:12:57 +02:00
|
|
|
if( 955 < $window.width() && bodyHeight > sidebarHeight && ( windowPos + windowHeight ) >= sidebarHeight ) {
|
2019-09-25 23:38:58 +02:00
|
|
|
$sidebar.css({
|
2019-09-26 00:12:57 +02:00
|
|
|
position: 'fixed',
|
2019-09-25 23:38:58 +02:00
|
|
|
bottom: sidebarHeight > windowHeight ? 0 : 'auto'
|
|
|
|
});
|
|
|
|
} else {
|
2019-09-26 00:12:57 +02:00
|
|
|
$sidebar.css('position', 'relative');
|
2019-09-25 23:38:58 +02:00
|
|
|
}
|
2014-11-19 19:23:21 +01:00
|
|
|
}
|
2014-11-13 04:09:22 +01:00
|
|
|
|
External Libraries: Further fix jQuery deprecations in WordPress core.
Follow-up to [50001], [50270], [50367], [50383], [50410], [50420], [50429], [50547].
Props chaion07, Clorith, costdev, desrosj, malthert, peterwilsoncc, presskopp, promz, sabernhardt, SergeyBiryukov, toro_unit, wpnomad.
Fixes #51519.
Built from https://develop.svn.wordpress.org/trunk@52285
git-svn-id: http://core.svn.wordpress.org/trunk@51877 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-30 18:18:01 +01:00
|
|
|
$( function() {
|
2014-12-11 00:02:23 +01:00
|
|
|
$body = $( document.body );
|
2014-11-19 19:23:21 +01:00
|
|
|
$window = $( window );
|
2014-12-11 00:02:23 +01:00
|
|
|
$sidebar = $( '#sidebar' ).first();
|
2014-11-13 04:09:22 +01:00
|
|
|
|
|
|
|
$window
|
2019-09-25 23:38:58 +02:00
|
|
|
.on( 'scroll.twentyfifteen', resizeAndScroll )
|
2015-03-06 18:34:26 +01:00
|
|
|
.on( 'load.twentyfifteen', onResizeARIA )
|
2014-11-19 19:23:21 +01:00
|
|
|
.on( 'resize.twentyfifteen', function() {
|
|
|
|
clearTimeout( resizeTimer );
|
|
|
|
resizeTimer = setTimeout( resizeAndScroll, 500 );
|
2015-03-06 18:34:26 +01:00
|
|
|
onResizeARIA();
|
2014-11-19 19:23:21 +01:00
|
|
|
} );
|
2015-03-06 18:34:26 +01:00
|
|
|
$sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll );
|
2014-11-19 19:23:21 +01:00
|
|
|
|
2019-09-25 23:38:58 +02:00
|
|
|
for ( var i = 0; i < 6; i++ ) {
|
2014-11-19 19:23:21 +01:00
|
|
|
setTimeout( resizeAndScroll, 100 * i );
|
|
|
|
}
|
2014-11-13 04:09:22 +01:00
|
|
|
} );
|
2014-10-26 16:04:21 +01:00
|
|
|
|
2014-11-25 07:12:22 +01:00
|
|
|
} )( jQuery );
|