Debian Codegraph @

extensions/DiscussionTools/modules/overflowMenu.js

raw symbols SCIP
1 /**
2 * Build an overflow menu button and items for display adjacent to heading and comment thread items.
3 *
4 * @param {jQuery} $container
5 * @param {ThreadItemSet} pageThreads
6 */
7 function init( $container, pageThreads ) {
8 mw.loader.using( [ 'oojs-ui-widgets', 'oojs-ui.styles.icons-editing-core' ] ).then( () => {
9 $container.find( '.ext-discussiontools-init-section-overflowMenuButton' ).each( ( i, button ) => {
10 // Comment ellipsis
11 let $threadMarker = $( button ).closest( '[data-mw-thread-id]' );
12 if ( !$threadMarker.length ) {
13 // Heading ellipsis
14 $threadMarker = $( button ).closest( '.ext-discussiontools-init-section' ).find( '[data-mw-thread-id]' );
15 }
16 const threadItem = pageThreads.findCommentById( $threadMarker.data( 'mw-thread-id' ) );
17
18 const buttonMenu = OO.ui.infuse( button, {
19 $overlay: true,
20 menu: {
21 classes: [ 'ext-discussiontools-init-section-overflowMenu' ],
22 horizontalPosition: threadItem.type === 'heading' ? 'end' : 'start'
23 }
24 } );
25
26 mw.loader.using( buttonMenu.getData().resourceLoaderModules || [] ).then( () => {
27 const itemConfigs = buttonMenu.getData().itemConfigs;
28 if ( !itemConfigs ) {
29 // We should never have missing itemConfigs, but if this happens, hide the empty menu
30 buttonMenu.toggle( false );
31 return;
32 }
33 const overflowMenuItemWidgets = itemConfigs.map( ( itemConfig ) => new OO.ui.MenuOptionWidget( itemConfig ) );
34 buttonMenu.getMenu().addItems( overflowMenuItemWidgets );
35 buttonMenu.getMenu().items.forEach( ( menuItem ) => {
36 mw.hook( 'discussionToolsOverflowMenuOnAddItem' ).fire( menuItem.getData().id, menuItem, threadItem );
37 } );
38 } );
39
40 buttonMenu.getMenu().on( 'choose', ( menuItem ) => {
41 mw.hook( 'discussionToolsOverflowMenuOnChoose' ).fire( menuItem.getData().id, menuItem, threadItem );
42 } );
43 } );
44
45 $container.find( '.ext-discussiontools-init-section-bar' ).on( 'click', ( e ) => {
46 // Don't toggle section when clicking on bar
47 e.stopPropagation();
48 } );
49 } );
50 }
51
52 module.exports = {
53 init: init
54 };