remove debugging code
[roojs1] / Roo / menu / BaseItem.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12
13 /**
14  * @class Roo.menu.BaseItem
15  * @extends Roo.Component
16  * The base class for all items that render into menus.  BaseItem provides default rendering, activated state
17  * management and base configuration options shared by all menu components.
18  * @constructor
19  * Creates a new BaseItem
20  * @param {Object} config Configuration options
21  */
22 Roo.menu.BaseItem = function(config){
23     Roo.menu.BaseItem.superclass.constructor.call(this, config);
24
25     this.addEvents({
26         /**
27          * @event click
28          * Fires when this item is clicked
29          * @param {Roo.menu.BaseItem} this
30          * @param {Roo.EventObject} e
31          */
32         click: true,
33         /**
34          * @event activate
35          * Fires when this item is activated
36          * @param {Roo.menu.BaseItem} this
37          */
38         activate : true,
39         /**
40          * @event deactivate
41          * Fires when this item is deactivated
42          * @param {Roo.menu.BaseItem} this
43          */
44         deactivate : true
45     });
46
47     if(this.handler){
48         this.on("click", this.handler, this.scope, true);
49     }
50 };
51
52 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
53     /**
54      * @cfg {Function} handler
55      * A function that will handle the click event of this menu item (defaults to undefined)
56      */
57     /**
58      * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
59      */
60     canActivate : false,
61     
62      /**
63      * @cfg {Boolean} hidden True to prevent creation of this menu item (defaults to false)
64      */
65     hidden: false,
66     
67     /**
68      * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
69      */
70     activeClass : "x-menu-item-active",
71     /**
72      * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
73      */
74     hideOnClick : true,
75     /**
76      * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
77      */
78     hideDelay : 100,
79
80     // private
81     ctype: "Roo.menu.BaseItem",
82
83     // private
84     actionMode : "container",
85
86     // private
87     render : function(container, parentMenu){
88         this.parentMenu = parentMenu;
89         Roo.menu.BaseItem.superclass.render.call(this, container);
90         this.container.menuItemId = this.id;
91     },
92
93     // private
94     onRender : function(container, position){
95         this.el = Roo.get(this.el);
96         container.dom.appendChild(this.el.dom);
97     },
98
99     // private
100     onClick : function(e){
101         if(!this.disabled && this.fireEvent("click", this, e) !== false
102                 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
103             this.handleClick(e);
104         }else{
105             e.stopEvent();
106         }
107     },
108
109     // private
110     activate : function(){
111         if(this.disabled){
112             return false;
113         }
114         var li = this.container;
115         li.addClass(this.activeClass);
116         this.region = li.getRegion().adjust(2, 2, -2, -2);
117         this.fireEvent("activate", this);
118         return true;
119     },
120
121     // private
122     deactivate : function(){
123         this.container.removeClass(this.activeClass);
124         this.fireEvent("deactivate", this);
125     },
126
127     // private
128     shouldDeactivate : function(e){
129         return !this.region || !this.region.contains(e.getPoint());
130     },
131
132     // private
133     handleClick : function(e){
134         if(this.hideOnClick){
135             this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
136         }
137     },
138
139     // private
140     expandMenu : function(autoActivate){
141         // do nothing
142     },
143
144     // private
145     hideMenu : function(){
146         // do nothing
147     }
148 });