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?
26 * Create a new Navbar Item
27 * @param {Object} config The config object
29 Roo.bootstrap.NavItem = function(config){
30 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
35 * The raw click event for the entire grid.
36 * @param {Roo.EventObject} e
41 * Fires when the active item active state changes
42 * @param {Roo.bootstrap.NavItem} this
43 * @param {boolean} state the new state
51 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
59 preventDefault : false,
64 getAutoCreate : function(){
72 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
75 cfg.cls += ' disabled';
77 if (this.href || this.html) {
81 href : this.href || "#",
86 // glyphicon and icon go before content..
87 if (this.glyphicon || this.icon) {
89 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
91 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
97 if (cfg.cn && this.menu) {
99 cfg.cn[0].html += " <span class='caret'></span>";
103 if (this.badge !== '') {
105 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
113 initEvents: function() {
114 // Roo.log('init events?');
115 // Roo.log(this.el.dom);
116 if (typeof (this.menu) != 'undefined') {
117 this.menu.parentType = this.xtype;
118 this.menu.triggerEl = this.el;
119 this.addxtype(Roo.apply({}, this.menu));
123 this.el.select('a',true).on('click', this.onClick, this);
124 // at this point parent should be available..
125 this.parent().register(this);
128 onClick : function(e)
131 if(this.preventDefault){
137 Roo.log("fire event clicked");
138 if(this.fireEvent('click', this, e) === false){
142 if (['tabs','pills'].indexOf(this.parent().type)!==-1) {
143 if (typeof(this.parent().setActiveItem) !== 'undefined') {
144 this.parent().setActiveItem(this);
152 isActive: function () {
155 setActive : function(state, fire)
159 this.el.removeClass('active');
160 } else if (!this.el.hasClass('active')) {
161 this.el.addClass('active');
164 this.fireEvent('changed', this, state);
169 // this should not be here...
170 setDisabled : function(state)
172 this.disabled = state;
174 this.el.removeClass('disabled');
175 } else if (!this.el.hasClass('disabled')) {
176 this.el.addClass('disabled');