module Ext_util_KeyMap:Handles mapping key events to handling functions f ...sig
..end
Handles mapping key events to handling functions for an element or a Component. One KeyMap can be used for multiple actions.
A KeyMap must be configured with a target as an event source which may be an Element or a Component.
If the target is an element, then the keydown
event will trigger the invocation of bindings.
It is possible to configure the KeyMap with a custom eventName to listen for. This may be useful when the target is a Component.
The KeyMap's event handling requires that the first parameter passed is a key event. So if the Component's event signature is different, specify a processEvent configuration which accepts the event's parameters and returns a key event.
Functions specified in bindings are called with this signature : (String key, Ext.EventObject e)
(if the
match is a multi-key combination the callback will still be called only once). A KeyMap can also handle a string
representation of keys. By default KeyMap starts enabled.
Usage:
// map one key by key code
var map = new Ext.util.KeyMap({
target: "my-element",
key: 13, // or Ext.EventObject.ENTER
fn: myHandler,
scope: myObject
});
// map multiple keys to one action by string
var map = new Ext.util.KeyMap({
target: "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.util.KeyMap({
target: "my-element",
binding: [{
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.'); }
}]
});
Since 4.1.0, KeyMaps can bind to Components and process key-based events fired by Components.
To bind to a Component, use the single parameter form of constructor and include the Component event name
to listen for, and a processEvent
implementation which returns the key event for further processing by
the KeyMap:
var map = new Ext.util.KeyMap({
target: myGridView,
eventName: 'itemkeydown',
processEvent: function(view, record, node, index, event) {
// Load the event with the extra information needed by the mappings
event.view = view;
event.store = view.getStore();
event.record = record;
event.index = index;
return event;
},
binding: {
key: Ext.EventObject.DELETE,
fn: function(keyCode, e) {
e.store.remove(e.record);
// Attempt to select the record that's now in its place
e.view.getSelectionModel().select(e.index);
e.view.el.focus();
}
}
});
class type t =object
..end
class type configs =object
..end
class type events =object
..end
class type statics =object
..end
val of_configs : configs Js.t -> t Js.t
of_configs c
casts a config object c
to an instance of class t
val to_configs : t Js.t -> configs Js.t
to_configs o
casts instance o
of class t
to a config object