Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / core / src / dom / Element.keys.js
1 /**
2  * @class Ext.core.Element
3  */
4 Ext.core.Element.addMethods({
5     /**
6      * Convenience method for constructing a KeyMap
7      * @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:
8      * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
9      * @param {Function} fn The function to call
10      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
11      * @return {Ext.util.KeyMap} The KeyMap created
12      */
13     addKeyListener : function(key, fn, scope){
14         var config;
15         if(typeof key != 'object' || Ext.isArray(key)){
16             config = {
17                 key: key,
18                 fn: fn,
19                 scope: scope
20             };
21         }else{
22             config = {
23                 key : key.key,
24                 shift : key.shift,
25                 ctrl : key.ctrl,
26                 alt : key.alt,
27                 fn: fn,
28                 scope: scope
29             };
30         }
31         return Ext.create('Ext.util.KeyMap', this, config);
32     },
33
34     /**
35      * Creates a KeyMap for this element
36      * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
37      * @return {Ext.util.KeyMap} The KeyMap created
38      */
39     addKeyMap : function(config){
40         return Ext.create('Ext.util.KeyMap', this, config);
41     }
42 });
43
44 //Import the newly-added Ext.core.Element functions into CompositeElementLite. We call this here because
45 //Element.keys.js is the last extra Ext.core.Element include in the ext-all.js build
46 Ext.CompositeElementLite.importElementMethods();