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;
87 initEvents: function()
89 if(Roo.isTouch && this.slideOnTouch){
90 this.el.on("touchstart", this.onTouchStart, this);
96 this.slideFn = window.setInterval(function() {
97 _this.showPanelNext();
103 onTouchStart : function(e, el, o)
105 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
109 this.showPanelNext();
112 getChildContainer : function()
114 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
118 * register a Navigation item
119 * @param {Roo.bootstrap.NavItem} the navitem to add
121 register : function(item)
123 this.tabs.push( item);
124 item.navId = this.navId; // not really needed..
129 getActivePanel : function()
132 Roo.each(this.tabs, function(t) {
142 getPanelByName : function(n)
145 Roo.each(this.tabs, function(t) {
154 indexOfPanel : function(p)
157 Roo.each(this.tabs, function(t,i) {
158 if (t.tabId == p.tabId) {
167 * show a specific panel
168 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
169 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
171 showPanel : function (pan)
173 if(this.transition || typeof(pan) == 'undefined'){
174 Roo.log("waiting for the transitionend");
178 if (typeof(pan) == 'number') {
179 pan = this.tabs[pan];
182 if (typeof(pan) == 'string') {
183 pan = this.getPanelByName(pan);
186 var cur = this.getActivePanel();
189 Roo.log('pan or acitve pan is undefined');
193 if (pan.tabId == this.getActivePanel().tabId) {
197 if (false === cur.fireEvent('beforedeactivate')) {
201 if(this.bullets > 0 && !Roo.isTouch){
202 this.setActiveBullet(this.indexOfPanel(pan));
205 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
207 this.transition = true;
208 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
209 var lr = dir == 'next' ? 'left' : 'right';
210 pan.el.addClass(dir); // or prev
211 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
212 cur.el.addClass(lr); // or right
216 cur.el.on('transitionend', function() {
217 Roo.log("trans end?");
219 pan.el.removeClass([lr,dir]);
222 cur.el.removeClass([lr]);
223 cur.setActive(false);
225 _this.transition = false;
227 }, this, { single: true } );
232 cur.setActive(false);
238 showPanelNext : function()
240 var i = this.indexOfPanel(this.getActivePanel());
242 if (i >= this.tabs.length - 1 && !this.autoslide) {
246 if (i >= this.tabs.length - 1 && this.autoslide) {
250 this.showPanel(this.tabs[i+1]);
253 showPanelPrev : function()
255 var i = this.indexOfPanel(this.getActivePanel());
257 if (i < 1 && !this.autoslide) {
261 if (i < 1 && this.autoslide) {
262 i = this.tabs.length;
265 this.showPanel(this.tabs[i-1]);
269 addBullet: function()
271 if(!this.bullets || Roo.isTouch){
274 var ctr = this.el.select('.carousel-bullets',true).first();
275 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
276 var bullet = ctr.createChild({
277 cls : 'bullet bullet-' + i
278 },ctr.dom.lastChild);
283 bullet.on('click', (function(e, el, o, ii, t){
289 if(this.autoslide && this.slideFn){
290 clearInterval(this.slideFn);
291 this.slideFn = window.setInterval(function() {
292 _this.showPanelNext();
296 }).createDelegate(this, [i, bullet], true));
301 setActiveBullet : function(i)
307 Roo.each(this.el.select('.bullet', true).elements, function(el){
308 el.removeClass('selected');
311 var bullet = this.el.select('.bullet-' + i, true).first();
317 bullet.addClass('selected');
328 Roo.apply(Roo.bootstrap.TabGroup, {
332 * register a Navigation Group
333 * @param {Roo.bootstrap.NavGroup} the navgroup to add
335 register : function(navgrp)
337 this.groups[navgrp.navId] = navgrp;
341 * fetch a Navigation Group based on the navigation ID
342 * if one does not exist , it will get created.
343 * @param {string} the navgroup to add
344 * @returns {Roo.bootstrap.NavGroup} the navgroup
346 get: function(navId) {
347 if (typeof(this.groups[navId]) == 'undefined') {
348 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
350 return this.groups[navId] ;