|
94 | 94 | } ); |
95 | 95 | } ); |
96 | 96 |
|
| 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 | + |
97 | 125 | /** |
98 | 126 | * Add or remove ARIA attributes. |
99 | 127 | * |
|
107 | 135 | button.attr( 'aria-expanded', 'false' ); |
108 | 136 | menu.attr( 'aria-expanded', 'false' ); |
109 | 137 | button.attr( 'aria-controls', 'primary-menu' ); |
| 138 | + $( '.menu-item-has-children' ).attr( 'aria-haspopup', 'false' ); |
110 | 139 | } else { |
111 | 140 | button.removeAttr( 'aria-expanded' ); |
112 | 141 | menu.removeAttr( 'aria-expanded' ); |
113 | 142 | button.removeAttr( 'aria-controls' ); |
| 143 | + $( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' ); |
114 | 144 | } |
115 | 145 | } |
116 | 146 |
|
117 | 147 | _window |
118 | | - .on( 'load.twentyfourteen', onResizeARIA ) |
119 | | - .on( 'resize.twentyfourteen', function() { |
| 148 | + .on( 'load.twentyfourteen resize.twentyfourteen', function() { |
| 149 | + touchDropdown(); |
120 | 150 | onResizeARIA(); |
121 | 151 | } ); |
122 | 152 |
|
|
0 commit comments