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){
96 this.slideFn = window.setInterval(function() {
97 _this.showPanelNext();
103 getChildContainer : function()
105 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
109 * register a Navigation item
110 * @param {Roo.bootstrap.NavItem} the navitem to add
112 register : function(item)
114 this.tabs.push( item);
115 item.navId = this.navId; // not really needed..
119 getActivePanel : function()
122 Roo.each(this.tabs, function(t) {
132 getPanelByName : function(n)
135 Roo.each(this.tabs, function(t) {
144 indexOfPanel : function(p)
147 Roo.each(this.tabs, function(t,i) {
148 if (t.tabId == p.tabId) {
157 * show a specific panel
158 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
159 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
161 showPanel : function (pan)
164 Roo.log("waiting for the transitionend");
168 if (typeof(pan) == 'number') {
169 pan = this.tabs[pan];
171 if (typeof(pan) == 'string') {
172 pan = this.getPanelByName(pan);
174 if (pan.tabId == this.getActivePanel().tabId) {
177 var cur = this.getActivePanel();
179 if (false === cur.fireEvent('beforedeactivate')) {
183 if(this.bullets > 0 && !Roo.isTouch){
184 this.setActiveBullet(this.indexOfPanel(pan));
187 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
189 this.transition = true;
190 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
191 var lr = dir == 'next' ? 'left' : 'right';
192 pan.el.addClass(dir); // or prev
193 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
194 cur.el.addClass(lr); // or right
198 cur.el.on('transitionend', function() {
199 Roo.log("trans end?");
201 pan.el.removeClass([lr,dir]);
204 cur.el.removeClass([lr]);
205 cur.setActive(false);
207 _this.transition = false;
209 }, this, { single: true } );
214 cur.setActive(false);
220 showPanelNext : function()
222 var i = this.indexOfPanel(this.getActivePanel());
224 if (i >= this.tabs.length - 1 && !this.autoslide) {
228 if (i >= this.tabs.length - 1 && this.autoslide) {
232 this.showPanel(this.tabs[i+1]);
235 showPanelPrev : function()
237 var i = this.indexOfPanel(this.getActivePanel());
239 if (i < 1 && !this.autoslide) {
243 if (i < 1 && this.autoslide) {
244 i = this.tabs.length;
247 this.showPanel(this.tabs[i-1]);
250 initBullet : function()
252 for (var i = 0; i < this.bullets; i++){
253 var bullet = this.el.select('.bullet-' + i, true).first();
259 bullet.on('click', (function(e, el, o, ii, t){
265 if(_this.autoslide && _this.slideFn){
266 clearInterval(_this.slideFn);
267 _this.slideFn = window.setInterval(function() {
268 _this.showPanelNext();
272 }).createDelegate(this, [i, bullet], true));
276 setActiveBullet : function(i)
282 Roo.each(this.el.select('.bullet', true).elements, function(el){
283 el.removeClass('selected');
286 var bullet = this.el.select('.bullet-' + i, true).first();
292 bullet.addClass('selected');
303 Roo.apply(Roo.bootstrap.TabGroup, {
307 * register a Navigation Group
308 * @param {Roo.bootstrap.NavGroup} the navgroup to add
310 register : function(navgrp)
312 this.groups[navgrp.navId] = navgrp;
316 * fetch a Navigation Group based on the navigation ID
317 * if one does not exist , it will get created.
318 * @param {string} the navgroup to add
319 * @returns {Roo.bootstrap.NavGroup} the navgroup
321 get: function(navId) {
322 if (typeof(this.groups[navId]) == 'undefined') {
323 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
325 return this.groups[navId] ;