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';
50 Roo.log('get auto create...............');
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;
87 initEvents: function()
89 Roo.log('-------- init events on tab group ---------');
95 if(Roo.isTouch && this.slideOnTouch){
96 this.el.on("touchstart", this.onTouchStart, this);
102 this.slideFn = window.setInterval(function() {
103 _this.showPanelNext();
109 onTouchStart : function(e, el, o)
111 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
115 this.showPanelNext();
118 getChildContainer : function()
120 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
124 * register a Navigation item
125 * @param {Roo.bootstrap.NavItem} the navitem to add
127 register : function(item)
129 this.tabs.push( item);
130 item.navId = this.navId; // not really needed..
135 getActivePanel : function()
138 Roo.each(this.tabs, function(t) {
148 getPanelByName : function(n)
151 Roo.each(this.tabs, function(t) {
160 indexOfPanel : function(p)
163 Roo.each(this.tabs, function(t,i) {
164 if (t.tabId == p.tabId) {
173 * show a specific panel
174 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
175 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
177 showPanel : function (pan)
180 Roo.log("waiting for the transitionend");
184 if (typeof(pan) == 'number') {
185 pan = this.tabs[pan];
187 if (typeof(pan) == 'string') {
188 pan = this.getPanelByName(pan);
190 if (pan.tabId == this.getActivePanel().tabId) {
193 var cur = this.getActivePanel();
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);
278 bullet.on('click', (function(e, el, o, ii, t){
284 if(this.autoslide && this.slideFn){
285 clearInterval(this.slideFn);
286 this.slideFn = window.setInterval(function() {
287 this.showPanelNext();
291 }).createDelegate(this, [i, bullet], true));
296 setActiveBullet : function(i)
302 Roo.each(this.el.select('.bullet', true).elements, function(el){
303 el.removeClass('selected');
306 var bullet = this.el.select('.bullet-' + i, true).first();
312 bullet.addClass('selected');
323 Roo.apply(Roo.bootstrap.TabGroup, {
327 * register a Navigation Group
328 * @param {Roo.bootstrap.NavGroup} the navgroup to add
330 register : function(navgrp)
332 this.groups[navgrp.navId] = navgrp;
336 * fetch a Navigation Group based on the navigation ID
337 * if one does not exist , it will get created.
338 * @param {string} the navgroup to add
339 * @returns {Roo.bootstrap.NavGroup} the navgroup
341 get: function(navId) {
342 if (typeof(this.groups[navId]) == 'undefined') {
343 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
345 return this.groups[navId] ;