equal
deleted
inserted
replaced
29 return; |
29 return; |
30 } |
30 } |
31 |
31 |
32 topMenuItems = adminBar.querySelectorAll( 'li.menupop' ); |
32 topMenuItems = adminBar.querySelectorAll( 'li.menupop' ); |
33 allMenuItems = adminBar.querySelectorAll( '.ab-item' ); |
33 allMenuItems = adminBar.querySelectorAll( '.ab-item' ); |
34 adminBarLogout = document.getElementById( 'wp-admin-bar-logout' ); |
34 adminBarLogout = document.querySelector( '#wp-admin-bar-logout a' ); |
35 adminBarSearchForm = document.getElementById( 'adminbarsearch' ); |
35 adminBarSearchForm = document.getElementById( 'adminbarsearch' ); |
36 shortlink = document.getElementById( 'wp-admin-bar-get-shortlink' ); |
36 shortlink = document.getElementById( 'wp-admin-bar-get-shortlink' ); |
37 skipLink = adminBar.querySelector( '.screen-reader-shortcut' ); |
37 skipLink = adminBar.querySelector( '.screen-reader-shortcut' ); |
38 mobileEvent = /Mobile\/.+Safari/.test( navigator.userAgent ) ? 'touchstart' : 'click'; |
38 mobileEvent = /Mobile\/.+Safari/.test( navigator.userAgent ) ? 'touchstart' : 'click'; |
39 |
39 |
93 adminBarSearchInput.addEventListener( 'blur', function() { |
93 adminBarSearchInput.addEventListener( 'blur', function() { |
94 removeClass( adminBarSearchForm, 'adminbar-focused' ); |
94 removeClass( adminBarSearchForm, 'adminbar-focused' ); |
95 } ); |
95 } ); |
96 } |
96 } |
97 |
97 |
98 if ( skipLink ) { |
|
99 // Focus the target of skip link after pressing Enter. |
|
100 skipLink.addEventListener( 'keydown', focusTargetAfterEnter ); |
|
101 } |
|
102 |
|
103 if ( shortlink ) { |
98 if ( shortlink ) { |
104 shortlink.addEventListener( 'click', clickShortlink ); |
99 shortlink.addEventListener( 'click', clickShortlink ); |
105 } |
100 } |
106 |
101 |
107 // Prevents the toolbar from covering up content when a hash is present in the URL. |
102 // Prevents the toolbar from covering up content when a hash is present in the URL. |
147 * @param {Event} event The keydown event. |
142 * @param {Event} event The keydown event. |
148 */ |
143 */ |
149 function toggleHoverIfEnter( event ) { |
144 function toggleHoverIfEnter( event ) { |
150 var wrapper; |
145 var wrapper; |
151 |
146 |
152 if ( event.which !== 13 ) { |
147 // Follow link if pressing Ctrl and/or Shift with Enter (opening in a new tab or window). |
|
148 if ( event.which !== 13 || event.ctrlKey || event.shiftKey ) { |
153 return; |
149 return; |
154 } |
150 } |
155 |
151 |
156 if ( !! getClosest( event.target, '.ab-sub-wrapper' ) ) { |
152 if ( !! getClosest( event.target, '.ab-sub-wrapper' ) ) { |
157 return; |
153 return; |
171 addClass( wrapper, 'hover' ); |
167 addClass( wrapper, 'hover' ); |
172 } |
168 } |
173 } |
169 } |
174 |
170 |
175 /** |
171 /** |
176 * Focus the target of skip link after pressing Enter. |
172 * Toggle hover class for mobile devices. |
177 * |
|
178 * @since 5.3.1 |
|
179 * |
|
180 * @param {Event} event The keydown event. |
|
181 */ |
|
182 function focusTargetAfterEnter( event ) { |
|
183 var id, userAgent; |
|
184 |
|
185 if ( event.which !== 13 ) { |
|
186 return; |
|
187 } |
|
188 |
|
189 id = event.target.getAttribute( 'href' ); |
|
190 userAgent = navigator.userAgent.toLowerCase(); |
|
191 |
|
192 if ( userAgent.indexOf( 'applewebkit' ) > -1 && id && id.charAt( 0 ) === '#' ) { |
|
193 setTimeout( function() { |
|
194 var target = document.getElementById( id.replace( '#', '' ) ); |
|
195 |
|
196 if ( target ) { |
|
197 target.setAttribute( 'tabIndex', '0' ); |
|
198 target.focus(); |
|
199 } |
|
200 }, 100 ); |
|
201 } |
|
202 } |
|
203 |
|
204 /** |
|
205 * Toogle hover class for mobile devices. |
|
206 * |
173 * |
207 * @since 5.3.1 |
174 * @since 5.3.1 |
208 * |
175 * |
209 * @param {NodeList} topMenuItems All menu items. |
176 * @param {NodeList} topMenuItems All menu items. |
210 * @param {Event} event The click event. |
177 * @param {Event} event The click event. |
334 element.className += ' '; |
301 element.className += ' '; |
335 } |
302 } |
336 |
303 |
337 element.className += className; |
304 element.className += className; |
338 } |
305 } |
|
306 |
|
307 var menuItemToggle = element.querySelector( 'a' ); |
|
308 if ( className === 'hover' && menuItemToggle && menuItemToggle.hasAttribute( 'aria-expanded' ) ) { |
|
309 menuItemToggle.setAttribute( 'aria-expanded', 'true' ); |
|
310 } |
339 } |
311 } |
340 |
312 |
341 /** |
313 /** |
342 * Remove class from an element. |
314 * Remove class from an element. |
343 * |
315 * |
363 while ( classes.indexOf( testName ) > -1 ) { |
335 while ( classes.indexOf( testName ) > -1 ) { |
364 classes = classes.replace( testName, '' ); |
336 classes = classes.replace( testName, '' ); |
365 } |
337 } |
366 |
338 |
367 element.className = classes.replace( /^[\s]+|[\s]+$/g, '' ); |
339 element.className = classes.replace( /^[\s]+|[\s]+$/g, '' ); |
|
340 } |
|
341 |
|
342 var menuItemToggle = element.querySelector( 'a' ); |
|
343 if ( className === 'hover' && menuItemToggle && menuItemToggle.hasAttribute( 'aria-expanded' ) ) { |
|
344 menuItemToggle.setAttribute( 'aria-expanded', 'false' ); |
368 } |
345 } |
369 } |
346 } |
370 |
347 |
371 /** |
348 /** |
372 * Remove hover class for all menu items. |
349 * Remove hover class for all menu items. |