]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/ui/Widget.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / ui / Widget.js
1 /**
2  * Widget.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  * Widget base class a widget is a control that has a tooltip and some basic states.
13  *
14  * @class tinymce.ui.Widget
15  * @extends tinymce.ui.Control
16  */
17 define("tinymce/ui/Widget", [
18         "tinymce/ui/Control",
19         "tinymce/ui/Tooltip"
20 ], function(Control, Tooltip) {
21         "use strict";
22
23         var tooltip;
24
25         var Widget = Control.extend({
26                 /**
27                  * Constructs a instance with the specified settings.
28                  *
29                  * @constructor
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.
34                  */
35                 init: function(settings) {
36                         var self = this;
37
38                         self._super(settings);
39                         self.canFocus = true;
40
41                         if (settings.tooltip && Widget.tooltips !== false) {
42                                 self.on('mouseenter mouseleave', function(e) {
43                                         var tooltip = self.tooltip().moveTo(-0xFFFF);
44
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']);
47
48                                                 tooltip.toggleClass('tooltip-n', rel == 'bc-tc');
49                                                 tooltip.toggleClass('tooltip-nw', rel == 'bc-tl');
50                                                 tooltip.toggleClass('tooltip-ne', rel == 'bc-tr');
51
52                                                 tooltip.moveRel(self.getEl(), rel);
53                                         } else {
54                                                 tooltip.hide();
55                                         }
56                                 });
57                         }
58
59                         self.aria('label', settings.tooltip);
60                 },
61
62                 /**
63                  * Returns the current tooltip instance.
64                  *
65                  * @method tooltip
66                  * @return {tinymce.ui.Tooltip} Tooltip instance.
67                  */
68                 tooltip: function() {
69                         var self = this;
70
71                         if (!tooltip) {
72                                 tooltip = new Tooltip({type: 'tooltip'});
73                                 tooltip.renderTo(self.getContainerElm());
74                         }
75
76                         return tooltip;
77                 },
78
79                 /**
80                  * Sets/gets the active state of the widget.
81                  *
82                  * @method active
83                  * @param {Boolean} [state] State if the control is active.
84                  * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
85                  */
86                 active: function(state) {
87                         var self = this, undef;
88
89                         if (state !== undef) {
90                                 self.aria('pressed', state);
91                                 self.toggleClass('active', state);
92                         }
93
94                         return self._super(state);
95                 },
96
97                 /**
98                  * Sets/gets the disabled state of the widget.
99                  *
100                  * @method disabled
101                  * @param {Boolean} [state] State if the control is disabled.
102                  * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
103                  */
104                 disabled: function(state) {
105                         var self = this, undef;
106
107                         if (state !== undef) {
108                                 self.aria('disabled', state);
109                                 self.toggleClass('disabled', state);
110                         }
111
112                         return self._super(state);
113                 },
114
115                 /**
116                  * Called after the control has been rendered.
117                  *
118                  * @method postRender
119                  */
120                 postRender: function() {
121                         var self = this, settings = self.settings;
122
123                         self._rendered = true;
124
125                         self._super();
126
127                         if (!self.parent() && (settings.width || settings.height)) {
128                                 self.initLayoutRect();
129                                 self.repaint();
130                         }
131
132                         if (settings.autofocus) {
133                                 setTimeout(function() {
134                                         self.focus();
135                                 }, 0);
136                         }
137                 },
138
139                 /**
140                  * Removes the current control from DOM and from UI collections.
141                  *
142                  * @method remove
143                  * @return {tinymce.ui.Control} Current control instance.
144                  */
145                 remove: function() {
146                         this._super();
147
148                         if (tooltip) {
149                                 tooltip.remove();
150                                 tooltip = null;
151                         }
152                 }
153         });
154
155         return Widget;
156 });