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();
143 getChildContainer : function()
145 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
149 * register a Navigation item
150 * @param {Roo.bootstrap.NavItem} the navitem to add
152 register : function(item)
154 this.tabs.push( item);
155 item.navId = this.navId; // not really needed..
160 getActivePanel : function()
163 Roo.each(this.tabs, function(t) {
173 getPanelByName : function(n)
176 Roo.each(this.tabs, function(t) {
185 indexOfPanel : function(p)
188 Roo.each(this.tabs, function(t,i) {
189 if (t.tabId == p.tabId) {
198 * show a specific panel
199 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
200 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
202 showPanel : function (pan)
204 if(this.transition || typeof(pan) == 'undefined'){
205 Roo.log("waiting for the transitionend");
209 if (typeof(pan) == 'number') {
210 pan = this.tabs[pan];
213 if (typeof(pan) == 'string') {
214 pan = this.getPanelByName(pan);
217 var cur = this.getActivePanel();
220 Roo.log('pan or acitve pan is undefined');
224 if (pan.tabId == this.getActivePanel().tabId) {
228 if (false === cur.fireEvent('beforedeactivate')) {
232 if(this.bullets > 0 && !Roo.isTouch){
233 this.setActiveBullet(this.indexOfPanel(pan));
236 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
238 //class="carousel-item carousel-item-next carousel-item-left"
240 this.transition = true;
241 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
242 var lr = dir == 'next' ? 'left' : 'right';
243 pan.el.addClass(dir); // or prev
244 pan.el.addClass('carousel-item-' + dir); // or prev
245 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
246 cur.el.addClass(lr); // or right
248 cur.el.addClass('carousel-item-' +lr); // or right
249 pan.el.addClass('carousel-item-' +lr);
253 cur.el.on('transitionend', function() {
254 Roo.log("trans end?");
256 pan.el.removeClass([lr,dir, 'carousel-item-' + lr, 'carousel-item-' + dir]);
259 cur.el.removeClass([lr, 'carousel-item-' + lr]);
260 cur.setActive(false);
262 _this.transition = false;
264 }, this, { single: true } );
269 cur.setActive(false);
275 showPanelNext : function()
277 var i = this.indexOfPanel(this.getActivePanel());
279 if (i >= this.tabs.length - 1 && !this.autoslide) {
283 if (i >= this.tabs.length - 1 && this.autoslide) {
287 this.showPanel(this.tabs[i+1]);
290 showPanelPrev : function()
292 var i = this.indexOfPanel(this.getActivePanel());
294 if (i < 1 && !this.autoslide) {
298 if (i < 1 && this.autoslide) {
299 i = this.tabs.length;
302 this.showPanel(this.tabs[i-1]);
306 addBullet: function()
308 if(!this.bullets || Roo.isTouch){
311 var ctr = this.el.select('.carousel-bullets',true).first();
312 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
313 var bullet = ctr.createChild({
314 cls : 'bullet bullet-' + i
315 },ctr.dom.lastChild);
320 bullet.on('click', (function(e, el, o, ii, t){
326 if(this.autoslide && this.slideFn){
327 clearInterval(this.slideFn);
328 this.slideFn = window.setInterval(function() {
329 _this.showPanelNext();
333 }).createDelegate(this, [i, bullet], true));
338 setActiveBullet : function(i)
344 Roo.each(this.el.select('.bullet', true).elements, function(el){
345 el.removeClass('selected');
348 var bullet = this.el.select('.bullet-' + i, true).first();
354 bullet.addClass('selected');
365 Roo.apply(Roo.bootstrap.TabGroup, {
369 * register a Navigation Group
370 * @param {Roo.bootstrap.NavGroup} the navgroup to add
372 register : function(navgrp)
374 this.groups[navgrp.navId] = navgrp;
378 * fetch a Navigation Group based on the navigation ID
379 * if one does not exist , it will get created.
380 * @param {string} the navgroup to add
381 * @returns {Roo.bootstrap.NavGroup} the navgroup
383 get: function(navId) {
384 if (typeof(this.groups[navId]) == 'undefined') {
385 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
387 return this.groups[navId] ;