3
* Copyright(c) 2006-2010 Ext JS, Inc.
5
* http://www.extjs.com/license
9
* <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
10
* navigation keys to function calls that will get called when the keys are pressed, providing an easy
11
* way to implement custom navigation schemes for any UI component.</p>
12
* <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
13
* pageUp, pageDown, del, home, end. Usage:</p>
15
var nav = new Ext.KeyNav("my-element", {
17
this.moveLeft(e.ctrlKey);
19
"right" : function(e){
20
this.moveRight(e.ctrlKey);
22
"enter" : function(e){
29
* @param {Mixed} el The element to bind to
30
* @param {Object} config The config
32
Ext.KeyNav = function(el, config){
33
this.el = Ext.get(el);
34
Ext.apply(this, config);
41
Ext.KeyNav.prototype = {
43
* @cfg {Boolean} disabled
44
* True to disable this KeyNav instance (defaults to false)
48
* @cfg {String} defaultEventAction
49
* The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
50
* {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
51
* {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
53
defaultEventAction: "stopEvent",
55
* @cfg {Boolean} forceKeyDown
56
* Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
57
* IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
58
* handle keydown instead of keypress.
65
var h = this.keyToHandler[k];
67
if(this.doRelay(e, this[h], h) !== true){
68
e[this.defaultEventAction]();
74
doRelay : function(e, h, hname){
75
return h.call(this.scope || this, e);
108
stopKeyUp: function(e) {
111
if (k >= 37 && k <= 40) {
112
// *** bugfix - safari 2.x fires 2 keyup events on cursor keys
113
// *** (note: this bugfix sacrifices the "keyup" event originating from keyNav elements in Safari 2)
119
* Destroy this KeyNav (this is the same as calling disable).
131
// call stopKeyUp() on "keyup" event
132
this.el.on('keyup', this.stopKeyUp, this);
135
this.el.on(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
136
this.disabled = false;
141
* Disable this KeyNav
143
disable: function() {
144
if (!this.disabled) {
146
// remove "keyup" event handler
147
this.el.un('keyup', this.stopKeyUp, this);
150
this.el.un(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
151
this.disabled = true;
156
* Convenience function for setting disabled/enabled by boolean.
157
* @param {Boolean} disabled
159
setDisabled : function(disabled){
160
this[disabled ? "disable" : "enable"]();
164
isKeydown: function(){
165
return this.forceKeyDown || Ext.EventManager.useKeydown;