Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71b76d7

Browse files
author
SimonSteinberger
committed
Various fixes
1 parent ed01f05 commit 71b76d7

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

auto-complete.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
JavaScript autoComplete v1.0.1
2+
JavaScript autoComplete v1.0.2
33
Copyright (c) 2014 Simon Steinberger / Pixabay
44
GitHub: https://github.com/Pixabay/JavaScript-autoComplete
55
License: http://www.opensource.org/licenses/mit-license.php
@@ -92,7 +92,7 @@ var autoComplete = (function(){
9292
this.className += ' selected';
9393
}, that.sc);
9494

95-
live('autocomplete-suggestion', 'mouseup', function(e){
95+
live('autocomplete-suggestion', 'mousedown', function(e){
9696
if (hasClass(this, 'autocomplete-suggestion')) { // else outside click
9797
var v = this.getAttribute('data-val');
9898
that.value = v;
@@ -106,7 +106,8 @@ var autoComplete = (function(){
106106
if (!over_sb) {
107107
that.last_val = that.value;
108108
that.sc.style.display = 'none';
109-
} else if (that !== document.activeElement) that.focus();
109+
setTimeout(function(){ that.sc.style.display = 'none'; }, 350); // hide suggestions on fast input
110+
} else if (that !== document.activeElement) setTimeout(function(){ that.focus(); }, 20);
110111
};
111112
addEvent(that, 'blur', that.blurHandler);
112113

@@ -147,9 +148,9 @@ var autoComplete = (function(){
147148
// esc
148149
else if (key == 27) { that.value = that.last_val; that.sc.style.display = 'none'; }
149150
// enter
150-
else if (key == 13) {
151+
else if (key == 13 || key == 9) {
151152
var sel = that.sc.querySelector('.autocomplete-suggestion.selected');
152-
if (sel) { o.onSelect(e, sel.getAttribute('data-val'), sel); setTimeout(function(){ that.sc.style.display = 'none'; }, 10); }
153+
if (sel && that.sc.style.display != 'none') { o.onSelect(e, sel.getAttribute('data-val'), sel); setTimeout(function(){ that.sc.style.display = 'none'; }, 20); }
153154
}
154155
};
155156
addEvent(that, 'keydown', that.keydownHandler);

auto-complete.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "javascript-auto-complete",
33
"description": "An extremely lightweight vanilla JavaScript completion suggester.",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"homepage": "https://github.com/Pixabay/JavaScript-autoComplete",
66
"authors": [{
77
"name": "Simon Steinberger",

demo.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ <h3>Settings</h3>
128128
<tr><td colspan="3">&nbsp;</td></tr>
129129
<tr><th>Callbacks</th><th colspan="2"></th></tr>
130130
<tr><td>onSelect(event, term, item)</td><td colspan="2">
131-
A callback function that fires when a suggestion is <b>selected by mouse click or pressing enter</b>.
131+
A callback function that fires when a suggestion is selected by mouse click, enter, or tab.
132132
<span class="inline-code">event</span> is the event that triggered the callback,
133133
<span class="inline-code">term</span> is the selected value.
134134
and <span class="inline-code">item</span> is the item rendered by the renderItem function.
135-
onSelect does <b>not</b> fire when pressing <i>Enter</i>, <i>Tab</i>, and other control keys that are passed directly to the input field.
136135
</td></tr>
137136

138137
<tr><td colspan="3">&nbsp;</td></tr>

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ https://goodies.pixabay.com/javascript/auto-complete/demo.html
2222

2323
## Changelog
2424

25+
### Version 1.0.2 - 2015/08/15
26+
27+
* Fixed: Hide suggestions on fast input.
28+
* Fixed: Select item with tab.
29+
* Fixed: Incorrect selection by mouse when suggestions are scrolled down.
30+
2531
### Version 1.0.1 - 2015/06/08
2632

2733
* Simplified code and minor bug fixes.

0 commit comments

Comments
 (0)