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 * Creates a tab panel control.
14 * @-x-less TabPanel.less
15 * @class tinymce.ui.TabPanel
16 * @extends tinymce.ui.Panel
18 * @setting {Number} activeTab Active tab index.
20 define("tinymce/ui/TabPanel", [
23 ], function(Panel, DomUtils) {
37 * Activates the specified tab by index.
40 * @param {Number} idx Index of the tab to activate.
42 activateTab: function(idx) {
43 if (this.activeTabId) {
44 DomUtils.removeClass(this.getEl(this.activeTabId), this.classPrefix + 'active');
47 this.activeTabId = 't' + idx;
49 DomUtils.addClass(this.getEl('t' + idx), this.classPrefix + 'active');
51 if (idx != this.lastIdx) {
52 this.items()[this.lastIdx].hide();
56 this.items()[idx].show().fire('showtab');
61 * Renders the control as a HTML string.
64 * @return {String} HTML representing the control.
66 renderHtml: function() {
67 var self = this, layout = self._layout, tabsHtml = '', prefix = self.classPrefix;
70 layout.preRender(self);
72 self.items().each(function(ctrl, i) {
74 '<div id="' + self._id + '-t' + i + '" class="' + prefix + 'tab" unselectable="on">' +
75 self.encode(ctrl.settings.title) +
81 '<div id="' + self._id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
82 '<div id="' + self._id + '-head" class="' + prefix + 'tabs">' +
85 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">' +
86 layout.renderHtml(self) +
93 * Called after the control has been rendered.
97 postRender: function() {
102 self.settings.activeTab = self.settings.activeTab || 0;
103 self.activateTab(self.settings.activeTab);
105 this.on('click', function(e) {
106 var targetParent = e.target.parentNode;
108 if (e.target.parentNode.id == self._id + '-head') {
109 var i = targetParent.childNodes.length;
112 if (targetParent.childNodes[i] == e.target) {
121 * Initializes the current controls layout rect.
122 * This will be executed by the layout managers to determine the
123 * default minWidth/minHeight etc.
125 * @method initLayoutRect
126 * @return {Object} Layout rect instance.
128 initLayoutRect: function() {
129 var self = this, rect, minW, minH;
132 self.items().each(function(item, i) {
133 minW = Math.max(minW, item.layoutRect().minW);
134 minH = Math.max(minH, item.layoutRect().minH);
135 if (self.settings.activeTab != i) {
140 self.items().each(function(ctrl) {
143 ctrl.settings.w = minW;
144 ctrl.settings.h = minH;
154 var headH = self.getEl('head').offsetHeight;
156 self.settings.minWidth = minW;
157 self.settings.minHeight = minH + headH;
159 rect = self._super();
160 rect.deltaH += self.getEl('head').offsetHeight;
161 rect.innerH = rect.h - rect.deltaH;