2023-10-11 12:04:39 +00:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2024-04-18 18:37:58 +00:00
|
|
|
mw.loader.using( [ 'oojs-ui-widgets', 'oojs-ui.styles.icons-editing-core' ] ).then( () => {
|
|
|
|
$container.find( '.ext-discussiontools-init-section-overflowMenuButton' ).each( ( i, button ) => {
|
2023-10-11 12:04:39 +00:00
|
|
|
// Comment ellipsis
|
2024-05-24 12:20:50 +00:00
|
|
|
let $threadMarker = $( button ).closest( '[data-mw-thread-id]' );
|
2023-10-11 12:04:39 +00:00
|
|
|
if ( !$threadMarker.length ) {
|
|
|
|
// Heading ellipsis
|
2024-04-18 18:37:58 +00:00
|
|
|
$threadMarker = $( button ).closest( '.ext-discussiontools-init-section' ).find( '[data-mw-thread-id]' );
|
2023-10-11 12:04:39 +00:00
|
|
|
}
|
2024-05-24 12:20:50 +00:00
|
|
|
const threadItem = pageThreads.findCommentById( $threadMarker.data( 'mw-thread-id' ) );
|
2023-10-11 12:04:39 +00:00
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
const buttonMenu = OO.ui.infuse( button, {
|
2023-10-11 12:04:39 +00:00
|
|
|
$overlay: true,
|
|
|
|
menu: {
|
|
|
|
classes: [ 'ext-discussiontools-init-section-overflowMenu' ],
|
|
|
|
horizontalPosition: threadItem.type === 'heading' ? 'end' : 'start'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
mw.loader.using( buttonMenu.getData().resourceLoaderModules || [] ).then( () => {
|
2024-05-24 12:20:50 +00:00
|
|
|
const itemConfigs = buttonMenu.getData().itemConfigs;
|
2023-10-11 12:04:39 +00:00
|
|
|
if ( !itemConfigs ) {
|
|
|
|
// We should never have missing itemConfigs, but if this happens, hide the empty menu
|
|
|
|
buttonMenu.toggle( false );
|
|
|
|
return;
|
|
|
|
}
|
2024-05-24 12:20:50 +00:00
|
|
|
const overflowMenuItemWidgets = itemConfigs.map( ( itemConfig ) => new OO.ui.MenuOptionWidget( itemConfig ) );
|
2023-10-11 12:04:39 +00:00
|
|
|
buttonMenu.getMenu().addItems( overflowMenuItemWidgets );
|
2024-04-18 18:37:58 +00:00
|
|
|
buttonMenu.getMenu().items.forEach( ( menuItem ) => {
|
2023-10-11 12:04:39 +00:00
|
|
|
mw.hook( 'discussionToolsOverflowMenuOnAddItem' ).fire( menuItem.getData().id, menuItem, threadItem );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
buttonMenu.getMenu().on( 'choose', ( menuItem ) => {
|
2023-10-11 12:04:39 +00:00
|
|
|
mw.hook( 'discussionToolsOverflowMenuOnChoose' ).fire( menuItem.getData().id, menuItem, threadItem );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
$container.find( '.ext-discussiontools-init-section-bar' ).on( 'click', ( e ) => {
|
2023-10-11 12:04:39 +00:00
|
|
|
// Don't toggle section when clicking on bar
|
|
|
|
e.stopPropagation();
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: init
|
|
|
|
};
|