Sticky header logout goes via API avoiding a second click

Bug: T324638
Change-Id: I59a192863706f1d2a09ec59090c0b099ced8cde0
This commit is contained in:
Jon Robson 2023-02-02 16:24:02 -08:00 committed by Jdlrobson
parent 61901f8b2d
commit d16d7e80d9

View file

@ -382,6 +382,11 @@ function addVisualEditorHooks( stickyIntersection, observer ) {
}
/**
* Clones the existing user menu (excluding items added by gadgets) and adds to the sticky header
* ensuring it is not focusable and that elements are no longer collapsible (since the sticky header
* itself collapses at low resolutions) and updates click tracking event names. Also wires up the
* logout link so it works in a single click.
*
* @param {Element} userMenu
* @return {Element} cloned userMenu
*/
@ -404,6 +409,16 @@ function prepareUserMenu( userMenu ) {
if ( userMenuCheckbox ) {
userMenuCheckbox.setAttribute( 'tabindex', '-1' );
}
// Make the logout go through the API (T324638)
const logoutLink = userMenuClone.querySelector( '#pt-logout-sticky-header a' );
if ( logoutLink ) {
logoutLink.addEventListener( 'click', function ( ev ) {
ev.preventDefault();
// @ts-ignore
mw.hook( 'skin.logout' ).fire( this.href );
} );
}
return userMenuClone;
}