mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
8d33a3de0d
* Made method descriptions imperative: "Do this" rather than "Does this" * Changed use of "this object" to "the object" in method documentation * Added missing documentation * Fixed incorrect documentation * Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console) * Normalized use of package names throughout * Normalized class descriptions * Removed incorrect @abstract tags * Added missing @method tags * Lots of other minor cleanup Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Toolbar class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface toolbar.
|
|
*
|
|
* @class
|
|
* @extends ve.EventEmitter
|
|
* @constructor
|
|
* @param {jQuery} $container
|
|
* @param {ve.Surface} surface
|
|
* @param {Array} config
|
|
*/
|
|
ve.ui.Toolbar = function VeUiToolbar( $container, surface, config ) {
|
|
// Parent constructor
|
|
ve.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.surface = surface;
|
|
this.$ = $container;
|
|
this.$groups = $( '<div class="ve-ui-toolbarGroups"></div>' );
|
|
this.config = config || {};
|
|
|
|
// Events
|
|
this.surface.getModel().on( 'contextChange', ve.bind( this.onContextChange, this ) );
|
|
|
|
// Initialization
|
|
this.$.prepend( this.$groups );
|
|
this.setup();
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.Toolbar, ve.EventEmitter );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Gets the surface the toolbar controls.
|
|
*
|
|
* @method
|
|
* @returns {ve.Surface} Surface being controlled
|
|
*/
|
|
ve.ui.Toolbar.prototype.getSurface = function () {
|
|
return this.surface;
|
|
};
|
|
|
|
/**
|
|
* Handle context changes on the surface.
|
|
*
|
|
* @method
|
|
* @emits "updateState" (nodes, full, partial)
|
|
* @emits "clearState"
|
|
*/
|
|
ve.ui.Toolbar.prototype.onContextChange = function () {
|
|
var i, len, leafNodes,
|
|
fragment = this.surface.getModel().getFragment(),
|
|
nodes = [];
|
|
|
|
leafNodes = fragment.getLeafNodes();
|
|
for ( i = 0, len = leafNodes.length; i < len; i++ ) {
|
|
nodes.push( leafNodes[i].node );
|
|
}
|
|
this.emit( 'updateState', nodes, fragment.getAnnotations(), fragment.getAnnotations( true ) );
|
|
};
|
|
|
|
/**
|
|
* Initialize all tools and groups.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Toolbar.prototype.setup = function () {
|
|
var i, j, group, $group, tool;
|
|
for ( i = 0; i < this.config.length; i++ ) {
|
|
group = this.config[i];
|
|
// Create group
|
|
$group = $( '<div class="ve-ui-toolbarGroup"></div>' )
|
|
.addClass( 've-ui-toolbarGroup-' + group.name );
|
|
if ( group.label ) {
|
|
$group.append( $( '<div class="ve-ui-toolbarLabel"></div>' ).html( group.label ) );
|
|
}
|
|
// Add tools
|
|
for ( j = 0; j < group.items.length; j++ ) {
|
|
tool = ve.ui.toolFactory.create( group.items[j], this );
|
|
if ( !tool ) {
|
|
throw new Error( 'Unknown tool: ' + group.items[j] );
|
|
}
|
|
$group.append( tool.$ );
|
|
}
|
|
// Append group
|
|
this.$groups.append( $group );
|
|
}
|
|
};
|