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 {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 > 0 && !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 ---------');
91 if(this.bullets > 0 && !Roo.isTouch){
98 this.el.on("touchstart", this.onTouchStart, this);
104 this.slideFn = window.setInterval(function() {
105 _this.showPanelNext();
111 onTouchStart : function(e, el, o)
113 if(!Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
117 this.showPanelNext();
120 getChildContainer : function()
122 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
126 * register a Navigation item
127 * @param {Roo.bootstrap.NavItem} the navitem to add
129 register : function(item)
131 this.tabs.push( item);
132 item.navId = this.navId; // not really needed..
136 getActivePanel : function()
139 Roo.each(this.tabs, function(t) {
149 getPanelByName : function(n)
152 Roo.each(this.tabs, function(t) {
161 indexOfPanel : function(p)
164 Roo.each(this.tabs, function(t,i) {
165 if (t.tabId == p.tabId) {
174 * show a specific panel
175 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
176 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
178 showPanel : function (pan)
181 Roo.log("waiting for the transitionend");
185 if (typeof(pan) == 'number') {
186 pan = this.tabs[pan];
188 if (typeof(pan) == 'string') {
189 pan = this.getPanelByName(pan);
191 if (pan.tabId == this.getActivePanel().tabId) {
194 var cur = this.getActivePanel();
196 if (false === cur.fireEvent('beforedeactivate')) {
200 if(this.bullets > 0 && !Roo.isTouch){
201 this.setActiveBullet(this.indexOfPanel(pan));
204 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
206 this.transition = true;
207 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
208 var lr = dir == 'next' ? 'left' : 'right';
209 pan.el.addClass(dir); // or prev
210 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
211 cur.el.addClass(lr); // or right
215 cur.el.on('transitionend', function() {
216 Roo.log("trans end?");
218 pan.el.removeClass([lr,dir]);
221 cur.el.removeClass([lr]);
222 cur.setActive(false);
224 _this.transition = false;
226 }, this, { single: true } );
231 cur.setActive(false);
237 showPanelNext : function()
239 var i = this.indexOfPanel(this.getActivePanel());
241 if (i >= this.tabs.length - 1 && !this.autoslide) {
245 if (i >= this.tabs.length - 1 && this.autoslide) {
249 this.showPanel(this.tabs[i+1]);
252 showPanelPrev : function()
254 var i = this.indexOfPanel(this.getActivePanel());
256 if (i < 1 && !this.autoslide) {
260 if (i < 1 && this.autoslide) {
261 i = this.tabs.length;
264 this.showPanel(this.tabs[i-1]);
267 initBullet : function()
275 for (var i = 0; i < this.bullets; i++){
276 var bullet = this.el.select('.bullet-' + i, true).first();
282 bullet.on('click', (function(e, el, o, ii, t){
288 if(_this.autoslide && _this.slideFn){
289 clearInterval(_this.slideFn);
290 _this.slideFn = window.setInterval(function() {
291 _this.showPanelNext();
295 }).createDelegate(this, [i, bullet], true));
299 setActiveBullet : function(i)
305 Roo.each(this.el.select('.bullet', true).elements, function(el){
306 el.removeClass('selected');
309 var bullet = this.el.select('.bullet-' + i, true).first();
315 bullet.addClass('selected');
326 Roo.apply(Roo.bootstrap.TabGroup, {
330 * register a Navigation Group
331 * @param {Roo.bootstrap.NavGroup} the navgroup to add
333 register : function(navgrp)
335 this.groups[navgrp.navId] = navgrp;
339 * fetch a Navigation Group based on the navigation ID
340 * if one does not exist , it will get created.
341 * @param {string} the navgroup to add
342 * @returns {Roo.bootstrap.NavGroup} the navgroup
344 get: function(navId) {
345 if (typeof(this.groups[navId]) == 'undefined') {
346 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
348 return this.groups[navId] ;