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 {Boolean} bullets show bullets for the panels
15 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
16 * @cfg {Boolean} slideOnTouch (true|false) slide on touch .. default false
17 * @cfg {Number} timer auto slide timer .. default 0 millisecond
20 * Create a new TabGroup
21 * @param {Object} config The config object
24 Roo.bootstrap.TabGroup = function(config){
25 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
27 this.navId = Roo.id();
30 Roo.bootstrap.TabGroup.register(this);
34 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
44 getAutoCreate : function()
46 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
48 cfg.cls += ' tab-content';
51 cfg.cls += ' carousel slide';
54 cls : 'carousel-inner'
57 if(this.bullets && !Roo.isTouch){
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 if(Roo.isTouch && this.slideOnTouch){
88 this.el.on("touchstart", this.onTouchStart, this);
94 this.slideFn = window.setInterval(function() {
95 _this.showPanelNext();
101 onTouchStart : function(e, el, o)
103 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
107 this.showPanelNext();
110 getChildContainer : function()
112 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
116 * register a Navigation item
117 * @param {Roo.bootstrap.NavItem} the navitem to add
119 register : function(item)
121 this.tabs.push( item);
122 item.navId = this.navId; // not really needed..
127 getActivePanel : function()
130 Roo.each(this.tabs, function(t) {
140 getPanelByName : function(n)
143 Roo.each(this.tabs, function(t) {
152 indexOfPanel : function(p)
155 Roo.each(this.tabs, function(t,i) {
156 if (t.tabId == p.tabId) {
165 * show a specific panel
166 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
167 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
169 showPanel : function (pan)
171 if(this.transition || typeof(pan) == 'undefined'){
172 Roo.log("waiting for the transitionend");
176 if (typeof(pan) == 'number') {
177 pan = this.tabs[pan];
180 if (typeof(pan) == 'string') {
181 pan = this.getPanelByName(pan);
184 var cur = this.getActivePanel();
187 Roo.log('pan or acitve pan is undefined');
191 if (pan.tabId == this.getActivePanel().tabId) {
195 if (false === cur.fireEvent('beforedeactivate')) {
199 if(this.bullets > 0 && !Roo.isTouch){
200 this.setActiveBullet(this.indexOfPanel(pan));
203 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
205 this.transition = true;
206 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
207 var lr = dir == 'next' ? 'left' : 'right';
208 pan.el.addClass(dir); // or prev
209 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
210 cur.el.addClass(lr); // or right
214 cur.el.on('transitionend', function() {
215 Roo.log("trans end?");
217 pan.el.removeClass([lr,dir]);
220 cur.el.removeClass([lr]);
221 cur.setActive(false);
223 _this.transition = false;
225 }, this, { single: true } );
230 cur.setActive(false);
236 showPanelNext : function()
238 var i = this.indexOfPanel(this.getActivePanel());
240 if (i >= this.tabs.length - 1 && !this.autoslide) {
244 if (i >= this.tabs.length - 1 && this.autoslide) {
248 this.showPanel(this.tabs[i+1]);
251 showPanelPrev : function()
253 var i = this.indexOfPanel(this.getActivePanel());
255 if (i < 1 && !this.autoslide) {
259 if (i < 1 && this.autoslide) {
260 i = this.tabs.length;
263 this.showPanel(this.tabs[i-1]);
267 addBullet: function()
269 if(!this.bullets || Roo.isTouch){
272 var ctr = this.el.select('.carousel-bullets',true).first();
273 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
274 var bullet = ctr.createChild({
275 cls : 'bullet bullet-' + i
276 },ctr.dom.lastChild);
281 bullet.on('click', (function(e, el, o, ii, t){
287 if(this.autoslide && this.slideFn){
288 clearInterval(this.slideFn);
289 this.slideFn = window.setInterval(function() {
290 _this.showPanelNext();
294 }).createDelegate(this, [i, bullet], true));
299 setActiveBullet : function(i)
305 Roo.each(this.el.select('.bullet', true).elements, function(el){
306 el.removeClass('selected');
309 var bullet = this.el.select('.bullet-' + i, true).first();
315 bullet.addClass('selected');
326 Roo.apply(Roo.bootstrap.TabGroup, {
330 * register a Navigation Group
331 * @param {Roo.bootstrap.NavGroup} the navgroup to add
333 register : function(navgrp)
335 this.groups[navgrp.navId] = navgrp;
339 * fetch a Navigation Group based on the navigation ID
340 * if one does not exist , it will get created.
341 * @param {string} the navgroup to add
342 * @returns {Roo.bootstrap.NavGroup} the navgroup
344 get: function(navId) {
345 if (typeof(this.groups[navId]) == 'undefined') {
346 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
348 return this.groups[navId] ;