Roo/bootstrap/MenuItem.js
[roojs1] / Roo / bootstrap / MenuItem.js
1 /*
2  * - LGPL
3  *
4  * menu item
5  * 
6  */
7
8
9 /**
10  * @class Roo.bootstrap.MenuItem
11  * @extends Roo.bootstrap.Component
12  * Bootstrap MenuItem class
13  * @cfg {String} html the menu label
14  * @cfg {String} href the link
15  * @cfg {Boolean} preventDefault (true | false) default true
16  * @cfg {Boolean} isContainer (true | false) default false
17  * 
18  * 
19  * @constructor
20  * Create a new MenuItem
21  * @param {Object} config The config object
22  */
23
24
25 Roo.bootstrap.MenuItem = function(config){
26     Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
27     this.addEvents({
28         // raw events
29         /**
30          * @event click
31          * The raw click event for the entire grid.
32          * @param {Roo.bootstrap.MenuItem} this
33          * @param {Roo.EventObject} e
34          */
35         "click" : true
36     });
37 };
38
39 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component,  {
40     
41     href : false,
42     html : false,
43     preventDefault: true,
44     isContainer : false,
45     
46     getAutoCreate : function(){
47         
48         if(this.isContainer){
49             return {
50                 tag: 'li',
51                 cls: 'dropdown-menu-item'
52             };
53         }
54         
55         var cfg= {
56             tag: 'li',
57             cls: 'dropdown-menu-item',
58             cn: [
59                     {
60                         tag : 'a',
61                         href : '#',
62                         html : 'Link'
63                     }
64                 ]
65         };
66         if (this.parent().type == 'treeview') {
67             cfg.cls = 'treeview-menu';
68         }
69         
70         cfg.cn[0].href = this.href || cfg.cn[0].href ;
71         cfg.cn[0].html = this.html || cfg.cn[0].html ;
72         return cfg;
73     },
74     
75     initEvents: function() {
76         
77         //this.el.select('a').on('click', this.onClick, this);
78         
79     },
80     onClick : function(e)
81     {
82         Roo.log('item on click ');
83         //if(this.preventDefault){
84         //    e.preventDefault();
85         //}
86         //this.parent().hideMenuItems();
87         
88         this.fireEvent('click', this, e);
89     },
90     getEl : function()
91     {
92         return this.el;
93     }
94 });
95
96  
97
98