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 DEPRICATED - use fa
17 * @cfg {String} icon DEPRICATED - use fa
18 * @cfg {String} fa - Fontawsome icon name (can add stuff to it like fa-2x)
19 * @cfg {Boolean} active Is item active
20 * @cfg {Boolean} disabled Is item disabled
22 * @cfg {Boolean} preventDefault (true | false) default false
23 * @cfg {String} tabId the tab that this item activates.
24 * @cfg {String} tagtype (a|span) render as a href or span?
25 * @cfg {Boolean} animateRef (true|false) link to element default false
28 * Create a new Navbar Item
29 * @param {Object} config The config object
31 Roo.bootstrap.NavItem = function(config){
32 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
37 * The raw click event for the entire grid.
38 * @param {Roo.EventObject} e
43 * Fires when the active item active state changes
44 * @param {Roo.bootstrap.NavItem} this
45 * @param {boolean} state the new state
51 * Fires when scroll to element
52 * @param {Roo.bootstrap.NavItem} this
53 * @param {Object} options
54 * @param {Roo.EventObject} e
62 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
71 preventDefault : false,
81 getAutoCreate : function(){
90 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
93 cfg.cls += ' disabled';
96 if (this.href || this.html || this.glyphicon || this.icon || this.fa) {
100 href : this.href || "#",
101 html: this.html || ''
104 if (this.tagtype == 'a') {
105 cfg.cn[0].cls = 'nav-link';
108 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
111 cfg.cn[0].html = '<i class="fa fas fa-'+this.fa+'"></i> <span>' + cfg.cn[0].html + '</span>'
114 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
119 cfg.cn[0].html += " <span class='caret'></span>";
123 if (this.badge !== '') {
125 cfg.cn[0].html += ' <span class="badge badge-secondary">' + this.badge + '</span>';
133 onRender : function(ct, position)
135 // Roo.log("Call onRender: " + this.xtype);
136 if (Roo.bootstrap.version == 4 && ct.dom.type != 'ul') {
140 return Roo.bootstrap.NavItem.superclass.onRender.call(this, ct, position);
144 initEvents: function()
146 if (typeof (this.menu) != 'undefined') {
147 this.menu.parentType = this.xtype;
148 this.menu.triggerEl = this.el;
149 this.menu = this.addxtype(Roo.apply({}, this.menu));
152 this.el.select('a',true).on('click', this.onClick, this);
154 if(this.tagtype == 'span'){
155 this.el.select('span',true).on('click', this.onClick, this);
158 // at this point parent should be available..
159 this.parent().register(this);
162 onClick : function(e)
164 if (e.getTarget('.dropdown-menu-item')) {
165 // did you click on a menu itemm.... - then don't trigger onclick..
170 this.preventDefault ||
173 Roo.log("NavItem - prevent Default?");
181 var tg = Roo.bootstrap.TabGroup.get(this.navId);
182 if (tg && tg.transition) {
183 Roo.log("waiting for the transitionend");
189 //Roo.log("fire event clicked");
190 if(this.fireEvent('click', this, e) === false){
194 if(this.tagtype == 'span'){
198 //Roo.log(this.href);
199 var ael = this.el.select('a',true).first();
202 if(ael && this.animateRef && this.href.indexOf('#') > -1){
203 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
204 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
205 return; // ignore... - it's a 'hash' to another page.
207 Roo.log("NavItem - prevent Default?");
209 this.scrollToElement(e);
213 var p = this.parent();
215 if (['tabs','pills'].indexOf(p.type)!==-1) {
216 if (typeof(p.setActiveItem) !== 'undefined') {
217 p.setActiveItem(this);
221 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
222 if (p.parentType == 'NavHeaderbar' && !this.menu) {
223 // remove the collapsed menu expand...
224 p.parent().el.select('.navbar-collapse',true).removeClass('in');
228 isActive: function () {
231 setActive : function(state, fire, is_was_active)
233 if (this.active && !state && this.navId) {
234 this.was_active = true;
235 var nv = Roo.bootstrap.NavGroup.get(this.navId);
237 nv.clearWasActive(this);
244 this.el.removeClass('active');
245 } else if (!this.el.hasClass('active')) {
246 this.el.addClass('active');
249 this.fireEvent('changed', this, state);
252 // show a panel if it's registered and related..
254 if (!this.navId || !this.tabId || !state || is_was_active) {
258 var tg = Roo.bootstrap.TabGroup.get(this.navId);
262 var pan = tg.getPanelByName(this.tabId);
266 // if we can not flip to new panel - go back to old nav highlight..
267 if (false == tg.showPanel(pan)) {
268 var nv = Roo.bootstrap.NavGroup.get(this.navId);
270 var onav = nv.getWasActive();
272 onav.setActive(true, false, true);
281 // this should not be here...
282 setDisabled : function(state)
284 this.disabled = state;
286 this.el.removeClass('disabled');
287 } else if (!this.el.hasClass('disabled')) {
288 this.el.addClass('disabled');
294 * Fetch the element to display the tooltip on.
295 * @return {Roo.Element} defaults to this.el
297 tooltipEl : function()
299 return this.el.select('' + this.tagtype + '', true).first();
302 scrollToElement : function(e)
304 var c = document.body;
307 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
309 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
310 c = document.documentElement;
313 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
319 var o = target.calcOffsetsTo(c);
326 this.fireEvent('scrollto', this, options, e);
328 Roo.get(c).scrollTo('top', options.value, true);