3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
17 Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
20 alternateColor: false,
22 alternateCls: 'x-grouptabs-panel-alt',
24 defaultType: 'grouptab',
26 deferredRender: false,
30 initComponent: function(){
31 Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
37 this.elements = 'body,header';
38 this.stripTarget = 'header';
40 this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
42 this.addClass('x-grouptabs-panel');
44 if (this.tabStyle && this.tabStyle != '') {
45 this.addClass('x-grouptabs-panel-' + this.tabStyle);
48 if (this.alternateColor) {
49 this.addClass(this.alternateCls);
52 this.on('beforeadd', function(gtp, item, index){
53 this.initGroup(item, index);
55 this.items.each(function(item){
56 item.on('tabchange',function(item){
57 this.fireEvent('tabchange', this, item.activeTab);
62 initEvents : function() {
63 this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
66 onRender: function(ct, position){
67 Ext.TabPanel.superclass.onRender.call(this, ct, position);
69 var pos = this.tabPosition == 'top' ? 'header' : 'footer';
70 this[pos].addClass('x-tab-panel-'+pos+'-plain');
73 var st = this[this.stripTarget];
75 this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
76 tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
78 var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
79 this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
81 this.header.addClass('x-grouptabs-panel-header');
82 this.bwrap.addClass('x-grouptabs-bwrap');
83 this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
86 var tt = new Ext.Template(
87 '<li class="{cls}" id="{id}">',
88 '<a class="x-grouptabs-expand" onclick="return false;"></a>',
89 '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
90 '<span>{text}</span></a>',
93 tt.disableFormats = true;
95 Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
97 this.items.each(this.initGroup, this);
100 afterRender: function(){
101 Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
103 this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
107 this.addClass('x-tab-panel-' + this.tabPosition);
108 this.header.setWidth(this.tabWidth);
110 if (this.activeGroup !== undefined) {
111 var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
112 delete this.activeGroup;
113 this.setActiveGroup(group);
114 group.setActiveTab(group.getMainItem());
118 getGroupEl : Ext.TabPanel.prototype.getTabEl,
121 findTargets: function(e){
123 itemEl = e.getTarget('li', this.strip);
125 item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
135 expand: e.getTarget('.x-grouptabs-expand', this.strip),
136 isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
143 onStripMouseDown: function(e){
148 var t = this.findTargets(e);
150 this.toggleGroup(t.el);
154 t.item.setActiveTab(t.item.getMainItem());
157 t.item.ownerCt.setActiveTab(t.item);
162 expandGroup: function(groupEl){
163 if(groupEl.isXType) {
164 groupEl = this.getGroupEl(groupEl);
166 Ext.fly(groupEl).addClass('x-grouptabs-expanded');
170 toggleGroup: function(groupEl){
171 if(groupEl.isXType) {
172 groupEl = this.getGroupEl(groupEl);
174 Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
178 collapseGroup: function(groupEl){
179 if(groupEl.isXType) {
180 groupEl = this.getGroupEl(groupEl);
182 Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
186 syncTabJoint: function(groupEl){
187 if (!this.tabJoint) {
191 groupEl = groupEl || this.getGroupEl(this.activeGroup);
193 this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
195 var y = Ext.isGecko2 ? 0 : 1;
196 if (this.tabPosition == 'left'){
197 this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
200 this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
204 this.tabJoint.hide();
208 getActiveTab : function() {
209 if(!this.activeGroup) return null;
210 return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
213 onResize: function(){
214 Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
218 createCorner: function(el, pos){
219 return Ext.fly(el).createChild({
220 cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
224 initGroup: function(group, index){
225 var before = this.strip.dom.childNodes[index],
226 p = this.getTemplateArgs(group);
228 p.cls += ' x-tab-first';
230 p.cls += ' x-grouptabs-main';
231 p.text = group.getMainItem().title;
233 var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
234 tl = this.createCorner(el, 'top-' + this.tabPosition),
235 bl = this.createCorner(el, 'bottom-' + this.tabPosition);
238 if (group.expanded) {
239 this.expandGroup(el);
242 if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
244 bl.setBottom('-5px');
251 changemainitem: this.onGroupChangeMainItem,
252 beforetabchange: this.onGroupBeforeTabChange
256 setActiveGroup : function(group) {
257 group = this.getComponent(group);
262 this.activeGroup = group;
265 if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
266 if(this.activeGroup){
267 this.activeGroup.activeTab = null;
268 var oldEl = this.getGroupEl(this.activeGroup);
270 Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
274 var groupEl = this.getGroupEl(group);
275 Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
277 this.activeGroup = group;
278 this.stack.add(group);
280 this.layout.setActiveItem(group);
281 this.syncTabJoint(groupEl);
283 this.fireEvent('groupchange', this, group);
289 onGroupBeforeTabChange: function(group, newTab, oldTab){
290 if(group !== this.activeGroup || newTab !== oldTab) {
291 this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
293 this.expandGroup(this.getGroupEl(group));
294 if(group !== this.activeGroup) {
295 return this.setActiveGroup(group);
299 getFrameHeight: function(){
300 var h = this.el.getFrameWidth('tb');
301 h += (this.tbar ? this.tbar.getHeight() : 0) +
302 (this.bbar ? this.bbar.getHeight() : 0);
307 adjustBodyWidth: function(w){
308 return w - this.tabWidth;
312 Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);