fix menu item # triggering url change
[roojs1] / Roo / bootstrap / menu / Item.js
1 /**
2  * @class Roo.bootstrap.menu.Item
3  * @extends Roo.bootstrap.Component
4  * @children  Roo.bootstrap.Button Roo.bootstrap.ButtonUploader Roo.bootstrap.Row Roo.bootstrap.Column Roo.bootstrap.Container
5  * @parent Roo.bootstrap.menu.Menu
6  * @licence LGPL
7  * Bootstrap MenuItem class
8  * 
9  * @cfg {String} html the menu label
10  * @cfg {String} href the link
11  * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
12  * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
13  * @cfg {Boolean} active  used on sidebars to highlight active itesm
14  * @cfg {String} fa favicon to show on left of menu item.
15  * @cfg {Roo.bootsrap.Menu} menu the child menu.
16  * 
17  * 
18  * @constructor
19  * Create a new MenuItem
20  * @param {Object} config The config object
21  */
22
23
24 Roo.bootstrap.menu.Item = function(config){
25     Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
26     this.addEvents({
27         // raw events
28         /**
29          * @event click
30          * The raw click event for the entire grid.
31          * @param {Roo.bootstrap.menu.Item} this
32          * @param {Roo.EventObject} e
33          */
34         "click" : true
35     });
36 };
37
38 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component,  {
39     
40     href : false,
41     html : false,
42     preventDefault: false,
43     isContainer : false,
44     active : false,
45     fa: false,
46     
47     getAutoCreate : function(){
48         
49         if(this.isContainer){
50             return {
51                 tag: 'li',
52                 cls: 'dropdown-menu-item '
53             };
54         }
55         var ctag = {
56             tag: 'span',
57             html: 'Link'
58         };
59         
60         var anc = {
61             tag : 'a',
62             cls : 'dropdown-item',
63             href : '#',
64             cn : [  ]
65         };
66         
67         if (this.fa !== false) {
68             anc.cn.push({
69                 tag : 'i',
70                 cls : 'fa fa-' + this.fa
71             });
72         }
73         
74         anc.cn.push(ctag);
75         
76         
77         var cfg= {
78             tag: 'li',
79             cls: 'dropdown-menu-item',
80             cn: [ anc ]
81         };
82         if (this.parent().type == 'treeview') {
83             cfg.cls = 'treeview-menu';
84         }
85         if (this.active) {
86             cfg.cls += ' active';
87         }
88         
89         
90         
91         anc.href = this.href || cfg.cn[0].href ;
92         ctag.html = this.html || cfg.cn[0].html ;
93         return cfg;
94     },
95     
96     initEvents: function()
97     {
98         if (this.parent().type == 'treeview') {
99             this.el.select('a').on('click', this.onClick, this);
100         }
101         
102         if (this.menu) {
103             this.menu.parentType = this.xtype;
104             this.menu.triggerEl = this.el;
105             this.menu = this.addxtype(Roo.apply({}, this.menu));
106         }
107         
108     },
109     onClick : function(e)
110     {
111         //Roo.log('item on click ');
112         
113         if(this.href === false || this.preventDefault){
114             e.preventDefault();
115         }
116         //this.parent().hideMenuItems();
117         
118         this.fireEvent('click', this, e);
119     },
120     getEl : function()
121     {
122         return this.el;
123     } 
124 });
125
126  
127
128  
129
130