2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryItemWidget class.
|
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 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
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-10 22:22:30 +00:00
|
|
|
* @cfg {Object} [item] Category item
|
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 );
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
/**
|
2013-06-10 22:22:30 +00:00
|
|
|
* Handle mouse click events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
2016-09-13 03:17:20 +00:00
|
|
|
* @fires togglePopupMenu on click.
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryItemWidget.prototype.onClick = function () {
|
|
|
|
this.emit( 'togglePopupMenu', this );
|
2015-02-05 19:42:57 +00:00
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ve.ui.MWCategoryItemWidget.super.prototype.onClick.apply( this, arguments );
|
2013-04-29 21:01:56 +00:00
|
|
|
};
|