9 * @class Roo.bootstrap.TabGroup
10 * @extends Roo.bootstrap.Column
11 * Bootstrap Column class
12 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
13 * @cfg {Boolean} carousel true to make the group behave like a carousel
14 * @cfg {Number} bullets show the panel pointer.. default 0
15 * @cfg {Boolena} autoslide (true|false) auto slide .. default false
16 * @cfg {Number} timer auto slide timer .. default 0 millisecond
19 * Create a new TabGroup
20 * @param {Object} config The config object
23 Roo.bootstrap.TabGroup = function(config){
24 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
26 this.navId = Roo.id();
29 Roo.bootstrap.TabGroup.register(this);
33 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
42 getAutoCreate : function()
44 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
46 cfg.cls += ' tab-content';
48 Roo.log('get auto create...............');
50 if (this.carousel && !Roo.isTouch) {
51 cfg.cls += ' carousel slide';
54 cls : 'carousel-inner'
60 cls : 'carousel-bullets',
65 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
68 for (var i = 0; i < this.bullets; i++){
70 cls : 'bullet bullet-' + i
78 cfg.cn[0].cn = bullets;
85 initEvents: function()
87 Roo.log('-------- init events on tab group ---------');
91 if(this.bullets > 0 && !Roo.isTouch){
93 for (var i = 0; i < this.bullets; i++){
94 var bullet = this.el.select('.bullet-' + i, true).first();
100 bullet.on('click', (function(e, el, o, ii, t){
106 if(_this.autoslide && _this.slideFn){
107 clearInterval(_this.slideFn);
108 _this.slideFn = window.setInterval(function() {
109 _this.showPanelNext();
113 }).createDelegate(this, [i, bullet], true));
118 this.slideFn = window.setInterval(function() {
119 _this.showPanelNext();
125 getChildContainer : function()
127 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
131 * register a Navigation item
132 * @param {Roo.bootstrap.NavItem} the navitem to add
134 register : function(item)
136 this.tabs.push( item);
137 item.navId = this.navId; // not really needed..
141 getActivePanel : function()
144 Roo.each(this.tabs, function(t) {
154 getPanelByName : function(n)
157 Roo.each(this.tabs, function(t) {
166 indexOfPanel : function(p)
169 Roo.each(this.tabs, function(t,i) {
170 if (t.tabId == p.tabId) {
179 * show a specific panel
180 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
181 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
183 showPanel : function (pan)
186 Roo.log("waiting for the transitionend");
190 if (typeof(pan) == 'number') {
191 pan = this.tabs[pan];
193 if (typeof(pan) == 'string') {
194 pan = this.getPanelByName(pan);
196 if (pan.tabId == this.getActivePanel().tabId) {
199 var cur = this.getActivePanel();
201 if (false === cur.fireEvent('beforedeactivate')) {
205 if(this.bullets > 0 && !Roo.isTouch){
206 this.setActiveBullet(this.indexOfPanel(pan));
209 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
211 this.transition = true;
212 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
213 var lr = dir == 'next' ? 'left' : 'right';
214 pan.el.addClass(dir); // or prev
215 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
216 cur.el.addClass(lr); // or right
220 cur.el.on('transitionend', function() {
221 Roo.log("trans end?");
223 pan.el.removeClass([lr,dir]);
226 cur.el.removeClass([lr]);
227 cur.setActive(false);
229 _this.transition = false;
231 }, this, { single: true } );
236 cur.setActive(false);
242 showPanelNext : function()
244 var i = this.indexOfPanel(this.getActivePanel());
246 if (i >= this.tabs.length - 1 && !this.autoslide) {
250 if (i >= this.tabs.length - 1 && this.autoslide) {
254 this.showPanel(this.tabs[i+1]);
257 showPanelPrev : function()
259 var i = this.indexOfPanel(this.getActivePanel());
261 if (i < 1 && !this.autoslide) {
265 if (i < 1 && this.autoslide) {
266 i = this.tabs.length;
269 this.showPanel(this.tabs[i-1]);
272 initBullet : function()
277 setActiveBullet : function(i)
283 Roo.each(this.el.select('.bullet', true).elements, function(el){
284 el.removeClass('selected');
287 var bullet = this.el.select('.bullet-' + i, true).first();
293 bullet.addClass('selected');
304 Roo.apply(Roo.bootstrap.TabGroup, {
308 * register a Navigation Group
309 * @param {Roo.bootstrap.NavGroup} the navgroup to add
311 register : function(navgrp)
313 this.groups[navgrp.navId] = navgrp;
317 * fetch a Navigation Group based on the navigation ID
318 * if one does not exist , it will get created.
319 * @param {string} the navgroup to add
320 * @returns {Roo.bootstrap.NavGroup} the navgroup
322 get: function(navId) {
323 if (typeof(this.groups[navId]) == 'undefined') {
324 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
326 return this.groups[navId] ;