3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.KeyNav"></div>/**
11 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
12 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
13 * way to implement custom navigation schemes for any UI component.</p>
14 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
15 * pageUp, pageDown, del, home, end. Usage:</p>
17 var nav = new Ext.KeyNav("my-element", {
19 this.moveLeft(e.ctrlKey);
21 "right" : function(e){
22 this.moveRight(e.ctrlKey);
24 "enter" : function(e){
31 * @param {Mixed} el The element to bind to
32 * @param {Object} config The config
34 Ext.KeyNav = function(el, config){
35 this.el = Ext.get(el);
36 Ext.apply(this, config);
43 Ext.KeyNav.prototype = {
44 <div id="cfg-Ext.KeyNav-disabled"></div>/**
45 * @cfg {Boolean} disabled
46 * True to disable this KeyNav instance (defaults to false)
49 <div id="cfg-Ext.KeyNav-defaultEventAction"></div>/**
50 * @cfg {String} defaultEventAction
51 * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
52 * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
53 * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
55 defaultEventAction: "stopEvent",
56 <div id="cfg-Ext.KeyNav-forceKeyDown"></div>/**
57 * @cfg {Boolean} forceKeyDown
58 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
59 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
60 * handle keydown instead of keypress.
67 var h = this.keyToHandler[k];
69 if(this.doRelay(e, this[h], h) !== true){
70 e[this.defaultEventAction]();
76 doRelay : function(e, h, hname){
77 return h.call(this.scope || this, e);
110 stopKeyUp: function(e) {
113 if (k >= 37 && k <= 40) {
114 // *** bugfix - safari 2.x fires 2 keyup events on cursor keys
115 // *** (note: this bugfix sacrifices the "keyup" event originating from keyNav elements in Safari 2)
120 <div id="method-Ext.KeyNav-destroy"></div>/**
121 * Destroy this KeyNav (this is the same as calling disable).
127 <div id="method-Ext.KeyNav-enable"></div>/**
133 // call stopKeyUp() on "keyup" event
134 this.el.on('keyup', this.stopKeyUp, this);
137 this.el.on(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
138 this.disabled = false;
142 <div id="method-Ext.KeyNav-disable"></div>/**
143 * Disable this KeyNav
145 disable: function() {
146 if (!this.disabled) {
148 // remove "keyup" event handler
149 this.el.un('keyup', this.stopKeyUp, this);
152 this.el.un(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
153 this.disabled = true;
157 <div id="method-Ext.KeyNav-setDisabled"></div>/**
158 * Convenience function for setting disabled/enabled by boolean.
159 * @param {Boolean} disabled
161 setDisabled : function(disabled){
162 this[disabled ? "disable" : "enable"]();
166 isKeydown: function(){
167 return this.forceKeyDown || Ext.EventManager.useKeydown;