mediawiki-skins-Vector/resources/skins.vector.js/menuTabs.js
Jon Robson 10033b294e Drop ES5 compatible code
Drop usages of $.closest in favor of ES6 closest

We also no longer need to check for whether closest is available
now that we do not need to worry about ES5 code.

Change-Id: I2442a4f69f8181dd761ca7ac418839cfca26a36f
2023-04-13 00:27:22 +00:00

36 lines
848 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
*/
function ( item ) {
// Check if this menu item belongs to a tabs menu.
if ( item.closest( TABS_SELECTOR ) ) {
addNoIconClass( item );
}
} );
}
module.exports = init;