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()
48 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
52 cfg.cls += ' tab-content';
55 cfg.cls += ' carousel slide';
58 cls : 'carousel-inner',
62 if(this.bullets && !Roo.isTouch){
65 cls : 'carousel-bullets',
70 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
73 for (var i = 0; i < this.bullets; i++){
75 cls : 'bullet bullet-' + i
83 cfg.cn[0].cn.push(bullets);
88 class : 'carousel-nav',
92 class : 'carousel-prev',
96 class : 'fa fa-chevron-left'
102 class : 'carousel-next',
106 class : 'fa fa-chevron-right'
117 initEvents: function()
119 if(Roo.isTouch && this.slideOnTouch){
120 this.el.on("touchstart", this.onTouchStart, this);
126 this.slideFn = window.setInterval(function() {
127 _this.showPanelNext();
133 onTouchStart : function(e, el, o)
135 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
139 this.showPanelNext();
142 getChildContainer : function()
144 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
148 * register a Navigation item
149 * @param {Roo.bootstrap.NavItem} the navitem to add
151 register : function(item)
153 this.tabs.push( item);
154 item.navId = this.navId; // not really needed..
159 getActivePanel : function()
162 Roo.each(this.tabs, function(t) {
172 getPanelByName : function(n)
175 Roo.each(this.tabs, function(t) {
184 indexOfPanel : function(p)
187 Roo.each(this.tabs, function(t,i) {
188 if (t.tabId == p.tabId) {
197 * show a specific panel
198 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
199 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
201 showPanel : function (pan)
203 if(this.transition || typeof(pan) == 'undefined'){
204 Roo.log("waiting for the transitionend");
208 if (typeof(pan) == 'number') {
209 pan = this.tabs[pan];
212 if (typeof(pan) == 'string') {
213 pan = this.getPanelByName(pan);
216 var cur = this.getActivePanel();
219 Roo.log('pan or acitve pan is undefined');
223 if (pan.tabId == this.getActivePanel().tabId) {
227 if (false === cur.fireEvent('beforedeactivate')) {
231 if(this.bullets > 0 && !Roo.isTouch){
232 this.setActiveBullet(this.indexOfPanel(pan));
235 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
237 this.transition = true;
238 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
239 var lr = dir == 'next' ? 'left' : 'right';
240 pan.el.addClass(dir); // or prev
241 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
242 cur.el.addClass(lr); // or right
246 cur.el.on('transitionend', function() {
247 Roo.log("trans end?");
249 pan.el.removeClass([lr,dir]);
252 cur.el.removeClass([lr]);
253 cur.setActive(false);
255 _this.transition = false;
257 }, this, { single: true } );
262 cur.setActive(false);
268 showPanelNext : function()
270 var i = this.indexOfPanel(this.getActivePanel());
272 if (i >= this.tabs.length - 1 && !this.autoslide) {
276 if (i >= this.tabs.length - 1 && this.autoslide) {
280 this.showPanel(this.tabs[i+1]);
283 showPanelPrev : function()
285 var i = this.indexOfPanel(this.getActivePanel());
287 if (i < 1 && !this.autoslide) {
291 if (i < 1 && this.autoslide) {
292 i = this.tabs.length;
295 this.showPanel(this.tabs[i-1]);
299 addBullet: function()
301 if(!this.bullets || Roo.isTouch){
304 var ctr = this.el.select('.carousel-bullets',true).first();
305 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
306 var bullet = ctr.createChild({
307 cls : 'bullet bullet-' + i
308 },ctr.dom.lastChild);
313 bullet.on('click', (function(e, el, o, ii, t){
319 if(this.autoslide && this.slideFn){
320 clearInterval(this.slideFn);
321 this.slideFn = window.setInterval(function() {
322 _this.showPanelNext();
326 }).createDelegate(this, [i, bullet], true));
331 setActiveBullet : function(i)
337 Roo.each(this.el.select('.bullet', true).elements, function(el){
338 el.removeClass('selected');
341 var bullet = this.el.select('.bullet-' + i, true).first();
347 bullet.addClass('selected');
358 Roo.apply(Roo.bootstrap.TabGroup, {
362 * register a Navigation Group
363 * @param {Roo.bootstrap.NavGroup} the navgroup to add
365 register : function(navgrp)
367 this.groups[navgrp.navId] = navgrp;
371 * fetch a Navigation Group based on the navigation ID
372 * if one does not exist , it will get created.
373 * @param {string} the navgroup to add
374 * @returns {Roo.bootstrap.NavGroup} the navgroup
376 get: function(navId) {
377 if (typeof(this.groups[navId]) == 'undefined') {
378 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
380 return this.groups[navId] ;