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