mediawiki-skins-Vector/resources/skins.vector.js/menuTabs.js
Ed Sanders 7e7486c4a5 build: Update eslint-config-wikimedia to 0.28.0 and autofix
Change-Id: I350941a711d2304fc968b3ba1f1e0afa5878578e
2024-06-06 16:22:05 +01:00

36 lines
842 B
JavaScript

const
TABS_SELECTOR = '.vector-menu-tabs',
LIST_ITEM_JS_SELECTOR = '.mw-list-item-js',
NO_ICON_CLASS = 'vector-tab-noicon';
/**
* T320691: Add a `.vector-tab-noicon` class to any tabbed menu item that is
* added by a gadget so that the menu item has the correct padding and margin.
*
* @param {HTMLElement} item
*/
function addNoIconClass( item ) {
item.classList.add( NO_ICON_CLASS );
}
function init() {
// Enhance previously added items.
Array.prototype.forEach.call(
document.querySelectorAll( TABS_SELECTOR + ' ' + LIST_ITEM_JS_SELECTOR ),
addNoIconClass
);
mw.hook( 'util.addPortletLink' ).add(
/**
* @param {HTMLElement} item
*/
( item ) => {
// Check if this menu item belongs to a tabs menu.
if ( item.closest( TABS_SELECTOR ) ) {
addNoIconClass( item );
}
} );
}
module.exports = init;