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'
59 if(this.bullets && !Roo.isTouch){
62 cls : 'carousel-bullets',
67 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
70 for (var i = 0; i < this.bullets; i++){
72 cls : 'bullet bullet-' + i
80 cfg.cn[0].cn = bullets;
85 class : 'carousel-nav',
89 class : 'carousel-prev',
93 class : 'fa fa-chevron-left'
99 class : 'carousel-next',
103 class : 'fa fa-chevron-right'
114 initEvents: function()
116 if(Roo.isTouch && this.slideOnTouch){
117 this.el.on("touchstart", this.onTouchStart, this);
123 this.slideFn = window.setInterval(function() {
124 _this.showPanelNext();
130 onTouchStart : function(e, el, o)
132 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
136 this.showPanelNext();
139 getChildContainer : function()
141 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
145 * register a Navigation item
146 * @param {Roo.bootstrap.NavItem} the navitem to add
148 register : function(item)
150 this.tabs.push( item);
151 item.navId = this.navId; // not really needed..
156 getActivePanel : function()
159 Roo.each(this.tabs, function(t) {
169 getPanelByName : function(n)
172 Roo.each(this.tabs, function(t) {
181 indexOfPanel : function(p)
184 Roo.each(this.tabs, function(t,i) {
185 if (t.tabId == p.tabId) {
194 * show a specific panel
195 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
196 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
198 showPanel : function (pan)
200 if(this.transition || typeof(pan) == 'undefined'){
201 Roo.log("waiting for the transitionend");
205 if (typeof(pan) == 'number') {
206 pan = this.tabs[pan];
209 if (typeof(pan) == 'string') {
210 pan = this.getPanelByName(pan);
213 var cur = this.getActivePanel();
216 Roo.log('pan or acitve pan is undefined');
220 if (pan.tabId == this.getActivePanel().tabId) {
224 if (false === cur.fireEvent('beforedeactivate')) {
228 if(this.bullets > 0 && !Roo.isTouch){
229 this.setActiveBullet(this.indexOfPanel(pan));
232 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
234 this.transition = true;
235 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
236 var lr = dir == 'next' ? 'left' : 'right';
237 pan.el.addClass(dir); // or prev
238 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
239 cur.el.addClass(lr); // or right
243 cur.el.on('transitionend', function() {
244 Roo.log("trans end?");
246 pan.el.removeClass([lr,dir]);
249 cur.el.removeClass([lr]);
250 cur.setActive(false);
252 _this.transition = false;
254 }, this, { single: true } );
259 cur.setActive(false);
265 showPanelNext : function()
267 var i = this.indexOfPanel(this.getActivePanel());
269 if (i >= this.tabs.length - 1 && !this.autoslide) {
273 if (i >= this.tabs.length - 1 && this.autoslide) {
277 this.showPanel(this.tabs[i+1]);
280 showPanelPrev : function()
282 var i = this.indexOfPanel(this.getActivePanel());
284 if (i < 1 && !this.autoslide) {
288 if (i < 1 && this.autoslide) {
289 i = this.tabs.length;
292 this.showPanel(this.tabs[i-1]);
296 addBullet: function()
298 if(!this.bullets || Roo.isTouch){
301 var ctr = this.el.select('.carousel-bullets',true).first();
302 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
303 var bullet = ctr.createChild({
304 cls : 'bullet bullet-' + i
305 },ctr.dom.lastChild);
310 bullet.on('click', (function(e, el, o, ii, t){
316 if(this.autoslide && this.slideFn){
317 clearInterval(this.slideFn);
318 this.slideFn = window.setInterval(function() {
319 _this.showPanelNext();
323 }).createDelegate(this, [i, bullet], true));
328 setActiveBullet : function(i)
334 Roo.each(this.el.select('.bullet', true).elements, function(el){
335 el.removeClass('selected');
338 var bullet = this.el.select('.bullet-' + i, true).first();
344 bullet.addClass('selected');
355 Roo.apply(Roo.bootstrap.TabGroup, {
359 * register a Navigation Group
360 * @param {Roo.bootstrap.NavGroup} the navgroup to add
362 register : function(navgrp)
364 this.groups[navgrp.navId] = navgrp;
368 * fetch a Navigation Group based on the navigation ID
369 * if one does not exist , it will get created.
370 * @param {string} the navgroup to add
371 * @returns {Roo.bootstrap.NavGroup} the navgroup
373 get: function(navId) {
374 if (typeof(this.groups[navId]) == 'undefined') {
375 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
377 return this.groups[navId] ;