mediawiki-extensions-Visual.../modules/ve/ui/toolgroups/ve.ui.MenuToolGroup.js
Trevor Parscal 8dfbc5baa5 Make tools generic and add fancy tool groups
Objectives:

* Got rid of mw prefixing in tools, inspectors and dialogs
* Simplify tool classes so they can be generically used as items in bars, lists and menus
* Add support for a catch-all toolbar group
* Simplify tool registration, leaning on tool classes' static name property
* Move default commands to command registry
* Move default triggers to trigger registry
* Get language tool working in standalone

Change-Id: Ic97a636f9a193374728629931b6702bee1b3416a
2013-09-03 11:27:39 -07:00

60 lines
1.3 KiB
JavaScript

/*!
* VisualEditor UserInterface MenuToolGroup class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* UserInterface bar tool group.
*
* @class
* @abstract
* @extends ve.ui.PopupToolGroup
*
* @constructor
* @param {ve.ui.Toolbar} toolbar
* @param {Object} [config] Config options
*/
ve.ui.MenuToolGroup = function VeUiMenuToolGroup( toolbar, config ) {
// Parent constructor
ve.ui.PopupToolGroup.call( this, toolbar, config );
// Events
this.toolbar.connect( this, { 'updateState': 'onUpdateState' } );
// Initialization
this.$.addClass( 've-ui-menuToolGroup' );
};
/* Inheritance */
ve.inheritClass( ve.ui.MenuToolGroup, ve.ui.PopupToolGroup );
/* Static Properties */
ve.ui.MenuToolGroup.static.showTrigger = true;
/* Methods */
/**
* Handle the toolbar state being updated.
*
* When the state changes, the title of each active item in the menu will be joined together and
* used as a label for the group. The label will be empty if none of the items are active.
*
* @method
*/
ve.ui.MenuToolGroup.prototype.onUpdateState = function () {
var name,
labelTexts = [];
for ( name in this.tools ) {
if ( this.tools[name].isActive() ) {
labelTexts.push( this.tools[name].getLabelText() );
}
}
this.setLabel( labelTexts.join( ', ' ) );
};