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} disable (true | false) default false
17  * @cfg {Boolean} preventDefault (true | false) default true
18  * 
19  * 
20  * @constructor
21  * Create a new Item
22  * @param {Object} config The config object
23  */
24
25
26 Roo.bootstrap.menu.Item = function(config){
27     Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
28     this.addEvents({
29         /**
30          * @event mouseover
31          * Fires when the mouse is hovering over this menu
32          * @param {Roo.bootstrap.menu.Item} this
33          * @param {Roo.EventObject} e
34          */
35         mouseover : true,
36         /**
37          * @event mouseout
38          * Fires when the mouse exits this menu
39          * @param {Roo.bootstrap.menu.Item} this
40          * @param {Roo.EventObject} e
41          */
42         mouseout : true,
43         // raw events
44         /**
45          * @event click
46          * The raw click event for the entire grid.
47          * @param {Roo.EventObject} e
48          */
49         click : true
50     });
51 };
52
53 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component,  {
54     
55     submenu : false,
56     href : '',
57     html : '',
58     preventDefault: true,
59     disable : false
60     
61     getAutoCreate : function()
62     {
63         var cfg = {
64             tag : 'li',
65             cn : [
66                 {
67                     tag : 'a',
68                     href : this.href || '#',
69                     html : this.html
70                 }
71             ]
72         };
73         
74         if(this.disable){
75             cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
76         }
77         
78         if(this.submenu){
79             cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
80         }
81         
82         return cfg;
83     },
84     
85     initEvents : function() 
86     {
87         this.el.on('mouseover', this.onMouseOver, this);
88         this.el.on('mouseout', this.onMouseOut, this);
89         
90         this.el.select('a', true).first().on('click', this.onClick, this);
91         
92     },
93     
94     onClick : function(e)
95     {
96         this.fireEvent("click", this, e);
97     },
98     
99     onMouseOver : function(e)
100     {
101         this.fireEvent("mouseover", this, e);
102     },
103     
104     onMouseOut : function(e)
105     {
106         this.fireEvent("mouseout", this, e);
107     }
108 });
109
110  
111
112