mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWCategoryItemWidget.js
Moriel Schottlender d1ff9e125e Make sure category widget methods call parent class methods
Mouseover and click events in the category widget should also call
their parent method.

Depends on the ooui change Ie576f4422

Change-Id: I73b574b28a5a60e4f046f3008407dbf4b1323b58
2015-02-13 18:29:20 +00:00

106 lines
2.6 KiB
JavaScript

/*!
* VisualEditor UserInterface MWCategoryItemWidget class.
*
* @copyright 2011-2015 VisualEditor Team and others; 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.DraggableElement
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {Object} [item] Category item
* @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
OO.ui.ButtonWidget.call( this, config );
// Mixin constructors
OO.ui.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;
// Events
this.$button.on( {
mousedown: this.onMouseDown.bind( this )
} );
// 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 );
}
this.$element.addClass( 've-ui-mwCategoryItemWidget' );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWCategoryItemWidget, OO.ui.ButtonWidget );
OO.mixinClass( ve.ui.MWCategoryItemWidget, OO.ui.DraggableElement );
/* Events */
/**
* @event savePopupState
*/
/**
* @event togglePopupMenu
* @param {ve.ui.MWCategoryItemWidget} item Item to load into popup
*/
/* Methods */
/**
* Handle mouse down events.
*
* @method
* @param {jQuery.Event} e Mouse down event
* @fires savePopupState on mousedown.
*/
ve.ui.MWCategoryItemWidget.prototype.onMouseDown = function () {
this.emit( 'savePopupState' );
// Parent method
return ve.ui.MWCategoryItemWidget.super.prototype.onMouseDown.apply( this, arguments );
};
/**
* Handle mouse click events.
*
* @method
* @param {jQuery.Event} e Mouse click event
* @fires togglePopupMenu on mousedown.
*/
ve.ui.MWCategoryItemWidget.prototype.onClick = function () {
this.emit( 'togglePopupMenu', this );
// Parent method
return ve.ui.MWCategoryItemWidget.super.prototype.onClick.apply( this, arguments );
};