Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / core / src / dom / Element.keys.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.Element
17  */
18 Ext.Element.addMethods({
19     /**
20      * Convenience method for constructing a KeyMap
21      * @param {String/Number/Number[]/Object} 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:
22      * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
23      * @param {Function} fn The function to call
24      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
25      * @return {Ext.util.KeyMap} The KeyMap created
26      */
27     addKeyListener : function(key, fn, scope){
28         var config;
29         if(typeof key != 'object' || Ext.isArray(key)){
30             config = {
31                 key: key,
32                 fn: fn,
33                 scope: scope
34             };
35         }else{
36             config = {
37                 key : key.key,
38                 shift : key.shift,
39                 ctrl : key.ctrl,
40                 alt : key.alt,
41                 fn: fn,
42                 scope: scope
43             };
44         }
45         return Ext.create('Ext.util.KeyMap', this, config);
46     },
47
48     /**
49      * Creates a KeyMap for this element
50      * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
51      * @return {Ext.util.KeyMap} The KeyMap created
52      */
53     addKeyMap : function(config){
54         return Ext.create('Ext.util.KeyMap', this, config);
55     }
56 });
57
58 //Import the newly-added Ext.Element functions into CompositeElementLite. We call this here because
59 //Element.keys.js is the last extra Ext.Element include in the ext-all.js build
60 Ext.CompositeElementLite.importElementMethods();
61