2013-04-29 21:01:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWCategoryItemWidget class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @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
|
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
|
2013-04-29 21:01:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWCategoryItemWidget = function VeUiMWCategoryItemWidget( config ) {
|
|
|
|
// Config intialization
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
2013-10-09 20:09:59 +00:00
|
|
|
OO.ui.Widget.call( this, config );
|
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;
|
|
|
|
this.menuOpen = false;
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$label = this.$( '<span>' );
|
|
|
|
this.$arrow = this.$( '<div>' );
|
|
|
|
this.$categoryItem = this.$( '<div>' );
|
2013-04-29 21:01:56 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.$categoryItem.on( {
|
2013-05-06 11:34:32 +00:00
|
|
|
'click': ve.bind( this.onClick, this ),
|
2013-04-29 21:01:56 +00:00
|
|
|
'mounsedown': ve.bind( this.onMouseDown, this )
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$label.text( this.value );
|
2013-10-09 20:09:59 +00:00
|
|
|
this.$arrow.addClass( 've-ui-mwCategoryItemControl oo-ui-icon-down' );
|
2013-04-29 21:01:56 +00:00
|
|
|
this.$categoryItem
|
2013-07-25 12:34:25 +00:00
|
|
|
.addClass( 've-ui-mwCategoryItemButton' )
|
2013-11-01 19:45:59 +00:00
|
|
|
.append( this.$label, this.$arrow, this.$( '<div>' ).css( 'clear', 'both' ) );
|
|
|
|
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
|
|
|
|
|
|
|
/* 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 );
|
|
|
|
};
|