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