mediawiki-extensions-Discus.../modules/overflowMenu.js
Bartosz Dziewoński d4c5aebd8f Prefer short arrow functions
When an arrow function body contains just a single `return` statement,
the braces can be omitted.

(Changes are mostly made by `grunt eslint --fix`, with only some line
breaks added by hand.)

Change-Id: I37f259f87085c8d20ed09cfa58a8456dd36cdc38
2024-04-20 00:08:51 +02:00

55 lines
2 KiB
JavaScript

/**
* Build an overflow menu button and items for display adjacent to heading and comment thread items.
*
* @param {jQuery} $container
* @param {ThreadItemSet} pageThreads
*/
function init( $container, pageThreads ) {
mw.loader.using( [ 'oojs-ui-widgets', 'oojs-ui.styles.icons-editing-core' ] ).then( () => {
$container.find( '.ext-discussiontools-init-section-overflowMenuButton' ).each( ( i, button ) => {
// Comment ellipsis
var $threadMarker = $( button ).closest( '[data-mw-thread-id]' );
if ( !$threadMarker.length ) {
// Heading ellipsis
$threadMarker = $( button ).closest( '.ext-discussiontools-init-section' ).find( '[data-mw-thread-id]' );
}
var threadItem = pageThreads.findCommentById( $threadMarker.data( 'mw-thread-id' ) );
var buttonMenu = OO.ui.infuse( button, {
$overlay: true,
menu: {
classes: [ 'ext-discussiontools-init-section-overflowMenu' ],
horizontalPosition: threadItem.type === 'heading' ? 'end' : 'start'
}
} );
mw.loader.using( buttonMenu.getData().resourceLoaderModules || [] ).then( () => {
var itemConfigs = buttonMenu.getData().itemConfigs;
if ( !itemConfigs ) {
// We should never have missing itemConfigs, but if this happens, hide the empty menu
buttonMenu.toggle( false );
return;
}
var overflowMenuItemWidgets = itemConfigs.map( ( itemConfig ) => new OO.ui.MenuOptionWidget( itemConfig ) );
buttonMenu.getMenu().addItems( overflowMenuItemWidgets );
buttonMenu.getMenu().items.forEach( ( menuItem ) => {
mw.hook( 'discussionToolsOverflowMenuOnAddItem' ).fire( menuItem.getData().id, menuItem, threadItem );
} );
} );
buttonMenu.getMenu().on( 'choose', ( menuItem ) => {
mw.hook( 'discussionToolsOverflowMenuOnChoose' ).fire( menuItem.getData().id, menuItem, threadItem );
} );
} );
$container.find( '.ext-discussiontools-init-section-bar' ).on( 'click', ( e ) => {
// Don't toggle section when clicking on bar
e.stopPropagation();
} );
} );
}
module.exports = {
init: init
};