4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-util-KeyNav'>/**
19 </span> * @class Ext.util.KeyNav
20 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
21 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
22 * way to implement custom navigation schemes for any UI component.</p>
23 * <p>The following are all of the possible keys that can be implemented: enter, space, left, right, up, down, tab, esc,
24 * pageUp, pageDown, del, backspace, home, end. Usage:</p>
25 <pre><code>
26 var nav = new Ext.util.KeyNav("my-element", {
27 "left" : function(e){
28 this.moveLeft(e.ctrlKey);
30 "right" : function(e){
31 this.moveRight(e.ctrlKey);
33 "enter" : function(e){
38 </code></pre>
40 Ext.define('Ext.util.KeyNav', {
42 alternateClassName: 'Ext.KeyNav',
44 requires: ['Ext.util.KeyMap'],
65 <span id='Ext-util-KeyNav-method-constructor'> /**
66 </span> * Creates new KeyNav.
67 * @param {String/HTMLElement/Ext.Element} el The element or its ID to bind to
68 * @param {Object} config The config
70 constructor: function(el, config){
71 this.setConfig(el, config || {});
74 <span id='Ext-util-KeyNav-method-setConfig'> /**
75 </span> * Sets up a configuration for the KeyNav.
77 * @param {String/HTMLElement/Ext.Element} el The element or its ID to bind to
78 * @param {Object} config A configuration object as specified in the constructor.
80 setConfig: function(el, config) {
85 var map = Ext.create('Ext.util.KeyMap', el, null, this.getKeyEvent('forceKeyDown' in config ? config.forceKeyDown : this.forceKeyDown)),
86 keys = Ext.util.KeyNav.keyOptions,
87 scope = config.scope || this,
92 if (keys.hasOwnProperty(key)) {
97 handler: Ext.Function.bind(this.handleEvent, scope, [config[key]], true),
98 defaultEventAction: config.defaultEventAction || this.defaultEventAction
105 if (!config.disabled) {
110 <span id='Ext-util-KeyNav-method-handleEvent'> /**
111 </span> * Method for filtering out the map argument
113 * @param {Ext.util.KeyMap} map
114 * @param {Ext.EventObject} event
115 * @param {Object} options Contains the handler to call
117 handleEvent: function(map, event, handler){
118 return handler.call(this, event);
121 <span id='Ext-util-KeyNav-cfg-disabled'> /**
122 </span> * @cfg {Boolean} disabled
123 * True to disable this KeyNav instance.
127 <span id='Ext-util-KeyNav-cfg-defaultEventAction'> /**
128 </span> * @cfg {String} defaultEventAction
129 * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
130 * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
131 * {@link Ext.EventObject#stopPropagation}.
133 defaultEventAction: "stopEvent",
135 <span id='Ext-util-KeyNav-cfg-forceKeyDown'> /**
136 </span> * @cfg {Boolean} forceKeyDown
137 * Handle the keydown event instead of keypress. KeyNav automatically does this for IE since
138 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
139 * handle keydown instead of keypress.
143 <span id='Ext-util-KeyNav-method-destroy'> /**
144 </span> * Destroy this KeyNav (this is the same as calling disable).
145 * @param {Boolean} removeEl True to remove the element associated with this KeyNav.
147 destroy: function(removeEl){
148 this.map.destroy(removeEl);
152 <span id='Ext-util-KeyNav-method-enable'> /**
153 </span> * Enable this KeyNav
157 this.disabled = false;
160 <span id='Ext-util-KeyNav-method-disable'> /**
161 </span> * Disable this KeyNav
163 disable: function() {
165 this.disabled = true;
168 <span id='Ext-util-KeyNav-method-setDisabled'> /**
169 </span> * Convenience function for setting disabled/enabled by boolean.
170 * @param {Boolean} disabled
172 setDisabled : function(disabled){
173 this.map.setDisabled(disabled);
174 this.disabled = disabled;
177 <span id='Ext-util-KeyNav-method-getKeyEvent'> /**
178 </span> * Determines the event to bind to listen for keys. Depends on the {@link #forceKeyDown} setting,
179 * as well as the useKeyDown option on the EventManager.
180 * @return {String} The type of event to listen for.
182 getKeyEvent: function(forceKeyDown){
183 return (forceKeyDown || Ext.EventManager.useKeyDown) ? 'keydown' : 'keypress';