2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryItemWidget class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-04-29 21:01:56 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an ve.ui.MWCategoryItemWidget object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2015-01-08 12:40:15 +00:00
|
|
|
* @extends OO.ui.ButtonWidget
|
2015-06-05 17:59:00 +00:00
|
|
|
* @mixins OO.ui.mixin.DraggableElement
|
2013-04-29 21:01:56 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-09-11 08:05:31 +00:00
|
|
|
* @param {Object} config
|
|
|
|
* @cfg {Object} item Category item
|
|
|
|
* @cfg {string} item.name Category name
|
|
|
|
* @cfg {string} item.value
|
|
|
|
* @cfg {string} [item.sortKey='']
|
|
|
|
* @cfg {ve.dm.MWCategoryMetaItem} item.metaItem
|
2014-02-14 20:03:42 +00:00
|
|
|
* @cfg {boolean} [hidden] Whether the category is hidden or not
|
2014-11-05 22:45:09 +00:00
|
|
|
* @cfg {boolean} [missing] Whether the category's description page is missing
|
2014-03-11 19:02:16 +00:00
|
|
|
* @cfg {string} [redirectTo] The name of the category this category's page redirects to.
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryItemWidget = function VeUiMWCategoryItemWidget( config ) {
|
2014-11-21 13:00:50 +00:00
|
|
|
// Config initialization
|
2014-08-22 20:50:48 +00:00
|
|
|
config = ve.extendObject( { indicator: 'down' }, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWCategoryItemWidget.super.call( this, config );
|
2014-02-14 23:12:47 +00:00
|
|
|
|
2014-11-14 20:44:55 +00:00
|
|
|
// Mixin constructors
|
2015-06-05 17:59:00 +00:00
|
|
|
OO.ui.mixin.DraggableElement.call( this, config );
|
2014-11-14 20:44:55 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
// Properties
|
|
|
|
this.name = config.item.name;
|
|
|
|
this.value = config.item.value;
|
|
|
|
this.sortKey = config.item.sortKey || '';
|
|
|
|
this.metaItem = config.item.metaItem;
|
2014-02-14 20:03:42 +00:00
|
|
|
this.isHidden = config.hidden;
|
2014-11-05 22:45:09 +00:00
|
|
|
this.isMissing = config.missing;
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Initialization
|
2015-01-08 12:40:15 +00:00
|
|
|
this.setLabel( config.redirectTo || this.value );
|
2014-11-05 22:45:09 +00:00
|
|
|
if ( config.redirectTo ) {
|
|
|
|
ve.init.platform.linkCache.styleElement( mw.Title.newFromText(
|
|
|
|
config.redirectTo,
|
|
|
|
mw.config.get( 'wgNamespaceIds' ).category
|
|
|
|
).getPrefixedText(), this.$label );
|
|
|
|
} else {
|
|
|
|
ve.init.platform.linkCache.styleElement( this.name, this.$label );
|
|
|
|
}
|
|
|
|
|
2019-02-25 11:48:53 +00:00
|
|
|
// Events
|
|
|
|
this.on( 'click', this.onButtonClick.bind( this ) );
|
|
|
|
|
2015-01-08 12:40:15 +00:00
|
|
|
this.$element.addClass( 've-ui-mwCategoryItemWidget' );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-01-08 12:40:15 +00:00
|
|
|
OO.inheritClass( ve.ui.MWCategoryItemWidget, OO.ui.ButtonWidget );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2015-06-05 17:59:00 +00:00
|
|
|
OO.mixinClass( ve.ui.MWCategoryItemWidget, OO.ui.mixin.DraggableElement );
|
2014-11-14 20:44:55 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event togglePopupMenu
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Item to load into popup
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2019-02-25 11:48:53 +00:00
|
|
|
* Handle button widget click events.
|
2013-06-10 22:22:30 +00:00
|
|
|
*
|
2016-09-13 03:17:20 +00:00
|
|
|
* @fires togglePopupMenu on click.
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
2019-02-25 11:48:53 +00:00
|
|
|
ve.ui.MWCategoryItemWidget.prototype.onButtonClick = function () {
|
2013-04-29 21:01:56 +00:00
|
|
|
this.emit( 'togglePopupMenu', this );
|
|
|
|
};
|