Debian Codegraph @

extensions/Echo/modules/ui/mw.echo.ui.ActionMenuPopupWidget.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Action menu popup widget for echo items.
4 *
5 * We don't currently have anything that properly answers the complete
6 * design for our popup menus in OOUI, so this widget serves two purposes:
7 * 1. The MenuSelectWidget is intended to deliver a menu that relates
8 * directly to its anchor, so its sizing is dictated by whatever anchors
9 * it. This is not what we require, so we have to override the 'click' event
10 * to reset the width of the menu.
11 * 2. It abstracts the behavior of the item menus for easier management
12 * in the item widget itself (which is fairly large)
13 *
14 * @class
15 * @extends OO.ui.ButtonWidget
16 *
17 * @constructor
18 * @param {Object} [config] Configuration object
19 * @param {jQuery} [config.$overlay] A jQuery element functioning as an overlay
20 * for popups.
21 * @param {Object} [config.horizontalPosition='auto'] How to position the menu, see OO.ui.FloatableElement.
22 * By default, 'start' will be tried first, and if that doesn't fit, 'end' will be used.
23 */
24 mw.echo.ui.ActionMenuPopupWidget = function MwEchoUiActionMenuPopupWidget( config ) {
25 config = config || {};
26
27 // Parent constructor
28 mw.echo.ui.ActionMenuPopupWidget.super.call( this, config );
29
30 this.$overlay = config.$overlay || this.$element;
31
32 // Menu
33 this.customMenuPosition = ( config.horizontalPosition || 'auto' ) !== 'auto';
34 this.menu = new OO.ui.MenuSelectWidget( {
35 $floatableContainer: this.$element,
36 horizontalPosition: this.customMenuPosition ? config.horizontalPosition : 'start',
37 classes: [ 'mw-echo-ui-actionMenuPopupWidget-menu' ],
38 widget: this
39 } );
40 this.$overlay.append( this.menu.$element );
41
42 // Events
43 this.connect( this, { click: 'onAction' } );
44 this.getMenu().connect( this, {
45 remove: 'decideToggle',
46 add: 'decideToggle',
47 clear: 'decideToggle'
48 } );
49 // Initialization
50 this.$element
51 .addClass( 'mw-echo-ui-actionMenuPopupWidget' );
52 };
53
54 /* Setup */
55
56 OO.inheritClass( mw.echo.ui.ActionMenuPopupWidget, OO.ui.ButtonWidget );
57
58 /**
59 * Handle the button action being triggered.
60 *
61 * @private
62 */
63 mw.echo.ui.ActionMenuPopupWidget.prototype.onAction = function () {
64 // HACK: If config.horizontalPosition isn't set, first try 'start', then 'end'
65 if ( !this.customMenuPosition ) {
66 this.menu.setHorizontalPosition( 'start' );
67 }
68 this.menu.toggle();
69 if ( !this.customMenuPosition && this.menu.isClipped() ) {
70 this.menu.setHorizontalPosition( 'end' );
71 }
72 };
73
74 /**
75 * Decide whether the menu should be visible, based on whether it is
76 * empty or not.
77 */
78 mw.echo.ui.ActionMenuPopupWidget.prototype.decideToggle = function () {
79 this.toggle( !this.getMenu().isEmpty() );
80 };
81
82 /**
83 * Get the widget's action menu
84 *
85 * @return {OO.ui.MenuSelectWidget} Menu
86 */
87 mw.echo.ui.ActionMenuPopupWidget.prototype.getMenu = function () {
88 return this.menu;
89 };
90 }() );