src/pyams_skin/resources/js/ext/tinymce/dev/classes/ui/Label.js
changeset 69 a361355b55c7
equal deleted inserted replaced
68:fd8fb93e1b6a 69:a361355b55c7
       
     1 /**
       
     2  * Label.js
       
     3  *
       
     4  * Copyright, Moxiecode Systems AB
       
     5  * Released under LGPL License.
       
     6  *
       
     7  * License: http://www.tinymce.com/license
       
     8  * Contributing: http://www.tinymce.com/contributing
       
     9  */
       
    10 
       
    11 /**
       
    12  * This class creates a label element. A label is a simple text control
       
    13  * that can be bound to other controls.
       
    14  *
       
    15  * @-x-less Label.less
       
    16  * @class tinymce.ui.Label
       
    17  * @extends tinymce.ui.Widget
       
    18  */
       
    19 define("tinymce/ui/Label", [
       
    20 	"tinymce/ui/Widget",
       
    21 	"tinymce/ui/DomUtils"
       
    22 ], function(Widget, DomUtils) {
       
    23 	"use strict";
       
    24 
       
    25 	return Widget.extend({
       
    26 		/**
       
    27 		 * Constructs a instance with the specified settings.
       
    28 		 *
       
    29 		 * @constructor
       
    30 		 * @param {Object} settings Name/value object with settings.
       
    31 		 * @param {Boolean} multiline Multiline label.
       
    32 		 */
       
    33 		init: function(settings) {
       
    34 			var self = this;
       
    35 
       
    36 			self._super(settings);
       
    37 			self.addClass('widget');
       
    38 			self.addClass('label');
       
    39 			self.canFocus = false;
       
    40 
       
    41 			if (settings.multiline) {
       
    42 				self.addClass('autoscroll');
       
    43 			}
       
    44 
       
    45 			if (settings.strong) {
       
    46 				self.addClass('strong');
       
    47 			}
       
    48 		},
       
    49 
       
    50 		/**
       
    51 		 * Initializes the current controls layout rect.
       
    52 		 * This will be executed by the layout managers to determine the
       
    53 		 * default minWidth/minHeight etc.
       
    54 		 *
       
    55 		 * @method initLayoutRect
       
    56 		 * @return {Object} Layout rect instance.
       
    57 		 */
       
    58 		initLayoutRect: function() {
       
    59 			var self = this, layoutRect = self._super();
       
    60 
       
    61 			if (self.settings.multiline) {
       
    62 				var size = DomUtils.getSize(self.getEl());
       
    63 
       
    64 				// Check if the text fits within maxW if not then try word wrapping it
       
    65 				if (size.width > layoutRect.maxW) {
       
    66 					layoutRect.minW = layoutRect.maxW;
       
    67 					self.addClass('multiline');
       
    68 				}
       
    69 
       
    70 				self.getEl().style.width = layoutRect.minW + 'px';
       
    71 				layoutRect.startMinH = layoutRect.h = layoutRect.minH = Math.min(layoutRect.maxH, DomUtils.getSize(self.getEl()).height);
       
    72 			}
       
    73 
       
    74 			return layoutRect;
       
    75 		},
       
    76 
       
    77 		/**
       
    78 		 * Repaints the control after a layout operation.
       
    79 		 *
       
    80 		 * @method repaint
       
    81 		 */
       
    82 		repaint: function() {
       
    83 			var self = this;
       
    84 
       
    85 			if (!self.settings.multiline) {
       
    86 				self.getEl().style.lineHeight = self.layoutRect().h + 'px';
       
    87 			}
       
    88 
       
    89 			return self._super();
       
    90 		},
       
    91 
       
    92 		/**
       
    93 		 * Sets/gets the current label text.
       
    94 		 *
       
    95 		 * @method text
       
    96 		 * @param {String} [text] New label text.
       
    97 		 * @return {String|tinymce.ui.Label} Current text or current label instance.
       
    98 		 */
       
    99 		text: function(text) {
       
   100 			var self = this;
       
   101 
       
   102 			if (self._rendered && text) {
       
   103 				this.innerHtml(self.encode(text));
       
   104 			}
       
   105 
       
   106 			return self._super(text);
       
   107 		},
       
   108 
       
   109 		/**
       
   110 		 * Renders the control as a HTML string.
       
   111 		 *
       
   112 		 * @method renderHtml
       
   113 		 * @return {String} HTML representing the control.
       
   114 		 */
       
   115 		renderHtml: function() {
       
   116 			var self = this, forId = self.settings.forId;
       
   117 
       
   118 			return (
       
   119 				'<label id="' + self._id + '" class="' + self.classes() + '"' + (forId ? ' for="' + forId + '"' : '') + '>' +
       
   120 					self.encode(self._text) +
       
   121 				'</label>'
       
   122 			);
       
   123 		}
       
   124 	});
       
   125 });