mediawiki-extensions-Visual.../modules/ve/ui/elements/ve.ui.LabeledElement.js
Trevor Parscal 6ec34a3dee Toolbar action widgetization and UI refactoring
Objectives:

* Use widgets to render toolbar actions
* Remove labels next to help notices and edit notices buttons
* Add a close button to the help notices and edit notices

Overview:

* ve.ui.ButtonWidget is now abstract, use ve.ui.PushButtonWidget instead
* ve.ui.IconButtonWidget now inherits from ve.ui.ButtonWidget
* ve.ui.PopupWidget's display method no longer takes x and y arguments
* Fixup naming issues in MWCategoryPopupWidget
* Fixup naming issues with some ve-init-mw CSS classes
* Rename ve-mw/ui/styles/ve.ui.Widget.css to ve.ui.MWWidget.css
* Change uses of "callout" to "tail"
* Add hyperlink functionality to buttons
* Make buttons accessible through focusing, but make unfocusable by
  clicking
* Add head option to popup for rendering a title and close button

Bug: 52386
Change-Id: Iea2c8df1be64d40f9c039873d89ee540cc56e687
2013-10-04 16:26:13 -07:00

89 lines
1.8 KiB
JavaScript

/*!
* VisualEditor UserInterface LabeledElement class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Labeled element.
*
* @class
* @abstract
*
* @constructor
* @param {jQuery} $label Label element
* @param {Object} [config] Configuration options
* @cfg {jQuery|string} [label=''] Label text
*/
ve.ui.LabeledElement = function VeUiLabeledElement( $label, config ) {
// Config intialization
config = config || {};
// Properties
this.$label = $label;
this.label = null;
// Initialization
this.$label.addClass( 've-ui-labeledElement-label' );
this.setLabel( config.label );
};
/* Static Properties */
ve.ui.LabeledElement.static = {};
/*
* HTML to use when label is empty.
*
* @static
* @property {string}
* @inheritable
*/
ve.ui.LabeledElement.static.emptyHtml = '&nbsp';
/* Methods */
/**
* Set the label.
*
* @method
* @param {jQuery|string} [value] jQuery HTML node selection or string text value to use for label
* @chainable
*/
ve.ui.LabeledElement.prototype.setLabel = function ( value ) {
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.html( this.constructor.static.emptyLabel );
this.label = null;
}
return this;
};
/**
* Get label value as plain text.
*
* @return {string} Label text
*/
ve.ui.LabeledElement.prototype.getLabelText = function () {
return this.$label.text();
};
/**
* Fit the label.
*
* @method
* @chainable
*/
ve.ui.LabeledElement.prototype.fitLabel = function () {
if ( this.$label.autoEllipsis ) {
this.$label.autoEllipsis( { 'hasSpan': false, 'tooltip': true } );
}
return this;
};