Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/widgets/ve.ui.MWCategoryItemWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface MWCategoryItemWidget class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * Creates an ve.ui.MWCategoryItemWidget object.
10 *
11 * @class
12 * @abstract
13 * @extends OO.ui.ButtonWidget
14 * @mixes OO.ui.mixin.DraggableElement
15 *
16 * @constructor
17 * @param {Object} config
18 * @param {Object} config.item Category item
19 * @param {string} config.item.name Category name
20 * @param {string} config.item.value
21 * @param {string} [config.item.sortKey='']
22 * @param {ve.dm.MWCategoryMetaItem} config.item.metaItem
23 * @param {boolean} [config.hidden] Whether the category is hidden or not
24 * @param {boolean} [config.missing] Whether the category's description page is missing
25 * @param {string} [config.redirectTo] The name of the category this category's page redirects to.
26 */
27 ve.ui.MWCategoryItemWidget = function VeUiMWCategoryItemWidget( config ) {
28 // Config initialization
29 config = ve.extendObject( { indicator: 'down' }, config );
30
31 // Parent constructor
32 ve.ui.MWCategoryItemWidget.super.call( this, config );
33
34 // Mixin constructors
35 OO.ui.mixin.DraggableElement.call( this, config );
36
37 // Properties
38 this.name = config.item.name;
39 this.value = config.item.value;
40 this.sortKey = config.item.sortKey || '';
41 this.metaItem = config.item.metaItem;
42 this.isHidden = config.hidden;
43 this.isMissing = config.missing;
44
45 // Initialization
46 this.setLabel( config.redirectTo || this.value );
47 if ( config.redirectTo ) {
48 ve.init.platform.linkCache.styleElement( mw.Title.newFromText(
49 config.redirectTo,
50 mw.config.get( 'wgNamespaceIds' ).category
51 ).getPrefixedText(), this.$label );
52 } else {
53 ve.init.platform.linkCache.styleElement( this.name, this.$label );
54 }
55
56 // Events
57 this.on( 'click', this.onButtonClick.bind( this ) );
58
59 this.$element.addClass( 've-ui-mwCategoryItemWidget' );
60 };
61
62 /* Inheritance */
63
64 OO.inheritClass( ve.ui.MWCategoryItemWidget, OO.ui.ButtonWidget );
65
66 OO.mixinClass( ve.ui.MWCategoryItemWidget, OO.ui.mixin.DraggableElement );
67
68 /* Events */
69
70 /**
71 * @event ve.ui.MWCategoryItemWidget#togglePopupMenu
72 * @param {ve.ui.MWCategoryItemWidget} item Item to load into popup
73 */
74
75 /* Methods */
76
77 /**
78 * Handle button widget click events.
79 *
80 * @fires ve.ui.MWCategoryItemWidget#togglePopupMenu
81 */
82 ve.ui.MWCategoryItemWidget.prototype.onButtonClick = function () {
83 this.emit( 'togglePopupMenu', this );
84 };