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
18 * @cfg {Boolean} showarrow (true|false) show arrow default true
21 * Create a new TabGroup
22 * @param {Object} config The config object
25 Roo.bootstrap.TabGroup = function(config){
26 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
28 this.navId = Roo.id();
31 Roo.bootstrap.TabGroup.register(this);
35 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
46 getAutoCreate : function()
50 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
54 cfg.cls += ' tab-content';
57 cfg.cls += ' carousel slide';
60 cls : 'carousel-inner',
64 if(this.bullets && !Roo.isTouch){
67 cls : 'carousel-bullets',
72 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
75 for (var i = 0; i < this.bullets; i++){
77 cls : 'bullet bullet-' + i
85 cfg.cn[0].cn.push(bullets);
91 class : 'carousel-arrow',
95 class : 'carousel-prev',
99 class : 'fa fa-chevron-left'
105 class : 'carousel-next',
109 class : 'fa fa-chevron-right'
122 initEvents: function()
124 if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
125 this.el.on("touchstart", this.onTouchStart, this);
131 this.slideFn = window.setInterval(function() {
132 _this.showPanelNext();
137 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
138 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
144 onTouchStart : function(e, el, o)
146 if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
150 this.showPanelNext();
153 getChildContainer : function()
155 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
159 * register a Navigation item
160 * @param {Roo.bootstrap.NavItem} the navitem to add
162 register : function(item)
164 this.tabs.push( item);
165 item.navId = this.navId; // not really needed..
170 getActivePanel : function()
173 Roo.each(this.tabs, function(t) {
183 getPanelByName : function(n)
186 Roo.each(this.tabs, function(t) {
195 indexOfPanel : function(p)
198 Roo.each(this.tabs, function(t,i) {
199 if (t.tabId == p.tabId) {
208 * show a specific panel
209 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
210 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
212 showPanel : function (pan)
214 if(this.transition || typeof(pan) == 'undefined'){
215 Roo.log("waiting for the transitionend");
219 if (typeof(pan) == 'number') {
220 pan = this.tabs[pan];
223 if (typeof(pan) == 'string') {
224 pan = this.getPanelByName(pan);
227 var cur = this.getActivePanel();
230 Roo.log('pan or acitve pan is undefined');
234 if (pan.tabId == this.getActivePanel().tabId) {
238 if (false === cur.fireEvent('beforedeactivate')) {
242 if(this.bullets > 0 && !Roo.isTouch){
243 this.setActiveBullet(this.indexOfPanel(pan));
246 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
248 this.transition = true;
249 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
250 var lr = dir == 'next' ? 'left' : 'right';
251 pan.el.addClass(dir); // or prev
252 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
253 cur.el.addClass(lr); // or right
257 cur.el.on('transitionend', function() {
258 Roo.log("trans end?");
260 pan.el.removeClass([lr,dir]);
263 cur.el.removeClass([lr]);
264 cur.setActive(false);
266 _this.transition = false;
268 }, this, { single: true } );
273 cur.setActive(false);
279 showPanelNext : function()
281 var i = this.indexOfPanel(this.getActivePanel());
283 if (i >= this.tabs.length - 1 && !this.autoslide) {
287 if (i >= this.tabs.length - 1 && this.autoslide) {
291 this.showPanel(this.tabs[i+1]);
294 showPanelPrev : function()
296 var i = this.indexOfPanel(this.getActivePanel());
298 if (i < 1 && !this.autoslide) {
302 if (i < 1 && this.autoslide) {
303 i = this.tabs.length;
306 this.showPanel(this.tabs[i-1]);
310 addBullet: function()
312 if(!this.bullets || Roo.isTouch){
315 var ctr = this.el.select('.carousel-bullets',true).first();
316 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
317 var bullet = ctr.createChild({
318 cls : 'bullet bullet-' + i
319 },ctr.dom.lastChild);
324 bullet.on('click', (function(e, el, o, ii, t){
330 if(this.autoslide && this.slideFn){
331 clearInterval(this.slideFn);
332 this.slideFn = window.setInterval(function() {
333 _this.showPanelNext();
337 }).createDelegate(this, [i, bullet], true));
342 setActiveBullet : function(i)
348 Roo.each(this.el.select('.bullet', true).elements, function(el){
349 el.removeClass('selected');
352 var bullet = this.el.select('.bullet-' + i, true).first();
358 bullet.addClass('selected');
369 Roo.apply(Roo.bootstrap.TabGroup, {
373 * register a Navigation Group
374 * @param {Roo.bootstrap.NavGroup} the navgroup to add
376 register : function(navgrp)
378 this.groups[navgrp.navId] = navgrp;
382 * fetch a Navigation Group based on the navigation ID
383 * if one does not exist , it will get created.
384 * @param {string} the navgroup to add
385 * @returns {Roo.bootstrap.NavGroup} the navgroup
387 get: function(navId) {
388 if (typeof(this.groups[navId]) == 'undefined') {
389 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
391 return this.groups[navId] ;