mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-11 16:16:51 +00:00
ca5157156a
Leave rule off for now as manual fixes are required. Also temporarily disable prefer-const rule as that will also require some manual fixes. Change-Id: I8c3478f26f51287acb943bd38c9c1020c06b9f39
55 lines
2 KiB
JavaScript
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
|
|
let $threadMarker = $( button ).closest( '[data-mw-thread-id]' );
|
|
if ( !$threadMarker.length ) {
|
|
// Heading ellipsis
|
|
$threadMarker = $( button ).closest( '.ext-discussiontools-init-section' ).find( '[data-mw-thread-id]' );
|
|
}
|
|
const threadItem = pageThreads.findCommentById( $threadMarker.data( 'mw-thread-id' ) );
|
|
|
|
const 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( () => {
|
|
const itemConfigs = buttonMenu.getData().itemConfigs;
|
|
if ( !itemConfigs ) {
|
|
// We should never have missing itemConfigs, but if this happens, hide the empty menu
|
|
buttonMenu.toggle( false );
|
|
return;
|
|
}
|
|
const 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
|
|
};
|