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