9 * @class Roo.bootstrap.NavItem
10 * @extends Roo.bootstrap.Component
11 * Bootstrap Navbar.NavItem class
12 * @cfg {String} href link to
13 * @cfg {String} html content of button
14 * @cfg {String} badge text inside badge
15 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
16 * @cfg {String} glyphicon name of glyphicon
17 * @cfg {String} icon name of font awesome icon
18 * @cfg {Boolean} active Is item active
19 * @cfg {Boolean} disabled Is item disabled
21 * @cfg {Boolean} preventDefault (true | false) default false
22 * @cfg {String} tabId the tab that this item activates.
23 * @cfg {String} tagtype (a|span) render as a href or span?
24 * @cfg {Boolean} animateRef (true|false) link to element default false
27 * Create a new Navbar Item
28 * @param {Object} config The config object
30 Roo.bootstrap.NavItem = function(config){
31 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
36 * The raw click event for the entire grid.
37 * @param {Roo.EventObject} e
42 * Fires when the active item active state changes
43 * @param {Roo.bootstrap.NavItem} this
44 * @param {boolean} state the new state
50 * Fires when scroll to element
51 * @param {Roo.bootstrap.NavItem} this
52 * @param {Object} options
53 * @param {Roo.EventObject} e
61 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
69 preventDefault : false,
76 getAutoCreate : function(){
84 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
87 cfg.cls += ' disabled';
90 if (this.href || this.html || this.glyphicon || this.icon) {
94 href : this.href || "#",
100 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
104 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
109 cfg.cn[0].html += " <span class='caret'></span>";
113 if (this.badge !== '') {
115 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
123 initEvents: function()
125 if (typeof (this.menu) != 'undefined') {
126 this.menu.parentType = this.xtype;
127 this.menu.triggerEl = this.el;
128 this.menu = this.addxtype(Roo.apply({}, this.menu));
131 this.el.select('a',true).on('click', this.onClick, this);
133 if(this.tagtype == 'span'){
134 this.el.select('span',true).on('click', this.onClick, this);
137 // at this point parent should be available..
138 this.parent().register(this);
141 onClick : function(e)
144 this.preventDefault ||
155 var tg = Roo.bootstrap.TabGroup.get(this.navId);
156 if (tg && tg.transition) {
157 Roo.log("waiting for the transitionend");
163 Roo.log("fire event clicked");
164 if(this.fireEvent('click', this, e) === false){
168 if(this.tagtype == 'span'){
171 var dom = this.el.select('a',true).dom;
172 if(this.animateRef && this.href.indexOf('#') > -1){
173 Roo.log(["test:",dom.href.split("#")[0], document.location.toString().split("#")[0]]);
174 if (dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
175 return; // ignore... - it's a 'hash' to another page.
179 this.scrollToElement(e);
183 var p = this.parent();
184 if (['tabs','pills'].indexOf(p.type)!==-1) {
185 if (typeof(p.setActiveItem) !== 'undefined') {
186 p.setActiveItem(this);
189 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
190 if (p.parentType == 'NavHeaderbar' && !this.menu) {
191 // remove the collapsed menu expand...
192 p.parent().el.select('.navbar-collapse',true).removeClass('in');
197 isActive: function () {
200 setActive : function(state, fire, is_was_active)
202 if (this.active && !state & this.navId) {
203 this.was_active = true;
204 var nv = Roo.bootstrap.NavGroup.get(this.navId);
206 nv.clearWasActive(this);
213 this.el.removeClass('active');
214 } else if (!this.el.hasClass('active')) {
215 this.el.addClass('active');
218 this.fireEvent('changed', this, state);
221 // show a panel if it's registered and related..
223 if (!this.navId || !this.tabId || !state || is_was_active) {
227 var tg = Roo.bootstrap.TabGroup.get(this.navId);
231 var pan = tg.getPanelByName(this.tabId);
235 // if we can not flip to new panel - go back to old nav highlight..
236 if (false == tg.showPanel(pan)) {
237 var nv = Roo.bootstrap.NavGroup.get(this.navId);
239 var onav = nv.getWasActive();
241 onav.setActive(true, false, true);
250 // this should not be here...
251 setDisabled : function(state)
253 this.disabled = state;
255 this.el.removeClass('disabled');
256 } else if (!this.el.hasClass('disabled')) {
257 this.el.addClass('disabled');
263 * Fetch the element to display the tooltip on.
264 * @return {Roo.Element} defaults to this.el
266 tooltipEl : function()
268 return this.el.select('' + this.tagtype + '', true).first();
271 scrollToElement : function(e)
273 var c = document.body;
275 var target = Roo.get(c).select('a[name=' + this.href.replace('#', '') +']', true).first();
281 var o = target.calcOffsetsTo(c);
288 this.fireEvent('scrollto', this, options, e);
290 Roo.get(c).scrollTo('top', options.value, true);