mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-15 03:44:02 +00:00
60bcf84dbb
Why: - We'll reuse this functionality on desktop, so it makes sense to extract it to a standalone file What: - Remove relevant code from mobile.js and place in overflowMenu.js Bug: T342251 Change-Id: I98f1253e8d6db31c1f71203b50911b6f1b92778b
59 lines
2.2 KiB
JavaScript
59 lines
2.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( function () {
|
|
// TODO: Replace with .ext-discussiontools-init-section-overflowMenuButton
|
|
// after parser cache is updated
|
|
$container.find( '.ext-discussiontools-init-section-ellipsisButton' ).each( function () {
|
|
// Comment ellipsis
|
|
var $threadMarker = $( this ).closest( '[data-mw-thread-id]' );
|
|
if ( !$threadMarker.length ) {
|
|
// Heading ellipsis
|
|
$threadMarker = $( this ).closest( '.ext-discussiontools-init-section' ).find( '[data-mw-thread-id]' );
|
|
}
|
|
var threadItem = pageThreads.findCommentById( $threadMarker.data( 'mw-thread-id' ) );
|
|
|
|
var buttonMenu = OO.ui.infuse( this, {
|
|
$overlay: true,
|
|
menu: {
|
|
classes: [ 'ext-discussiontools-init-section-overflowMenu' ],
|
|
horizontalPosition: threadItem.type === 'heading' ? 'end' : 'start'
|
|
}
|
|
} );
|
|
|
|
mw.loader.using( buttonMenu.getData().resourceLoaderModules || [] ).then( function () {
|
|
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( function ( itemConfig ) {
|
|
return new OO.ui.MenuOptionWidget( itemConfig );
|
|
} );
|
|
buttonMenu.getMenu().addItems( overflowMenuItemWidgets );
|
|
buttonMenu.getMenu().items.forEach( function ( menuItem ) {
|
|
mw.hook( 'discussionToolsOverflowMenuOnAddItem' ).fire( menuItem.getData().id, menuItem, threadItem );
|
|
} );
|
|
} );
|
|
|
|
buttonMenu.getMenu().on( 'choose', function ( menuItem ) {
|
|
mw.hook( 'discussionToolsOverflowMenuOnChoose' ).fire( menuItem.getData().id, menuItem, threadItem );
|
|
} );
|
|
} );
|
|
|
|
$container.find( '.ext-discussiontools-init-section-bar' ).on( 'click', function ( e ) {
|
|
// Don't toggle section when clicking on bar
|
|
e.stopPropagation();
|
|
} );
|
|
} );
|
|
}
|
|
|
|
module.exports = {
|
|
init: init
|
|
};
|