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