4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 // Shorten class names
13 var DOM = tinymce.DOM, is = tinymce.is;
16 * This class is the base class for all controls like buttons, toolbars, containers. This class should not
17 * be instantiated directly other controls should inherit from this one.
19 * @class tinymce.ui.Control
21 tinymce.create('tinymce.ui.Control', {
23 * Constructs a new control instance.
27 * @param {String} id Control id.
28 * @param {Object} s Optional name/value settings object.
30 Control : function(id, s, editor) {
32 this.settings = s = s || {};
33 this.rendered = false;
34 this.onRender = new tinymce.util.Dispatcher(this);
35 this.classPrefix = '';
36 this.scope = s.scope || this;
42 setAriaProperty : function(property, value) {
43 var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
45 DOM.setAttrib(element, 'aria-' + property, !!value);
50 DOM.get(this.id).focus();
54 * Sets the disabled state for the control. This will add CSS classes to the
55 * element that contains the control. So that it can be disabled visually.
58 * @param {Boolean} s Boolean state if the control should be disabled or not.
60 setDisabled : function(s) {
61 if (s != this.disabled) {
62 this.setAriaProperty('disabled', s);
64 this.setState('Disabled', s);
65 this.setState('Enabled', !s);
71 * Returns true/false if the control is disabled or not. This is a method since you can then
72 * choose to check some class or some internal bool state in subclasses.
75 * @return {Boolean} true/false if the control is disabled or not.
77 isDisabled : function() {
82 * Sets the activated state for the control. This will add CSS classes to the
83 * element that contains the control. So that it can be activated visually.
86 * @param {Boolean} s Boolean state if the control should be activated or not.
88 setActive : function(s) {
89 if (s != this.active) {
90 this.setState('Active', s);
92 this.setAriaProperty('pressed', s);
97 * Returns true/false if the control is disabled or not. This is a method since you can then
98 * choose to check some class or some internal bool state in subclasses.
101 * @return {Boolean} true/false if the control is disabled or not.
103 isActive : function() {
108 * Sets the specified class state for the control.
111 * @param {String} c Class name to add/remove depending on state.
112 * @param {Boolean} s True/false state if the class should be removed or added.
114 setState : function(c, s) {
115 var n = DOM.get(this.id);
117 c = this.classPrefix + c;
122 DOM.removeClass(n, c);
126 * Returns true/false if the control has been rendered or not.
129 * @return {Boolean} State if the control has been rendered or not.
131 isRendered : function() {
132 return this.rendered;
136 * Renders the control as a HTML string. This method is much faster than using the DOM and when
137 * creating a whole toolbar with buttons it does make a lot of difference.
140 * @return {String} HTML for the button control element.
142 renderHTML : function() {
146 * Renders the control to the specified container element.
149 * @param {Element} n HTML DOM element to add control to.
151 renderTo : function(n) {
152 DOM.setHTML(n, this.renderHTML());
156 * Post render event. This will be executed after the control has been rendered and can be used to
157 * set states, add events to the control etc. It's recommended for subclasses of the control to call this method by using this.parent().
161 postRender : function() {
164 // Set pending states
165 if (is(t.disabled)) {
179 * Removes the control. This means it will be removed from the DOM and any
180 * events tied to it will also be removed.
184 remove : function() {
190 * Destroys the control will free any memory by removing event listeners etc.
194 destroy : function() {
195 tinymce.dom.Event.clear(this.id);