2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
11 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
\r
12 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
\r
13 * way to implement custom navigation schemes for any UI component.</p>
\r
14 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
\r
15 * pageUp, pageDown, del, home, end. Usage:</p>
\r
17 var nav = new Ext.KeyNav("my-element", {
\r
18 "left" : function(e){
\r
19 this.moveLeft(e.ctrlKey);
\r
21 "right" : function(e){
\r
22 this.moveRight(e.ctrlKey);
\r
24 "enter" : function(e){
\r
31 * @param {Mixed} el The element to bind to
\r
32 * @param {Object} config The config
\r
34 Ext.KeyNav = function(el, config){
\r
35 this.el = Ext.get(el);
\r
36 Ext.apply(this, config);
\r
38 this.disabled = true;
\r
43 Ext.KeyNav.prototype = {
\r
45 * @cfg {Boolean} disabled
\r
46 * True to disable this KeyNav instance (defaults to false)
\r
50 * @cfg {String} defaultEventAction
\r
51 * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
\r
52 * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
\r
53 * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
\r
55 defaultEventAction: "stopEvent",
\r
57 * @cfg {Boolean} forceKeyDown
\r
58 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
\r
59 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
\r
60 * handle keydown instead of keypress.
\r
62 forceKeyDown : false,
\r
65 prepareEvent : function(e){
\r
67 var h = this.keyToHandler[k];
\r
69 // e.stopPropagation();
\r
71 if(Ext.isSafari2 && h && k >= 37 && k <= 40){
\r
77 relay : function(e){
\r
79 var h = this.keyToHandler[k];
\r
81 if(this.doRelay(e, this[h], h) !== true){
\r
82 e[this.defaultEventAction]();
\r
88 doRelay : function(e, h, hname){
\r
89 return h.call(this.scope || this, e);
\r
92 // possible handlers
\r
106 // quick lookup hash
\r
123 * Enable this KeyNav
\r
125 enable: function(){
\r
127 if(this.forceKeyDown || Ext.isIE || Ext.isSafari3 || Ext.isAir){
\r
128 this.el.on("keydown", this.relay, this);
\r
130 this.el.on("keydown", this.prepareEvent, this);
\r
131 this.el.on("keypress", this.relay, this);
\r
133 this.disabled = false;
\r
138 * Disable this KeyNav
\r
140 disable: function(){
\r
141 if(!this.disabled){
\r
142 if(this.forceKeyDown || Ext.isIE || Ext.isSafari3 || Ext.isAir){
\r
143 this.el.un("keydown", this.relay, this);
\r
145 this.el.un("keydown", this.prepareEvent, this);
\r
146 this.el.un("keypress", this.relay, this);
\r
148 this.disabled = true;
\r