Merge "Prevent gadgets from adding to the sticky header user menu via addPortletLink"

This commit is contained in:
jenkins-bot 2021-09-23 21:46:04 +00:00 committed by Gerrit Code Review
commit 7bd31d0c8a

View file

@ -6,7 +6,6 @@ var
FIRST_HEADING_ID = 'firstHeading', FIRST_HEADING_ID = 'firstHeading',
USER_MENU_ID = 'p-personal', USER_MENU_ID = 'p-personal',
VECTOR_USER_LINKS_SELECTOR = '.vector-user-links', VECTOR_USER_LINKS_SELECTOR = '.vector-user-links',
VECTOR_MENU_CONTENT_LIST_SELECTOR = '.vector-menu-content-list',
SEARCH_TOGGLE_SELECTOR = '.vector-sticky-header-search-toggle'; SEARCH_TOGGLE_SELECTOR = '.vector-sticky-header-search-toggle';
/** /**
@ -112,23 +111,11 @@ function makeStickyHeaderFunctional(
makeNodeTrackable( userMenuClone ); makeNodeTrackable( userMenuClone );
userMenuStickyElementsWithIds.forEach( makeNodeTrackable ); userMenuStickyElementsWithIds.forEach( makeNodeTrackable );
// Add gadget-injected items of the fixed user menu into the sticky header user menu. // Remove portlet links added by gadgets using mw.util.addPortletLink
// Only applies to gadgets running after the code above and won't apply to existing items. var gadgetLinks = userMenuClone.querySelector( 'mw-list-item-js' );
mw.hook( 'util.addPortletLink' ).add( function ( /** @type {HTMLElement} */ item ) { if ( gadgetLinks ) {
// Get the nav tag parent of the gadget-injected menu item. We verify that .closest is gadgetLinks.remove();
// available for use because of feature detection in init function.
var parentNav = item.closest( 'nav' );
// Check if a gadget is injecting an item into the user menu.
if ( parentNav && parentNav.getAttribute( 'id' ) === 'p-personal' ) {
var
itemClone = /** @type {HTMLElement} */ ( item.cloneNode( true ) ),
userMenuCloneUl = userMenuClone.querySelector( VECTOR_MENU_CONTENT_LIST_SELECTOR );
if ( userMenuCloneUl ) {
makeNodeTrackable( itemClone );
userMenuCloneUl.appendChild( itemClone );
} }
}
} );
// Clone the updated user menu to the sticky header. // Clone the updated user menu to the sticky header.
if ( userMenuStickyContainerInner ) { if ( userMenuStickyContainerInner ) {