2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-01-30 00:27:47 +00:00
|
|
|
/**
|
|
|
|
* Secondary menu item
|
|
|
|
*
|
|
|
|
* @class
|
2020-07-23 13:38:23 +00:00
|
|
|
* @extends OO.ui.ButtonOptionWidget
|
2024-04-30 14:21:54 +00:00
|
|
|
* @mixes OO.ui.mixin.PendingElement
|
2016-01-30 00:27:47 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {string} [config.type] Optional action type. Used to note a dynamic action, by setting it to 'dynamic-action'
|
|
|
|
* @param {string} [config.url] Item URL for links
|
|
|
|
* @param {string} [config.tooltip] Tooltip for links
|
|
|
|
* @param {string} [config.description] An optional description for the item
|
|
|
|
* @param {Object} [config.actionData] Action data
|
|
|
|
* @param {boolean} [config.prioritized] The item is prioritized outside the
|
2016-01-30 00:27:47 +00:00
|
|
|
* popup menu.
|
|
|
|
*/
|
|
|
|
mw.echo.ui.MenuItemWidget = function MwEchoUiMenuItemWidget( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
2018-03-24 20:52:04 +00:00
|
|
|
this.dynamic = config.type === 'dynamic-action';
|
|
|
|
// Needs to be set before parent constructor is called
|
|
|
|
// as it changes the value of getTagName.
|
|
|
|
this.isLink = config.url && !this.isDynamicAction();
|
|
|
|
|
2016-01-30 00:27:47 +00:00
|
|
|
// Parent constructor
|
2024-06-13 14:34:07 +00:00
|
|
|
mw.echo.ui.MenuItemWidget.super.call( this, Object.assign( { framed: false }, config ) );
|
2016-01-30 00:27:47 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
2016-08-05 21:44:55 +00:00
|
|
|
OO.ui.mixin.PendingElement.call( this, config );
|
2016-01-30 00:27:47 +00:00
|
|
|
|
|
|
|
this.prioritized = !!config.prioritized;
|
2016-08-05 21:44:55 +00:00
|
|
|
this.messages = this.isDynamicAction() ?
|
|
|
|
config.actionData.messages :
|
2016-08-24 23:45:02 +00:00
|
|
|
{};
|
2016-08-05 21:44:55 +00:00
|
|
|
|
|
|
|
this.actionData = config.actionData || {};
|
|
|
|
|
2016-01-30 00:27:47 +00:00
|
|
|
// Optional description
|
|
|
|
this.descriptionLabel = new OO.ui.LabelWidget( {
|
2018-03-24 20:52:04 +00:00
|
|
|
classes: [ 'mw-echo-ui-menuItemWidget-description' ],
|
2016-08-24 23:45:02 +00:00
|
|
|
label: config.description || ''
|
2016-01-30 00:27:47 +00:00
|
|
|
} );
|
2016-08-24 23:45:02 +00:00
|
|
|
this.descriptionLabel.toggle( !this.prioritized && config.description );
|
2016-01-30 00:27:47 +00:00
|
|
|
|
2018-03-24 20:52:04 +00:00
|
|
|
this.$label.append( this.descriptionLabel.$element );
|
|
|
|
|
2016-01-30 00:27:47 +00:00
|
|
|
// Build the option
|
|
|
|
this.$element
|
|
|
|
.addClass( 'mw-echo-ui-menuItemWidget' )
|
|
|
|
.toggleClass( 'mw-echo-ui-menuItemWidget-prioritized', this.prioritized )
|
2018-03-24 20:52:04 +00:00
|
|
|
.toggleClass( 'mw-echo-ui-menuItemWidget-dynamic-action', this.isDynamicAction() );
|
|
|
|
|
|
|
|
if ( this.isLink ) {
|
|
|
|
this.$element.attr( {
|
|
|
|
href: config.url,
|
|
|
|
title: config.tooltip
|
|
|
|
} );
|
2016-01-30 00:27:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
2020-07-23 13:38:23 +00:00
|
|
|
OO.inheritClass( mw.echo.ui.MenuItemWidget, OO.ui.ButtonOptionWidget );
|
2016-08-05 21:44:55 +00:00
|
|
|
OO.mixinClass( mw.echo.ui.MenuItemWidget, OO.ui.mixin.PendingElement );
|
2016-01-30 00:27:47 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
mw.echo.ui.MenuItemWidget.static.highlightable = false;
|
|
|
|
mw.echo.ui.MenuItemWidget.static.pressable = false;
|
|
|
|
|
2016-03-01 02:34:02 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2018-03-24 20:52:04 +00:00
|
|
|
mw.echo.ui.MenuItemWidget.prototype.getTagName = function () {
|
|
|
|
return this.isLink ? 'a' : 'div';
|
|
|
|
};
|
|
|
|
|
2022-08-23 21:02:28 +00:00
|
|
|
mw.echo.ui.MenuItemWidget.prototype.onClick = function ( e ) {
|
|
|
|
// Stop propagation, so that the default dynamic action of the notification isn't triggered
|
|
|
|
// (e.g. expanding a bundled notification).
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// If this is a dynamic action, also prevent default to disable the native browser behavior,
|
|
|
|
// the default link of the notification won't be followed.
|
|
|
|
// (If this is a link, default link of the notification is ignored as native browser behavior.)
|
|
|
|
if ( !this.isLink ) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mw.echo.ui.MenuItemWidget.super.prototype.onClick.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2016-03-01 02:34:02 +00:00
|
|
|
mw.echo.ui.MenuItemWidget.prototype.isSelectable = function () {
|
2016-08-05 21:44:55 +00:00
|
|
|
// If we have a link force selectability to false, otherwise defer to parent method
|
|
|
|
// Without a link (for dynamic actions or specific internal actions) we need this widget
|
|
|
|
// to be selectable so it emits the 'choose' event
|
2018-05-22 14:56:46 +00:00
|
|
|
return !this.isLink && mw.echo.ui.MenuItemWidget.super.prototype.isSelectable.apply( this, arguments );
|
2016-03-01 02:34:02 +00:00
|
|
|
};
|
|
|
|
|
2016-08-05 21:44:55 +00:00
|
|
|
/**
|
|
|
|
* Check whether this item is prioritized
|
|
|
|
*
|
|
|
|
* @return {boolean} Item is prioritized
|
|
|
|
*/
|
|
|
|
mw.echo.ui.MenuItemWidget.prototype.isPrioritized = function () {
|
|
|
|
return this.prioritized;
|
|
|
|
};
|
|
|
|
|
2024-04-30 14:21:54 +00:00
|
|
|
/**
|
|
|
|
* @typedef {Object} ConfirmationMessages
|
|
|
|
* @memberof mw.echo.ui.MenuItemWidget
|
|
|
|
* @property {string} title Title for the confirmation dialog
|
|
|
|
* @property {string} description Description for the confirmation dialog
|
|
|
|
*/
|
|
|
|
|
2016-08-05 21:44:55 +00:00
|
|
|
/**
|
|
|
|
* Get the messages for the confirmation dialog
|
|
|
|
* We expect optionally two messages - title and description.
|
|
|
|
*
|
|
|
|
* NOTE: The messages are parsed as HTML. If user-input is expected
|
|
|
|
* please make sure to properly escape it.
|
|
|
|
*
|
2024-04-30 14:21:54 +00:00
|
|
|
* @return {mw.echo.ui.MenuItemWidget.ConfirmationMessages} Messages for the confirmation dialog
|
2016-08-05 21:44:55 +00:00
|
|
|
*/
|
|
|
|
mw.echo.ui.MenuItemWidget.prototype.getConfirmationMessages = function () {
|
|
|
|
return this.messages.confirmation;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the action data associated with this item
|
|
|
|
*
|
|
|
|
* @return {Object} Action data
|
|
|
|
*/
|
|
|
|
mw.echo.ui.MenuItemWidget.prototype.getActionData = function () {
|
|
|
|
return this.actionData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This item is a dynamic action
|
|
|
|
*
|
|
|
|
* @return {boolean} Item is a dynamic action
|
|
|
|
*/
|
|
|
|
mw.echo.ui.MenuItemWidget.prototype.isDynamicAction = function () {
|
|
|
|
return this.dynamic;
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|