3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.KeyNav"></div>/**
17 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
18 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
19 * way to implement custom navigation schemes for any UI component.</p>
20 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
21 * pageUp, pageDown, del, home, end. Usage:</p>
23 var nav = new Ext.KeyNav("my-element", {
25 this.moveLeft(e.ctrlKey);
27 "right" : function(e){
28 this.moveRight(e.ctrlKey);
30 "enter" : function(e){
37 * @param {Mixed} el The element to bind to
38 * @param {Object} config The config
40 Ext.KeyNav = function(el, config){
41 this.el = Ext.get(el);
42 Ext.apply(this, config);
49 Ext.KeyNav.prototype = {
50 <div id="cfg-Ext.KeyNav-disabled"></div>/**
51 * @cfg {Boolean} disabled
52 * True to disable this KeyNav instance (defaults to false)
55 <div id="cfg-Ext.KeyNav-defaultEventAction"></div>/**
56 * @cfg {String} defaultEventAction
57 * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
58 * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
59 * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
61 defaultEventAction: "stopEvent",
62 <div id="cfg-Ext.KeyNav-forceKeyDown"></div>/**
63 * @cfg {Boolean} forceKeyDown
64 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
65 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
66 * handle keydown instead of keypress.
73 var h = this.keyToHandler[k];
75 if(this.doRelay(e, this[h], h) !== true){
76 e[this.defaultEventAction]();
82 doRelay : function(e, h, hname){
83 return h.call(this.scope || this, e);
116 stopKeyUp: function(e) {
119 if (k >= 37 && k <= 40) {
120 // *** bugfix - safari 2.x fires 2 keyup events on cursor keys
121 // *** (note: this bugfix sacrifices the "keyup" event originating from keyNav elements in Safari 2)
126 <div id="method-Ext.KeyNav-destroy"></div>/**
127 * Destroy this KeyNav (this is the same as calling disable).
133 <div id="method-Ext.KeyNav-enable"></div>/**
139 // call stopKeyUp() on "keyup" event
140 this.el.on('keyup', this.stopKeyUp, this);
143 this.el.on(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
144 this.disabled = false;
148 <div id="method-Ext.KeyNav-disable"></div>/**
149 * Disable this KeyNav
151 disable: function() {
152 if (!this.disabled) {
154 // remove "keyup" event handler
155 this.el.un('keyup', this.stopKeyUp, this);
158 this.el.un(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
159 this.disabled = true;
163 <div id="method-Ext.KeyNav-setDisabled"></div>/**
164 * Convenience function for setting disabled/enabled by boolean.
165 * @param {Boolean} disabled
167 setDisabled : function(disabled){
168 this[disabled ? "disable" : "enable"]();
172 isKeydown: function(){
173 return this.forceKeyDown || Ext.EventManager.useKeydown;