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