4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
12 * This class creates a label element. A label is a simple text control
13 * that can be bound to other controls.
16 * @class tinymce.ui.Label
17 * @extends tinymce.ui.Widget
19 define("tinymce/ui/Label", [
24 return Widget.extend({
26 * Constructs a instance with the specified settings.
29 * @param {Object} settings Name/value object with settings.
30 * @param {Boolean} multiline Multiline label.
32 init: function(settings) {
35 self._super(settings);
36 self.addClass('widget');
37 self.addClass('label');
38 self.canFocus = false;
40 if (settings.multiline) {
41 self.addClass('autoscroll');
44 if (settings.strong) {
45 self.addClass('strong');
50 * Initializes the current controls layout rect.
51 * This will be executed by the layout managers to determine the
52 * default minWidth/minHeight etc.
54 * @method initLayoutRect
55 * @return {Object} Layout rect instance.
57 initLayoutRect: function() {
58 var self = this, layoutRect = self._super();
60 if (self.settings.multiline) {
61 // Check if the text fits within maxW if not then try word wrapping it
62 if (self.getEl().offsetWidth > layoutRect.maxW) {
63 layoutRect.minW = layoutRect.maxW;
64 self.addClass('multiline');
67 self.getEl().style.width = layoutRect.minW + 'px';
68 layoutRect.startMinH = layoutRect.h = layoutRect.minH = Math.min(layoutRect.maxH, self.getEl().offsetHeight);
75 * Sets/gets the disabled state on the control.
78 * @param {Boolean} state Value to set to control.
79 * @return {Boolean/tinymce.ui.Label} Current control on a set operation or current state on a get.
81 disabled: function(state) {
82 var self = this, undef;
84 if (state !== undef) {
85 self.toggleClass('label-disabled', state);
88 self.getEl()[0].className = self.classes();
92 return self._super(state);
96 * Repaints the control after a layout operation.
100 repaint: function() {
103 if (!self.settings.multiline) {
104 self.getEl().style.lineHeight = self.layoutRect().h + 'px';
107 return self._super();
111 * Sets/gets the current label text.
114 * @param {String} [text] New label text.
115 * @return {String|tinymce.ui.Label} Current text or current label instance.
117 text: function(text) {
120 if (self._rendered && text) {
121 this.innerHtml(self.encode(text));
124 return self._super(text);
128 * Renders the control as a HTML string.
131 * @return {String} HTML representing the control.
133 renderHtml: function() {
134 var self = this, forId = self.settings.forId;
137 '<label id="' + self._id + '" class="' + self.classes() + '"' + (forId ? ' for="' + forId : '') + '">' +
138 self.encode(self._text) +