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 * Widget base class a widget is a control that has a tooltip and some basic states.
14 * @class tinymce.ui.Widget
15 * @extends tinymce.ui.Control
17 define("tinymce/ui/Widget", [
20 ], function(Control, Tooltip) {
25 var Widget = Control.extend({
27 * Constructs a instance with the specified settings.
30 * @param {Object} settings Name/value object with settings.
31 * @setting {String} tooltip Tooltip text to display when hovering.
32 * @setting {Boolean} autofocus True if the control should be focused when rendered.
33 * @setting {String} text Text to display inside widget.
35 init: function(settings) {
38 self._super(settings);
41 if (settings.tooltip && Widget.tooltips !== false) {
42 self.on('mouseenter mouseleave', function(e) {
43 var tooltip = self.tooltip().moveTo(-0xFFFF);
45 if (e.control == self && e.type == 'mouseenter') {
46 var rel = tooltip.text(settings.tooltip).show().testMoveRel(self.getEl(), ['bc-tc', 'bc-tl', 'bc-tr']);
48 tooltip.toggleClass('tooltip-n', rel == 'bc-tc');
49 tooltip.toggleClass('tooltip-nw', rel == 'bc-tl');
50 tooltip.toggleClass('tooltip-ne', rel == 'bc-tr');
52 tooltip.moveRel(self.getEl(), rel);
59 self.aria('label', settings.tooltip);
63 * Returns the current tooltip instance.
66 * @return {tinymce.ui.Tooltip} Tooltip instance.
72 tooltip = new Tooltip({type: 'tooltip'});
73 tooltip.renderTo(self.getContainerElm());
80 * Sets/gets the active state of the widget.
83 * @param {Boolean} [state] State if the control is active.
84 * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
86 active: function(state) {
87 var self = this, undef;
89 if (state !== undef) {
90 self.aria('pressed', state);
91 self.toggleClass('active', state);
94 return self._super(state);
98 * Sets/gets the disabled state of the widget.
101 * @param {Boolean} [state] State if the control is disabled.
102 * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
104 disabled: function(state) {
105 var self = this, undef;
107 if (state !== undef) {
108 self.aria('disabled', state);
109 self.toggleClass('disabled', state);
112 return self._super(state);
116 * Called after the control has been rendered.
120 postRender: function() {
121 var self = this, settings = self.settings;
123 self._rendered = true;
127 if (!self.parent() && (settings.width || settings.height)) {
128 self.initLayoutRect();
132 if (settings.autofocus) {
133 setTimeout(function() {
140 * Removes the current control from DOM and from UI collections.
143 * @return {tinymce.ui.Control} Current control instance.