2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('autocomplete-list-keys', function (Y, NAME) {
11 Mixes keyboard support into AutoCompleteList. By default, this module is not
12 loaded for iOS and Android devices.
15 @submodule autocomplete-list-keys
26 Y.before(this._bindKeys, this, 'bindUI');
30 ListKeys.prototype = {
31 // -- Lifecycle Methods ----------------------------------------------------
34 Initializes keyboard command mappings.
40 _initKeys: function () {
44 // Register keyboard command handlers. _keys contains handlers that will
45 // always be called; _keysVisible contains handlers that will only be
46 // called when the list is visible.
47 keys[KEY_DOWN] = this._keyDown;
49 keysVisible[KEY_ENTER] = this._keyEnter;
50 keysVisible[KEY_ESC] = this._keyEsc;
51 keysVisible[KEY_TAB] = this._keyTab;
52 keysVisible[KEY_UP] = this._keyUp;
55 this._keysVisible = keysVisible;
58 destructor: function () {
63 Binds keyboard events.
68 _bindKeys: function () {
69 this._keyEvents = this._inputNode.on('keydown', this._onInputKey, this);
73 Unbinds keyboard events.
78 _unbindKeys: function () {
79 this._keyEvents && this._keyEvents.detach();
80 this._keyEvents = null;
83 // -- Protected Methods ----------------------------------------------------
86 Called when the down arrow key is pressed.
91 _keyDown: function () {
92 if (this.get('visible')) {
93 this._activateNextItem();
100 Called when the enter key is pressed.
105 _keyEnter: function (e) {
106 var item = this.get('activeItem');
109 this.selectItem(item, e);
111 // Don't prevent form submission when there's no active item.
117 Called when the escape key is pressed.
122 _keyEsc: function () {
127 Called when the tab key is pressed.
132 _keyTab: function (e) {
135 if (this.get('tabSelect')) {
136 item = this.get('activeItem');
139 this.selectItem(item, e);
148 Called when the up arrow key is pressed.
153 _keyUp: function () {
154 this._activatePrevItem();
157 // -- Protected Event Handlers ---------------------------------------------
160 Handles `inputNode` key events.
163 @param {EventTarget} e
166 _onInputKey: function (e) {
170 this._lastInputKey = keyCode;
172 if (this.get('results').length) {
173 handler = this._keys[keyCode];
175 if (!handler && this.get('visible')) {
176 handler = this._keysVisible[keyCode];
180 // A handler may return false to indicate that it doesn't wish
181 // to prevent the default key behavior.
182 if (handler.call(this, e) !== false) {
190 Y.Base.mix(Y.AutoCompleteList, [ListKeys]);
193 }, '3.13.0', {"requires": ["autocomplete-list", "base-build"]});