3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.KeyNav"></div>/**
10 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
11 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
12 * way to implement custom navigation schemes for any UI component.</p>
13 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
14 * pageUp, pageDown, del, home, end. Usage:</p>
16 var nav = new Ext.KeyNav("my-element", {
18 this.moveLeft(e.ctrlKey);
20 "right" : function(e){
21 this.moveRight(e.ctrlKey);
23 "enter" : function(e){
30 * @param {Mixed} el The element to bind to
31 * @param {Object} config The config
33 Ext.KeyNav = function(el, config){
34 this.el = Ext.get(el);
35 Ext.apply(this, config);
42 Ext.KeyNav.prototype = {
43 <div id="cfg-Ext.KeyNav-disabled"></div>/**
44 * @cfg {Boolean} disabled
45 * True to disable this KeyNav instance (defaults to false)
48 <div id="cfg-Ext.KeyNav-defaultEventAction"></div>/**
49 * @cfg {String} defaultEventAction
50 * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
51 * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
52 * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
54 defaultEventAction: "stopEvent",
55 <div id="cfg-Ext.KeyNav-forceKeyDown"></div>/**
56 * @cfg {Boolean} forceKeyDown
57 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
58 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
59 * handle keydown instead of keypress.
64 prepareEvent : function(e){
66 var h = this.keyToHandler[k];
67 if(Ext.isSafari2 && h && k >= 37 && k <= 40){
75 var h = this.keyToHandler[k];
77 if(this.doRelay(e, this[h], h) !== true){
78 e[this.defaultEventAction]();
84 doRelay : function(e, h, hname){
85 return h.call(this.scope || this, e);
118 <div id="method-Ext.KeyNav-enable"></div>/**
123 // ie won't do special keys on keypress, no one else will repeat keys with keydown
124 // the EventObject will normalize Safari automatically
125 if(this.isKeydown()){
126 this.el.on("keydown", this.relay, this);
128 this.el.on("keydown", this.prepareEvent, this);
129 this.el.on("keypress", this.relay, this);
131 this.disabled = false;
135 <div id="method-Ext.KeyNav-disable"></div>/**
136 * Disable this KeyNav
140 if(this.isKeydown()){
141 this.el.un("keydown", this.relay, this);
143 this.el.un("keydown", this.prepareEvent, this);
144 this.el.un("keypress", this.relay, this);
146 this.disabled = true;
150 <div id="method-Ext.KeyNav-setDisabled"></div>/**
151 * Convenience function for setting disabled/enabled by boolean.
152 * @param {Boolean} disabled
154 setDisabled : function(disabled){
155 this[disabled ? "disable" : "enable"]();
159 isKeydown: function(){
160 return this.forceKeyDown || Ext.EventManager.useKeydown;