Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / core / src / dom / Element.keys.js
diff --git a/src/core/src/dom/Element.keys.js b/src/core/src/dom/Element.keys.js
new file mode 100644 (file)
index 0000000..af02067
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * @class Ext.core.Element
+ */
+Ext.core.Element.addMethods({
+    /**
+     * Convenience method for constructing a KeyMap
+     * @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:
+     * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
+     * @param {Function} fn The function to call
+     * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
+     * @return {Ext.util.KeyMap} The KeyMap created
+     */
+    addKeyListener : function(key, fn, scope){
+        var config;
+        if(typeof key != 'object' || Ext.isArray(key)){
+            config = {
+                key: key,
+                fn: fn,
+                scope: scope
+            };
+        }else{
+            config = {
+                key : key.key,
+                shift : key.shift,
+                ctrl : key.ctrl,
+                alt : key.alt,
+                fn: fn,
+                scope: scope
+            };
+        }
+        return Ext.create('Ext.util.KeyMap', this, config);
+    },
+
+    /**
+     * Creates a KeyMap for this element
+     * @param {Object} config The KeyMap config. See {@link Ext.util.KeyMap} for more details
+     * @return {Ext.util.KeyMap} The KeyMap created
+     */
+    addKeyMap : function(config){
+        return Ext.create('Ext.util.KeyMap', this, config);
+    }
+});
+
+//Import the newly-added Ext.core.Element functions into CompositeElementLite. We call this here because
+//Element.keys.js is the last extra Ext.core.Element include in the ext-all.js build
+Ext.CompositeElementLite.importElementMethods();