2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryItemWidget class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 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
|
2013-10-09 20:09:59 +00:00
|
|
|
* @extends OO.ui.Widget
|
2014-09-04 00:18:41 +00:00
|
|
|
* @mixins OO.ui.IndicatorElement
|
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-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 ) {
|
|
|
|
// Config intialization
|
2014-08-22 20:50:48 +00:00
|
|
|
config = ve.extendObject( { indicator: 'down' }, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Widget.call( this, config );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2014-02-14 23:12:47 +00:00
|
|
|
// Mixin constructors
|
2014-09-04 00:18:41 +00:00
|
|
|
OO.ui.IndicatorElement.call( this, config );
|
2014-02-14 23:12:47 +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;
|
2013-04-29 21:01:56 +00:00
|
|
|
this.menuOpen = false;
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$label = this.$( '<span>' );
|
|
|
|
this.$categoryItem = this.$( '<div>' );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.$categoryItem.on( {
|
2014-08-22 20:50:48 +00:00
|
|
|
click: this.onClick.bind( this ),
|
|
|
|
mousedown: this.onMouseDown.bind( this )
|
2013-04-29 21:01:56 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
2014-02-14 23:12:47 +00:00
|
|
|
this.$label
|
|
|
|
.addClass( 've-ui-mwCategoryItemWidget-label' )
|
2014-03-11 19:02:16 +00:00
|
|
|
.text( config.redirectTo || this.value );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$categoryItem
|
2014-02-14 23:12:47 +00:00
|
|
|
.addClass( 've-ui-mwCategoryItemWidget-button' )
|
|
|
|
.append( this.$label, this.$indicator );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element
|
2013-07-25 12:34:25 +00:00
|
|
|
.addClass( 've-ui-mwCategoryItemWidget' )
|
2013-04-29 21:01:56 +00:00
|
|
|
.append( this.$categoryItem );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.inheritClass( ve.ui.MWCategoryItemWidget, OO.ui.Widget );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
2014-09-04 00:18:41 +00:00
|
|
|
OO.mixinClass( ve.ui.MWCategoryItemWidget, OO.ui.IndicatorElement );
|
2014-02-14 23:12:47 +00:00
|
|
|
|
2013-04-29 21:01:56 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event savePopupState
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event togglePopupMenu
|
|
|
|
* @param {ve.ui.MWCategoryItemWidget} item Item to load into popup
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2013-06-10 22:22:30 +00:00
|
|
|
* Handle mouse down events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse down event
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires savePopupState on mousedown.
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryItemWidget.prototype.onMouseDown = function () {
|
|
|
|
this.emit( 'savePopupState' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-10 22:22:30 +00:00
|
|
|
* Handle mouse click events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires togglePopupMenu on mousedown.
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryItemWidget.prototype.onClick = function () {
|
|
|
|
this.emit( 'togglePopupMenu', this );
|
|
|
|
};
|