mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-19 01:01:00 +00:00
fb36687fc3
Since we are dealing with arrays here with the value of classes but using native DOMElement we need to convert the array to a string Follow up to I331912a1cd6cd4293c22a1a48bb32cdec48bd37d Change-Id: If08d68af8cebecaea02cc29bf779d25d58c0c6c3
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
/**
|
|
* @param {jQuery.Object} $item The added list item, or null if no element was added.
|
|
* @return {Object} of arrays with mandatory class names for list item elements.
|
|
*/
|
|
function getClassesForItem( $item ) {
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
|
var isToggleList = $item.parent().hasClass( 'toggle-list__list' );
|
|
if ( isToggleList ) {
|
|
return {
|
|
li: [ 'toggle-list-item' ],
|
|
span: [ 'toggle-list-item__label' ],
|
|
a: [ 'toggle-list-item__anchor' ]
|
|
};
|
|
} else {
|
|
return {
|
|
li: [],
|
|
span: [],
|
|
a: []
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {HTMLElement|null} link The added list item, or null if no element was added.
|
|
* @param {Object} data
|
|
*/
|
|
module.exports = function ( link, data ) {
|
|
var label, $item, $a, classes,
|
|
id = data.id || 'unknowngadget';
|
|
|
|
if ( link ) {
|
|
$item = $( link );
|
|
classes = getClassesForItem( $item );
|
|
$item.addClass( classes.li );
|
|
$a = $item.find( 'a' );
|
|
$a.addClass( [
|
|
'menu-list-item__button',
|
|
'menu__item--' + id,
|
|
'mw-ui-icon',
|
|
'mw-ui-icon-before',
|
|
'mw-ui-icon-portletlink-' + id
|
|
].concat( classes.a ) );
|
|
label = document.createElement( 'span' );
|
|
label.setAttribute( 'class', classes.span.join( ' ' ) );
|
|
label.textContent = $item.text();
|
|
$a.empty().append( label );
|
|
}
|
|
};
|