Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / core / Element.keys.js
1 /*!
2  * Ext JS Library 3.1.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.Element\r
9  */\r
10 Ext.Element.addMethods({\r
11     /**\r
12      * Convenience method for constructing a KeyMap\r
13      * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:\r
14      * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>\r
15      * @param {Function} fn The function to call\r
16      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.\r
17      * @return {Ext.KeyMap} The KeyMap created\r
18      */\r
19     addKeyListener : function(key, fn, scope){\r
20         var config;\r
21         if(!Ext.isObject(key) || Ext.isArray(key)){\r
22             config = {\r
23                 key: key,\r
24                 fn: fn,\r
25                 scope: scope\r
26             };\r
27         }else{\r
28             config = {\r
29                 key : key.key,\r
30                 shift : key.shift,\r
31                 ctrl : key.ctrl,\r
32                 alt : key.alt,\r
33                 fn: fn,\r
34                 scope: scope\r
35             };\r
36         }\r
37         return new Ext.KeyMap(this, config);\r
38     },\r
39 \r
40     /**\r
41      * Creates a KeyMap for this element\r
42      * @param {Object} config The KeyMap config. See {@link Ext.KeyMap} for more details\r
43      * @return {Ext.KeyMap} The KeyMap created\r
44      */\r
45     addKeyMap : function(config){\r
46         return new Ext.KeyMap(this, config);\r
47     }\r
48 });