X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/ee06f37b0f6f6d94cd05a6ffae556660f7c4a2bc..c930e9176a5a85509c5b0230e2bff5c22a591432:/examples/ux/GroupTab.js diff --git a/examples/ux/GroupTab.js b/examples/ux/GroupTab.js new file mode 100644 index 00000000..1fc5704f --- /dev/null +++ b/examples/ux/GroupTab.js @@ -0,0 +1,266 @@ +/*! + * Ext JS Library 3.0.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ux.GroupTab = Ext.extend(Ext.Container, { + mainItem: 0, + + expanded: true, + + deferredRender: true, + + activeTab: null, + + idDelimiter: '__', + + headerAsText: false, + + frame: false, + + hideBorders: true, + + initComponent: function(config){ + Ext.apply(this, config); + this.frame = false; + + Ext.ux.GroupTab.superclass.initComponent.call(this); + + this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange'); + + this.setLayout(new Ext.layout.CardLayout({ + deferredRender: this.deferredRender + })); + + if (!this.stack) { + this.stack = Ext.TabPanel.AccessStack(); + } + + this.initItems(); + + this.on('beforerender', function(){ + this.groupEl = this.ownerCt.getGroupEl(this); + }, this); + + this.on('add', this.onAdd, this, { + target: this + }); + this.on('remove', this.onRemove, this, { + target: this + }); + + if (this.mainItem !== undefined) { + var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem); + delete this.mainItem; + this.setMainItem(item); + } + }, + + /** + * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which + * can return false to cancel the tab change. + * @param {String/Panel} tab The id or tab Panel to activate + */ + setActiveTab : function(item){ + item = this.getComponent(item); + if(!item || this.fireEvent('beforetabchange', this, item, this.activeTab) === false){ + return; + } + if(!this.rendered){ + this.activeTab = item; + return; + } + if(this.activeTab != item){ + if(this.activeTab && this.activeTab != this.mainItem){ + var oldEl = this.getTabEl(this.activeTab); + if(oldEl){ + Ext.fly(oldEl).removeClass('x-grouptabs-strip-active'); + } + this.activeTab.fireEvent('deactivate', this.activeTab); + } + var el = this.getTabEl(item); + Ext.fly(el).addClass('x-grouptabs-strip-active'); + this.activeTab = item; + this.stack.add(item); + + this.layout.setActiveItem(item); + if(this.layoutOnTabChange && item.doLayout){ + item.doLayout(); + } + if(this.scrolling){ + this.scrollToTab(item, this.animScroll); + } + + item.fireEvent('activate', item); + this.fireEvent('tabchange', this, item); + } + }, + + getTabEl: function(item){ + if (item == this.mainItem) { + return this.groupEl; + } + return Ext.TabPanel.prototype.getTabEl.call(this, item); + }, + + onRender: function(ct, position){ + Ext.ux.GroupTab.superclass.onRender.call(this, ct, position); + + this.strip = Ext.fly(this.groupEl).createChild({ + tag: 'ul', + cls: 'x-grouptabs-sub' + }); + + this.tooltip = new Ext.ToolTip({ + target: this.groupEl, + delegate: 'a.x-grouptabs-text', + trackMouse: true, + renderTo: document.body, + listeners: { + beforeshow: function(tip) { + var item = (tip.triggerElement.parentNode === this.mainItem.tabEl) + ? this.mainItem + : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]); + + if(!item.tabTip) { + return false; + } + tip.body.dom.innerHTML = item.tabTip; + }, + scope: this + } + }); + + if (!this.itemTpl) { + var tt = new Ext.Template('