Skip to content

Commit 4abc12a

Browse files
committed
Fix: Twenty Fourteen dropdown menu accessibility on touch devices
1 parent d71b1d8 commit 4abc12a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/wp-content/themes/twentyfourteen/js/functions.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@
9494
} );
9595
} );
9696

97+
/**
98+
* Enable hover for dropdown menu for touch devices
99+
*
100+
* @see trac ticket #30575
101+
*/
102+
function touchDropdown() {
103+
if ( 781 > _window.width() ) {
104+
$( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.twentyfourteen blur.twentyfourteen', function() {
105+
$( this ).parents().toggleClass( 'focus' );
106+
} );
107+
if ( 'ontouchstart' in window ) {
108+
$( document.body ).off( 'touchstart.twentyfourteen' );
109+
}
110+
} else {
111+
if ( 'ontouchstart' in window ) {
112+
$( document.body ).on( 'touchstart.twentyfourteen', '.menu-item-has-children > a, .page_item_has_children > a', function( e ) {
113+
var el = $( this ).parent( 'li' );
114+
115+
if ( ! el.hasClass( 'focus' ) ) {
116+
e.preventDefault();
117+
el.toggleClass( 'focus' );
118+
el.siblings( '.focus' ).removeClass( 'focus' );
119+
}
120+
} );
121+
}
122+
}
123+
}
124+
97125
/**
98126
* Add or remove ARIA attributes.
99127
*
@@ -107,16 +135,18 @@
107135
button.attr( 'aria-expanded', 'false' );
108136
menu.attr( 'aria-expanded', 'false' );
109137
button.attr( 'aria-controls', 'primary-menu' );
138+
$( '.menu-item-has-children' ).attr( 'aria-haspopup', 'false' );
110139
} else {
111140
button.removeAttr( 'aria-expanded' );
112141
menu.removeAttr( 'aria-expanded' );
113142
button.removeAttr( 'aria-controls' );
143+
$( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' );
114144
}
115145
}
116146

117147
_window
118-
.on( 'load.twentyfourteen', onResizeARIA )
119-
.on( 'resize.twentyfourteen', function() {
148+
.on( 'load.twentyfourteen resize.twentyfourteen', function() {
149+
touchDropdown();
120150
onResizeARIA();
121151
} );
122152

0 commit comments

Comments
 (0)