mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-26 14:56:36 +00:00
Map keyboard keys on keys object.
This commit is contained in:
parent
8312b03dbe
commit
57a245eede
@ -5,7 +5,7 @@
|
|||||||
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
|
||||||
* For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/
|
* For details, see the web site: http://www.devbridge.com/projects/autocomplete/jquery/
|
||||||
*
|
*
|
||||||
* Last Review: 12/19/2012
|
* Last Review: 12/22/2012
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*jslint browser: true, white: true, plusplus: true, vars: true */
|
/*jslint browser: true, white: true, plusplus: true, vars: true */
|
||||||
@ -48,6 +48,14 @@
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
var keys = {
|
||||||
|
ESC: 27,
|
||||||
|
TAB: 9,
|
||||||
|
RETURN: 13,
|
||||||
|
UP: 38,
|
||||||
|
DOWN: 40
|
||||||
|
};
|
||||||
|
|
||||||
function Autocomplete(el, options) {
|
function Autocomplete(el, options) {
|
||||||
var noop = function () { },
|
var noop = function () { },
|
||||||
that = this,
|
that = this,
|
||||||
@ -227,7 +235,7 @@
|
|||||||
|
|
||||||
onKeyPress: function (e) {
|
onKeyPress: function (e) {
|
||||||
// If suggestions are hidden and user presses arrow down, display suggestions:
|
// If suggestions are hidden and user presses arrow down, display suggestions:
|
||||||
if (!this.disabled && !this.visible && e.keyCode === 40 && this.currentValue) {
|
if (!this.disabled && !this.visible && e.keyCode === keys.DOWN && this.currentValue) {
|
||||||
this.suggest();
|
this.suggest();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -237,25 +245,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case 27: //KEY_ESC:
|
case keys.ESC:
|
||||||
this.el.val(this.currentValue);
|
this.el.val(this.currentValue);
|
||||||
this.hide();
|
this.hide();
|
||||||
break;
|
break;
|
||||||
case 9: //KEY_TAB:
|
case keys.TAB:
|
||||||
case 13: //KEY_RETURN:
|
case keys.RETURN:
|
||||||
if (this.selectedIndex === -1) {
|
if (this.selectedIndex === -1) {
|
||||||
this.hide();
|
this.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.select(this.selectedIndex);
|
this.select(this.selectedIndex);
|
||||||
if (e.keyCode === 9) {
|
if (e.keyCode === keys.TAB) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 38: //KEY_UP:
|
case keys.UP:
|
||||||
this.moveUp();
|
this.moveUp();
|
||||||
break;
|
break;
|
||||||
case 40: //KEY_DOWN:
|
case keys.DOWN:
|
||||||
this.moveDown();
|
this.moveDown();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -273,8 +281,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
case 38: //KEY_UP:
|
case keys.UP:
|
||||||
case 40: //KEY_DOWN:
|
case keys.DOWN:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user