mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-02 01:46:47 +00:00
6774cd74f3
Changes: * Pass toolGroup into tools instead of toolbar * Split tool labels into title and accel * Make toolbars provide accelerator labels * Remove getLabelText method since it's not being used and is likely not useful * Make tools update their own labels * Only show accelerator information for triggers that are active in the surface * Make surface toolbars listen to commands being added and update tools accordingly * Introduce command object to encapsulate command info Change-Id: Ieac4bfa63b63ac0a9dee154af3007a33b4d447ff
76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
/*!
|
|
* ObjectOriented UserInterface LabeledElement class.
|
|
*
|
|
* @copyright 2011-2013 OOJS Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Element containing a label.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
*
|
|
* @constructor
|
|
* @param {jQuery} $label Label node, assigned to #$label
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {jQuery|string} [label=''] Label text
|
|
*/
|
|
OO.ui.LabeledElement = function OoUiLabeledElement( $label, config ) {
|
|
// Config intialization
|
|
config = config || {};
|
|
|
|
// Properties
|
|
this.$label = $label;
|
|
this.label = null;
|
|
|
|
// Initialization
|
|
this.$label.addClass( 'oo-ui-labeledElement-label' );
|
|
this.setLabel( config.label );
|
|
};
|
|
|
|
/* Static Properties */
|
|
|
|
OO.ui.LabeledElement.static = {};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Set the label.
|
|
*
|
|
* @method
|
|
* @param {jQuery|string} [value] jQuery HTML node selection or string text value to use for label
|
|
* @chainable
|
|
*/
|
|
OO.ui.LabeledElement.prototype.setLabel = function ( value ) {
|
|
var empty = false;
|
|
|
|
if ( typeof value === 'string' && value.trim() ) {
|
|
this.$label.text( value );
|
|
this.label = value;
|
|
} else if ( value instanceof jQuery ) {
|
|
this.$label.empty().append( value );
|
|
this.label = value;
|
|
} else {
|
|
this.$label.empty();
|
|
this.label = null;
|
|
empty = true;
|
|
}
|
|
this.$label[empty ? 'addClass' : 'removeClass']( 'oo-ui-labeledElement-empty' );
|
|
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Fit the label.
|
|
*
|
|
* @method
|
|
* @chainable
|
|
*/
|
|
OO.ui.LabeledElement.prototype.fitLabel = function () {
|
|
if ( this.$label.autoEllipsis ) {
|
|
this.$label.autoEllipsis( { 'hasSpan': false, 'tooltip': true } );
|
|
}
|
|
return this;
|
|
};
|