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 {Number} timer auto slide timer .. default 0 millisecond
17 * @cfg {Boolean} showarrow (true|false) show arrow default true
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, {
45 getAutoCreate : function()
47 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
49 cfg.cls += ' tab-content';
52 cfg.cls += ' carousel slide';
55 cls : 'carousel-inner',
59 if(this.bullets && !Roo.isTouch){
62 cls : 'carousel-bullets',
67 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
74 cfg.cn[0].cn.push(bullets);
80 class : 'carousel-arrow',
84 class : 'carousel-prev',
88 class : 'fa fa-chevron-left'
94 class : 'carousel-next',
98 class : 'fa fa-chevron-right'
111 initEvents: function()
113 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
114 // this.el.on("touchstart", this.onTouchStart, this);
120 this.slideFn = window.setInterval(function() {
121 _this.showPanelNext();
126 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
127 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
133 // onTouchStart : function(e, el, o)
135 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
139 // this.showPanelNext();
142 onTouchStart : function(e)
146 Roo.log('on touch start');
150 Roo.log(e.browserEvent.touches[0].clientX);
153 onTouchMove : function(e)
157 Roo.log('on touch move');
162 onTouchEnd : function(e)
166 Roo.log('on touch end');
172 getChildContainer : function()
174 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
178 * register a Navigation item
179 * @param {Roo.bootstrap.NavItem} the navitem to add
181 register : function(item)
183 this.tabs.push( item);
184 item.navId = this.navId; // not really needed..
189 getActivePanel : function()
192 Roo.each(this.tabs, function(t) {
202 getPanelByName : function(n)
205 Roo.each(this.tabs, function(t) {
214 indexOfPanel : function(p)
217 Roo.each(this.tabs, function(t,i) {
218 if (t.tabId == p.tabId) {
227 * show a specific panel
228 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
229 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
231 showPanel : function (pan)
233 if(this.transition || typeof(pan) == 'undefined'){
234 Roo.log("waiting for the transitionend");
238 if (typeof(pan) == 'number') {
239 pan = this.tabs[pan];
242 if (typeof(pan) == 'string') {
243 pan = this.getPanelByName(pan);
246 var cur = this.getActivePanel();
249 Roo.log('pan or acitve pan is undefined');
253 if (pan.tabId == this.getActivePanel().tabId) {
257 if (false === cur.fireEvent('beforedeactivate')) {
261 if(this.bullets > 0 && !Roo.isTouch){
262 this.setActiveBullet(this.indexOfPanel(pan));
265 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
267 this.transition = true;
268 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
269 var lr = dir == 'next' ? 'left' : 'right';
270 pan.el.addClass(dir); // or prev
271 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
272 cur.el.addClass(lr); // or right
276 cur.el.on('transitionend', function() {
277 Roo.log("trans end?");
279 pan.el.removeClass([lr,dir]);
282 cur.el.removeClass([lr]);
283 cur.setActive(false);
285 _this.transition = false;
287 }, this, { single: true } );
292 cur.setActive(false);
298 showPanelNext : function()
300 var i = this.indexOfPanel(this.getActivePanel());
302 if (i >= this.tabs.length - 1 && !this.autoslide) {
306 if (i >= this.tabs.length - 1 && this.autoslide) {
310 this.showPanel(this.tabs[i+1]);
313 showPanelPrev : function()
315 var i = this.indexOfPanel(this.getActivePanel());
317 if (i < 1 && !this.autoslide) {
321 if (i < 1 && this.autoslide) {
322 i = this.tabs.length;
325 this.showPanel(this.tabs[i-1]);
329 addBullet: function()
331 if(!this.bullets || Roo.isTouch){
334 var ctr = this.el.select('.carousel-bullets',true).first();
335 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
336 var bullet = ctr.createChild({
337 cls : 'bullet bullet-' + i
338 },ctr.dom.lastChild);
343 bullet.on('click', (function(e, el, o, ii, t){
349 if(this.autoslide && this.slideFn){
350 clearInterval(this.slideFn);
351 this.slideFn = window.setInterval(function() {
352 _this.showPanelNext();
356 }).createDelegate(this, [i, bullet], true));
361 setActiveBullet : function(i)
367 Roo.each(this.el.select('.bullet', true).elements, function(el){
368 el.removeClass('selected');
371 var bullet = this.el.select('.bullet-' + i, true).first();
377 bullet.addClass('selected');
388 Roo.apply(Roo.bootstrap.TabGroup, {
392 * register a Navigation Group
393 * @param {Roo.bootstrap.NavGroup} the navgroup to add
395 register : function(navgrp)
397 this.groups[navgrp.navId] = navgrp;
401 * fetch a Navigation Group based on the navigation ID
402 * if one does not exist , it will get created.
403 * @param {string} the navgroup to add
404 * @returns {Roo.bootstrap.NavGroup} the navgroup
406 get: function(navId) {
407 if (typeof(this.groups[navId]) == 'undefined') {
408 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
410 return this.groups[navId] ;