2012-08-20 20:35:33 +02:00
|
|
|
/**
|
2014-03-19 06:29:16 +01:00
|
|
|
* Handles toggling the navigation menu for small screens and
|
|
|
|
* accessibility for submenu items.
|
2012-08-20 20:35:33 +02:00
|
|
|
*/
|
2012-08-24 23:07:19 +02:00
|
|
|
( function() {
|
2012-11-14 21:21:01 +01:00
|
|
|
var nav = document.getElementById( 'site-navigation' ), button, menu;
|
2014-03-19 06:29:16 +01:00
|
|
|
if ( ! nav ) {
|
2012-11-14 21:21:01 +01:00
|
|
|
return;
|
2014-03-19 06:29:16 +01:00
|
|
|
}
|
|
|
|
|
2014-07-11 19:47:14 +02:00
|
|
|
button = nav.getElementsByTagName( 'button' )[0];
|
2012-11-14 21:21:01 +01:00
|
|
|
menu = nav.getElementsByTagName( 'ul' )[0];
|
2014-03-19 06:29:16 +01:00
|
|
|
if ( ! button ) {
|
2012-11-14 21:21:01 +01:00
|
|
|
return;
|
2014-03-19 06:29:16 +01:00
|
|
|
}
|
2012-08-20 20:35:33 +02:00
|
|
|
|
2012-09-20 18:28:27 +02:00
|
|
|
// Hide button if menu is missing or empty.
|
2012-11-14 21:21:01 +01:00
|
|
|
if ( ! menu || ! menu.childNodes.length ) {
|
2012-09-20 18:28:27 +02:00
|
|
|
button.style.display = 'none';
|
2012-11-14 21:21:01 +01:00
|
|
|
return;
|
2012-09-20 18:28:27 +02:00
|
|
|
}
|
|
|
|
|
2012-08-25 18:50:05 +02:00
|
|
|
button.onclick = function() {
|
2014-03-19 06:29:16 +01:00
|
|
|
if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
|
2012-08-25 18:50:05 +02:00
|
|
|
menu.className = 'nav-menu';
|
2014-03-19 06:29:16 +01:00
|
|
|
}
|
2012-08-24 23:07:19 +02:00
|
|
|
|
2014-03-19 06:29:16 +01:00
|
|
|
if ( -1 !== button.className.indexOf( 'toggled-on' ) ) {
|
2012-08-25 18:50:05 +02:00
|
|
|
button.className = button.className.replace( ' toggled-on', '' );
|
|
|
|
menu.className = menu.className.replace( ' toggled-on', '' );
|
|
|
|
} else {
|
|
|
|
button.className += ' toggled-on';
|
|
|
|
menu.className += ' toggled-on';
|
|
|
|
}
|
|
|
|
};
|
2014-03-19 06:29:16 +01:00
|
|
|
} )();
|
|
|
|
|
|
|
|
// Better focus for hidden submenu items for accessibility.
|
|
|
|
( function( $ ) {
|
|
|
|
$( '.main-navigation' ).find( 'a' ).on( 'focus.twentytwelve blur.twentytwelve', function() {
|
|
|
|
$( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' );
|
|
|
|
} );
|
2014-06-08 21:00:14 +02:00
|
|
|
|
|
|
|
if ( 'ontouchstart' in window ) {
|
2014-12-05 23:59:23 +01:00
|
|
|
$('body').on( 'touchstart.twentytwelve', '.menu-item-has-children > a, .page_item_has_children > a', function( e ) {
|
2014-06-08 21:00:14 +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:16 +01:00
|
|
|
} )( jQuery );
|