2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2015-10-16 23:18:25 +00:00
|
|
|
/**
|
|
|
|
* Action menu popup widget for echo items.
|
|
|
|
*
|
|
|
|
* We don't currently have anything that properly answers the complete
|
|
|
|
* design for our popup menus in OOUI, so this widget serves two purposes:
|
2017-06-23 19:42:23 +00:00
|
|
|
* 1. The MenuSelectWidget is intended to deliver a menu that relates
|
2015-10-16 23:18:25 +00:00
|
|
|
* directly to its anchor, so its sizing is dictated by whatever anchors
|
|
|
|
* it. This is not what we require, so we have to override the 'click' event
|
|
|
|
* to reset the width of the menu.
|
|
|
|
* 2. It abstracts the behavior of the item menus for easier management
|
|
|
|
* in the item widget itself (which is fairly large)
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.ButtonWidget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {jQuery} [$overlay] A jQuery element functioning as an overlay
|
|
|
|
* for popups.
|
2020-04-28 03:41:25 +00:00
|
|
|
* @cfg {Object} [horizontalPosition='auto'] How to position the menu, see OO.ui.FloatableElement.
|
|
|
|
* By default, 'start' will be tried first, and if that doesn't fit, 'end' will be used.
|
2015-10-16 23:18:25 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.ActionMenuPopupWidget = function MwEchoUiActionMenuPopupWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2018-05-22 14:56:46 +00:00
|
|
|
mw.echo.ui.ActionMenuPopupWidget.super.call( this, config );
|
2015-10-16 23:18:25 +00:00
|
|
|
|
|
|
|
this.$overlay = config.$overlay || this.$element;
|
|
|
|
|
|
|
|
// Menu
|
2020-04-28 03:41:25 +00:00
|
|
|
this.customMenuPosition = ( config.horizontalPosition || 'auto' ) !== 'auto';
|
2020-10-03 18:30:01 +00:00
|
|
|
this.menu = new OO.ui.MenuSelectWidget( {
|
2017-06-23 19:42:23 +00:00
|
|
|
$floatableContainer: this.$element,
|
2020-04-28 03:41:25 +00:00
|
|
|
horizontalPosition: this.customMenuPosition ? config.horizontalPosition : 'start',
|
2016-01-18 23:01:17 +00:00
|
|
|
classes: [ 'mw-echo-ui-actionMenuPopupWidget-menu' ],
|
|
|
|
widget: this
|
2020-10-03 18:30:01 +00:00
|
|
|
} );
|
2015-10-16 23:18:25 +00:00
|
|
|
this.$overlay.append( this.menu.$element );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.connect( this, { click: 'onAction' } );
|
2016-08-05 21:44:55 +00:00
|
|
|
this.getMenu().connect( this, {
|
|
|
|
remove: 'decideToggle',
|
|
|
|
add: 'decideToggle',
|
|
|
|
clear: 'decideToggle'
|
|
|
|
} );
|
2015-10-16 23:18:25 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-actionMenuPopupWidget' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup */
|
|
|
|
|
|
|
|
OO.inheritClass( mw.echo.ui.ActionMenuPopupWidget, OO.ui.ButtonWidget );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the button action being triggered.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ActionMenuPopupWidget.prototype.onAction = function () {
|
2020-04-28 03:41:25 +00:00
|
|
|
// HACK: If config.horizontalPosition isn't set, first try 'start', then 'end'
|
|
|
|
if ( !this.customMenuPosition ) {
|
|
|
|
this.menu.setHorizontalPosition( 'start' );
|
|
|
|
}
|
2015-10-16 23:18:25 +00:00
|
|
|
this.menu.toggle();
|
2020-04-28 03:41:25 +00:00
|
|
|
if ( !this.customMenuPosition && this.menu.isClipped() ) {
|
|
|
|
this.menu.setHorizontalPosition( 'end' );
|
|
|
|
}
|
2015-10-16 23:18:25 +00:00
|
|
|
};
|
|
|
|
|
2016-08-05 21:44:55 +00:00
|
|
|
/**
|
|
|
|
* Decide whether the menu should be visible, based on whether it is
|
|
|
|
* empty or not.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.ActionMenuPopupWidget.prototype.decideToggle = function () {
|
|
|
|
this.toggle( !this.getMenu().isEmpty() );
|
|
|
|
};
|
|
|
|
|
2015-10-16 23:18:25 +00:00
|
|
|
/**
|
|
|
|
* Get the widget's action menu
|
|
|
|
*
|
2017-06-23 19:42:23 +00:00
|
|
|
* @return {OO.ui.MenuSelectWidget} Menu
|
2015-10-16 23:18:25 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.ActionMenuPopupWidget.prototype.getMenu = function () {
|
|
|
|
return this.menu;
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|