4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
15 * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
16 * navigation keys to function calls that will get called when the keys are pressed, providing an easy
17 * way to implement custom navigation schemes for any UI component.</p>
18 * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
19 * pageUp, pageDown, del, home, end. Usage:</p>
21 var nav = new Roo.KeyNav("my-element", {
23 this.moveLeft(e.ctrlKey);
25 "right" : function(e){
26 this.moveRight(e.ctrlKey);
28 "enter" : function(e){
35 * @param {String/HTMLElement/Roo.Element} el The element to bind to
36 * @param {Object} config The config
38 Roo.KeyNav = function(el, config){
39 this.el = Roo.get(el);
40 Roo.apply(this, config);
47 Roo.KeyNav.prototype = {
49 * @cfg {Boolean} disabled
50 * True to disable this KeyNav instance (defaults to false)
54 * @cfg {String} defaultEventAction
55 * The method to call on the {@link Roo.EventObject} after this KeyNav intercepts a key. Valid values are
56 * {@link Roo.EventObject#stopEvent}, {@link Roo.EventObject#preventDefault} and
57 * {@link Roo.EventObject#stopPropagation} (defaults to 'stopEvent')
59 defaultEventAction: "stopEvent",
61 * @cfg {Boolean} forceKeyDown
62 * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
63 * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
64 * handle keydown instead of keypress.
69 prepareEvent : function(e){
71 var h = this.keyToHandler[k];
73 // e.stopPropagation();
75 if(Roo.isSafari && h && k >= 37 && k <= 40){
83 var h = this.keyToHandler[k];
85 if(this.doRelay(e, this[h], h) !== true){
86 e[this.defaultEventAction]();
92 doRelay : function(e, h, hname){
93 return h.call(this.scope || this, e);
131 // ie won't do special keys on keypress, no one else will repeat keys with keydown
132 // the EventObject will normalize Safari automatically
133 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
134 this.el.on("keydown", this.relay, this);
136 this.el.on("keydown", this.prepareEvent, this);
137 this.el.on("keypress", this.relay, this);
139 this.disabled = false;
144 * Disable this KeyNav
148 if(this.forceKeyDown || Roo.isIE || Roo.isAir){
149 this.el.un("keydown", this.relay);
151 this.el.un("keydown", this.prepareEvent);
152 this.el.un("keypress", this.relay);
154 this.disabled = true;