Ext.KeyMap.html
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<div class="body-wrap">
<div class="top-tools">
<a class="inner-link" href="#Ext.KeyMap-props"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-prop">Properties</a>
<a class="inner-link" href="#Ext.KeyMap-methods"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-method">Methods</a>
<a class="inner-link" href="#Ext.KeyMap-events"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-event">Events</a>
<a class="bookmark" href="../docs/?class=Ext.KeyMap"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-fav">Direct Link</a>
</div>
<h1>Class Ext.KeyMap</h1>
<table cellspacing="0">
<tr><td class="label">Package:</td><td class="hd-info">Ext</td></tr>
<tr><td class="label">Defined In:</td><td class="hd-info"><a href="../source/util/KeyMap_wev8.js" target="_blank">KeyMap_wev8.js</a></td></tr>
<tr><td class="label">Class:</td><td class="hd-info">KeyMap</td></tr>
<tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
</table>
<div class="description">
Handles mapping keys to actions for an element. One key map can be used for multiple actions.
The constructor accepts the same config object as defined by <a ext:cls="Ext.KeyMap" ext:member="addBinding" href="output/Ext.KeyMap.html#addBinding">addBinding</a>.
If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
combination it will call the function with this signature (if the match is a multi-key
combination the callback will still be called only once): (String key, Ext.EventObject e)
A KeyMap can also handle a string representation of keys.<br />
Usage:
<pre><code><i>// map one key by key code</i>
<b>var</b> map = <b>new</b> Ext.KeyMap(<em>"my-element"</em>, {
key: 13, <i>// or Ext.EventObject.ENTER</i>
fn: myHandler,
scope: myObject
});
<i>// map multiple keys to one action by string</i>
<b>var</b> map = <b>new</b> Ext.KeyMap(<em>"my-element"</em>, {
key: <em>"a\r\n\t"</em>,
fn: myHandler,
scope: myObject
});
<i>// map multiple keys to multiple actions by strings and array of codes</i>
<b>var</b> map = <b>new</b> Ext.KeyMap(<em>"my-element"</em>, [
{
key: [10,13],
fn: <b>function</b>(){ alert(<em>"Return was pressed"</em>); }
}, {
key: <em>"abc"</em>,
fn: <b>function</b>(){ alert(<em>'a, b or c was pressed'</em>); }
}, {
key: <em>"\t"</em>,
ctrl:true,
shift:true,
fn: <b>function</b>(){ alert(<em>'Control + shift + tab was pressed.'</em>); }
}
]);</code></pre>
<b>Note: A KeyMap starts enabled</b> </div>
<div class="hr"></div>
<a id="Ext.KeyMap-props"></a>
<h2>Public Properties</h2>
<table cellspacing="0" class="member-table">
<tr>
<th class="sig-header" colspan="2">Property</th>
<th class="msource-header">Defined By</th>
</tr>
<tr class="property-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-stopEvent"></a>
<b>stopEvent</b> : Boolean <div class="mdesc">
<div class="short">True to stop the event from bubbling and prevent the default browser action if the
key was handled by the KeyMap (def...</div>
<div class="long">
True to stop the event from bubbling and prevent the default browser action if the
key was handled by the KeyMap (defaults to false) </div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
</table>
<a id="Ext.KeyMap-methods"></a>
<h2>Public Methods</h2>
<table cellspacing="0" class="member-table">
<tr>
<th class="sig-header" colspan="2">Method</th>
<th class="msource-header">Defined By</th>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-KeyMap"></a>
<b>KeyMap</b>( <code>Mixed el</code>, <code>Object config</code>, <span class="optional" title="Optional">[<code>String eventName</code>]</span> ) <div class="mdesc">
<div class="short"></div>
<div class="long">
<div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The element to bind to</div></li><li><code>config</code> : Object<div class="sub-desc">The config (see <a ext:cls="Ext.KeyMap" ext:member="addBinding" href="output/Ext.KeyMap.html#addBinding">addBinding</a>)</div></li><li><code>eventName</code> : String<div class="sub-desc">(optional) The event to bind to (defaults to "keydown")</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code></code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-addBinding"></a>
<b>addBinding</b>( <code>Object/Array config</code> ) : void <div class="mdesc">
<div class="short">Add a new binding to this KeyMap. The following config object properties are supported:
Property Type ...</div>
<div class="long">
Add a new binding to this KeyMap. The following config object properties are supported:
<pre>Property Type Description
---------- --------------- ----------------------------------------------------------------------
key String/Array A single keycode or an array of keycodes to handle
shift Boolean True to handle key only when shift is pressed (defaults to false)
ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
alt Boolean True to handle key only when alt is pressed (defaults to false)
handler Function The function to call when KeyMap finds the expected key combination
fn Function Alias of handler (for backwards-compatibility)
scope Object The scope of the callback function</pre>
Usage:
<pre><code><i>// Create a KeyMap</i>
<b>var</b> map = <b>new</b> Ext.KeyMap(document, {
key: Ext.EventObject.ENTER,
fn: handleKey,
scope: <b>this</b>
});
<i>//Add a <b>new</b> binding to the existing KeyMap later</i>
map.addBinding({
key: <em>'abc'</em>,
shift: true,
fn: handleKey,
scope: <b>this</b>
});</code></pre> <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>config</code> : Object/Array<div class="sub-desc">A single KeyMap config or an array of configs</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>void</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-disable"></a>
<b>disable</b>() : void <div class="mdesc">
<div class="short">Disable this KeyMap</div>
<div class="long">
Disable this KeyMap <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li>None.</li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>void</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-enable"></a>
<b>enable</b>() : void <div class="mdesc">
<div class="short">Enables this KeyMap</div>
<div class="long">
Enables this KeyMap <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li>None.</li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>void</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-isEnabled"></a>
<b>isEnabled</b>() : Boolean <div class="mdesc">
<div class="short">Returns true if this KeyMap is enabled</div>
<div class="long">
Returns true if this KeyMap is enabled <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li>None.</li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>Boolean</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.KeyMap-on"></a>
<b>on</b>( <code>Number/Array/Object key</code>, <code>Function fn</code>, <span class="optional" title="Optional">[<code>Object scope</code>]</span> ) : void <div class="mdesc">
<div class="short">Shorthand for adding a single key listener</div>
<div class="long">
Shorthand for adding a single key listener <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>key</code> : Number/Array/Object<div class="sub-desc">Either the numeric key code, array of key codes or an object with the
following options:
{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</div></li><li><code>fn</code> : Function<div class="sub-desc">The function to call</div></li><li><code>scope</code> : Object<div class="sub-desc">(optional) The scope of the function</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>void</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">KeyMap</td>
</tr>
</table>
<a id="Ext.KeyMap-events"></a>
<h2>Public Events</h2>
<div class="no-members">This class has no public events.</div>
</div>