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));
50 cfg.cls += ' tab-content';
53 cfg.cls += ' carousel slide';
56 cls : 'carousel-inner',
60 if(this.bullets && !Roo.isTouch){
63 cls : 'carousel-bullets',
68 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
71 for (var i = 0; i < this.bullets; i++){
73 cls : 'bullet bullet-' + i
81 cfg.cn[0].cn.push(bullets);
86 class : 'carousel-nav',
90 class : 'carousel-prev',
94 class : 'fa fa-chevron-left'
100 class : 'carousel-next',
104 class : 'fa fa-chevron-right'
115 initEvents: function()
117 if(Roo.isTouch && this.slideOnTouch){
118 this.el.on("touchstart", this.onTouchStart, this);
124 this.slideFn = window.setInterval(function() {
125 _this.showPanelNext();
131 onTouchStart : function(e, el, o)
133 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
137 this.showPanelNext();
140 getChildContainer : function()
142 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
146 * register a Navigation item
147 * @param {Roo.bootstrap.NavItem} the navitem to add
149 register : function(item)
151 this.tabs.push( item);
152 item.navId = this.navId; // not really needed..
157 getActivePanel : function()
160 Roo.each(this.tabs, function(t) {
170 getPanelByName : function(n)
173 Roo.each(this.tabs, function(t) {
182 indexOfPanel : function(p)
185 Roo.each(this.tabs, function(t,i) {
186 if (t.tabId == p.tabId) {
195 * show a specific panel
196 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
197 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
199 showPanel : function (pan)
201 if(this.transition || typeof(pan) == 'undefined'){
202 Roo.log("waiting for the transitionend");
206 if (typeof(pan) == 'number') {
207 pan = this.tabs[pan];
210 if (typeof(pan) == 'string') {
211 pan = this.getPanelByName(pan);
214 var cur = this.getActivePanel();
217 Roo.log('pan or acitve pan is undefined');
221 if (pan.tabId == this.getActivePanel().tabId) {
225 if (false === cur.fireEvent('beforedeactivate')) {
229 if(this.bullets > 0 && !Roo.isTouch){
230 this.setActiveBullet(this.indexOfPanel(pan));
233 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
235 this.transition = true;
236 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
237 var lr = dir == 'next' ? 'left' : 'right';
238 pan.el.addClass(dir); // or prev
239 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
240 cur.el.addClass(lr); // or right
244 cur.el.on('transitionend', function() {
245 Roo.log("trans end?");
247 pan.el.removeClass([lr,dir]);
250 cur.el.removeClass([lr]);
251 cur.setActive(false);
253 _this.transition = false;
255 }, this, { single: true } );
260 cur.setActive(false);
266 showPanelNext : function()
268 var i = this.indexOfPanel(this.getActivePanel());
270 if (i >= this.tabs.length - 1 && !this.autoslide) {
274 if (i >= this.tabs.length - 1 && this.autoslide) {
278 this.showPanel(this.tabs[i+1]);
281 showPanelPrev : function()
283 var i = this.indexOfPanel(this.getActivePanel());
285 if (i < 1 && !this.autoslide) {
289 if (i < 1 && this.autoslide) {
290 i = this.tabs.length;
293 this.showPanel(this.tabs[i-1]);
297 addBullet: function()
299 if(!this.bullets || Roo.isTouch){
302 var ctr = this.el.select('.carousel-bullets',true).first();
303 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
304 var bullet = ctr.createChild({
305 cls : 'bullet bullet-' + i
306 },ctr.dom.lastChild);
311 bullet.on('click', (function(e, el, o, ii, t){
317 if(this.autoslide && this.slideFn){
318 clearInterval(this.slideFn);
319 this.slideFn = window.setInterval(function() {
320 _this.showPanelNext();
324 }).createDelegate(this, [i, bullet], true));
329 setActiveBullet : function(i)
335 Roo.each(this.el.select('.bullet', true).elements, function(el){
336 el.removeClass('selected');
339 var bullet = this.el.select('.bullet-' + i, true).first();
345 bullet.addClass('selected');
356 Roo.apply(Roo.bootstrap.TabGroup, {
360 * register a Navigation Group
361 * @param {Roo.bootstrap.NavGroup} the navgroup to add
363 register : function(navgrp)
365 this.groups[navgrp.navId] = navgrp;
369 * fetch a Navigation Group based on the navigation ID
370 * if one does not exist , it will get created.
371 * @param {string} the navgroup to add
372 * @returns {Roo.bootstrap.NavGroup} the navgroup
374 get: function(navId) {
375 if (typeof(this.groups[navId]) == 'undefined') {
376 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
378 return this.groups[navId] ;