Class Ext.KeyMap
Package: | Ext |
Class: | KeyMap |
Extends: | Object |
Defined In: | KeyMap.js |
Handles mapping keys to actions for an element. One key map can be used for multiple actions.
The constructor accepts the same config object as defined by
addBinding.
If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
combination it will call the function with this signature (if the match is a multi-key
combination the callback will still be called only once): (String key, Ext.EventObject e)
A KeyMap can also handle a string representation of keys.
Usage:
// map one key by key code
var map = new Ext.KeyMap("my-element", {
key: 13, // or Ext.EventObject.ENTER
fn: myHandler,
scope: myObject
});
// map multiple keys to one action by string
var map = new Ext.KeyMap("my-element", {
key: "a\r\n\t",
fn: myHandler,
scope: myObject
});
// map multiple keys to multiple actions by strings and array of codes
var map = new Ext.KeyMap("my-element", [
{
key: [10,13],
fn: function(){ alert("Return was pressed"); }
}, {
key: "abc",
fn: function(){ alert('a, b or c was pressed'); }
}, {
key: "\t",
ctrl:true,
shift:true,
fn: function(){ alert('Control + shift + tab was pressed.'); }
}
]);
Note: A KepMap starts enabled
属性
-
方法
-
事件
公共属性
|
stopEvent : Boolean |
KeyMap |
True to stop the event from bubbling and prevent the default browser action if the
key was handled by the KeyMap (def... |
公共方法
|
KeyMap(String/HTMLElement/Ext.Element el , Object config , [String eventName ]) |
KeyMap |
|
|
addBinding(Object config ) : void |
KeyMap |
Add a new binding to this KeyMap. The following config object properties are supported:
Property Type ... |
|
disable() : void |
KeyMap |
Disable this KeyMap |
|
enable() : void |
KeyMap |
Enable this KeyMap |
|
isEnabled() : Boolean |
KeyMap |
Returns true if this KepMap is enabled |
公共事件
此类没有公共事件。
属性详情
stopEvent
public Boolean stopEvent
True to stop the event from bubbling and prevent the default browser action if the
key was handled by the KeyMap (defaults to false)
This property is defined by KeyMap.
构造函数
KeyMap
public function KeyMap(String/HTMLElement/Ext.Element el
, Object config
, [String eventName
])
方法详情
addBinding
public function addBinding(Object config
)
Add a new binding to this KeyMap. The following config object properties are supported:
Property Type Description
---------- --------------- ----------------------------------------------------------------------
key String/Array A single keycode or an array of keycodes to handle
shift Boolean True to handle key only when shift is pressed (defaults to false)
ctrl Boolean True to handle key only when ctrl is pressed (defaults to false)
alt Boolean True to handle key only when alt is pressed (defaults to false)
fn Function The function to call when KeyMap finds the expected key combination
scope Object The scope of the callback function
Usage:
// Create a KeyMap
var map = new Ext.KeyMap(document, {
key: Ext.EventObject.ENTER,
fn: handleKey,
scope: this
});
//Add a new binding to the existing KeyMap later
map.addBinding({
key: 'abc',
shift: true,
fn: handleKey,
scope: this
});
参数:
config
: ObjectA single KeyMap config
返回:
This method is defined by KeyMap.
disable
public function disable()
This method is defined by KeyMap.
enable
public function enable()
This method is defined by KeyMap.
isEnabled
public function isEnabled()
Returns true if this KepMap is enabled
This method is defined by KeyMap.