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