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 {Number} bullets show the panel pointer.. default 0
15 * @cfg {Boolena} autoslide (true|false) auto slide .. default false
16 * @cfg {Number} timer auto slide timer .. default 0 millisecond
19 * Create a new TabGroup
20 * @param {Object} config The config object
23 Roo.bootstrap.TabGroup = function(config){
24 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
26 this.navId = Roo.id();
29 Roo.bootstrap.TabGroup.register(this);
33 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
42 getAutoCreate : function()
44 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
46 cfg.cls += ' tab-content';
48 Roo.log('get auto create...............');
51 cfg.cls += ' carousel slide';
54 cls : 'carousel-inner'
57 if(this.bullets > 0 && !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;
85 initEvents: function()
87 Roo.log('-------- init events on tab group ---------');
89 if(this.bullets > 0 && !Roo.isTouch){
96 this.el.on("touchstart", this.onTouchStart, this);
102 this.slideFn = window.setInterval(function() {
103 _this.showPanelNext();
109 onTouchStart : function(e, el, o)
111 Roo.log('onTouchStart');
113 Roo.log(e.getTarget());
116 getChildContainer : function()
118 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
122 * register a Navigation item
123 * @param {Roo.bootstrap.NavItem} the navitem to add
125 register : function(item)
127 this.tabs.push( item);
128 item.navId = this.navId; // not really needed..
132 getActivePanel : function()
135 Roo.each(this.tabs, function(t) {
145 getPanelByName : function(n)
148 Roo.each(this.tabs, function(t) {
157 indexOfPanel : function(p)
160 Roo.each(this.tabs, function(t,i) {
161 if (t.tabId == p.tabId) {
170 * show a specific panel
171 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
172 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
174 showPanel : function (pan)
177 Roo.log("waiting for the transitionend");
181 if (typeof(pan) == 'number') {
182 pan = this.tabs[pan];
184 if (typeof(pan) == 'string') {
185 pan = this.getPanelByName(pan);
187 if (pan.tabId == this.getActivePanel().tabId) {
190 var cur = this.getActivePanel();
192 if (false === cur.fireEvent('beforedeactivate')) {
196 if(this.bullets > 0 && !Roo.isTouch){
197 this.setActiveBullet(this.indexOfPanel(pan));
200 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
202 this.transition = true;
203 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
204 var lr = dir == 'next' ? 'left' : 'right';
205 pan.el.addClass(dir); // or prev
206 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
207 cur.el.addClass(lr); // or right
211 cur.el.on('transitionend', function() {
212 Roo.log("trans end?");
214 pan.el.removeClass([lr,dir]);
217 cur.el.removeClass([lr]);
218 cur.setActive(false);
220 _this.transition = false;
222 }, this, { single: true } );
227 cur.setActive(false);
233 showPanelNext : function()
235 var i = this.indexOfPanel(this.getActivePanel());
237 if (i >= this.tabs.length - 1 && !this.autoslide) {
241 if (i >= this.tabs.length - 1 && this.autoslide) {
245 this.showPanel(this.tabs[i+1]);
248 showPanelPrev : function()
250 var i = this.indexOfPanel(this.getActivePanel());
252 if (i < 1 && !this.autoslide) {
256 if (i < 1 && this.autoslide) {
257 i = this.tabs.length;
260 this.showPanel(this.tabs[i-1]);
263 initBullet : function()
271 for (var i = 0; i < this.bullets; i++){
272 var bullet = this.el.select('.bullet-' + i, true).first();
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));
295 setActiveBullet : function(i)
301 Roo.each(this.el.select('.bullet', true).elements, function(el){
302 el.removeClass('selected');
305 var bullet = this.el.select('.bullet-' + i, true).first();
311 bullet.addClass('selected');
322 Roo.apply(Roo.bootstrap.TabGroup, {
326 * register a Navigation Group
327 * @param {Roo.bootstrap.NavGroup} the navgroup to add
329 register : function(navgrp)
331 this.groups[navgrp.navId] = navgrp;
335 * fetch a Navigation Group based on the navigation ID
336 * if one does not exist , it will get created.
337 * @param {string} the navgroup to add
338 * @returns {Roo.bootstrap.NavGroup} the navgroup
340 get: function(navId) {
341 if (typeof(this.groups[navId]) == 'undefined') {
342 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
344 return this.groups[navId] ;