mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-04 10:48:52 +00:00
b518e55ef9
This is not great, but it's a start (and unblocks other pull-throughs). New changes: c401efc98 build: Replace jsduck with jsdoc for documentation 16ba162a0 JSDoc: @mixins -> @mixes 9e0a1f53b JSDoc: Fix complex return types 449b6cc0f Prefer arrow function callbacks 1539af2c8 Remove 'this' bindings in arrow functions b760f3b14 Use arrow functions in OO.ui.Process steps 57c24109e Use arrow functions in jQuery callbacks 9622ccef9 Convert some remaining functions callbacks to arrow functions f6c885021 Remove useless local variable 1cd800020 Clear branch node cache when rebuilding tree Bug: T250843 Bug: T363329 Change-Id: I0f4878ca84b95e3f388b358b943f105637e455f9
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MWCategoryItemWidget class.
|
|
*
|
|
* @copyright See AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.MWCategoryItemWidget object.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
* @extends OO.ui.ButtonWidget
|
|
* @mixins OO.ui.mixin.DraggableElement
|
|
*
|
|
* @constructor
|
|
* @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
|
|
* @cfg {boolean} [hidden] Whether the category is hidden or not
|
|
* @cfg {boolean} [missing] Whether the category's description page is missing
|
|
* @cfg {string} [redirectTo] The name of the category this category's page redirects to.
|
|
*/
|
|
ve.ui.MWCategoryItemWidget = function VeUiMWCategoryItemWidget( config ) {
|
|
// Config initialization
|
|
config = ve.extendObject( { indicator: 'down' }, config );
|
|
|
|
// Parent constructor
|
|
ve.ui.MWCategoryItemWidget.super.call( this, config );
|
|
|
|
// Mixin constructors
|
|
OO.ui.mixin.DraggableElement.call( this, config );
|
|
|
|
// Properties
|
|
this.name = config.item.name;
|
|
this.value = config.item.value;
|
|
this.sortKey = config.item.sortKey || '';
|
|
this.metaItem = config.item.metaItem;
|
|
this.isHidden = config.hidden;
|
|
this.isMissing = config.missing;
|
|
|
|
// Initialization
|
|
this.setLabel( config.redirectTo || this.value );
|
|
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 );
|
|
}
|
|
|
|
// Events
|
|
this.on( 'click', this.onButtonClick.bind( this ) );
|
|
|
|
this.$element.addClass( 've-ui-mwCategoryItemWidget' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWCategoryItemWidget, OO.ui.ButtonWidget );
|
|
|
|
OO.mixinClass( ve.ui.MWCategoryItemWidget, OO.ui.mixin.DraggableElement );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event ve.ui.MWCategoryItemWidget#togglePopupMenu
|
|
* @param {ve.ui.MWCategoryItemWidget} item Item to load into popup
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle button widget click events.
|
|
*
|
|
* @fires togglePopupMenu on click.
|
|
*/
|
|
ve.ui.MWCategoryItemWidget.prototype.onButtonClick = function () {
|
|
this.emit( 'togglePopupMenu', this );
|
|
};
|