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

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions auto-complete.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ var autoComplete = (function(){
};
addEvent(that, 'blur', that.blurHandler);

var suggest = function(data){
var val = that.value;
var suggest = function(data, val){
if (!val) {
var val = that.value;
}
that.cache[val] = data;
if (data.length && val.length >= o.minChars) {
var s = '';
Expand Down Expand Up @@ -152,6 +154,9 @@ var autoComplete = (function(){
else if (key == 27) { that.value = that.last_val; that.sc.style.display = 'none'; }
// enter
else if (key == 13 || key == 9) {
if (that.sc.style.display !== 'none') {
e.preventDefault();
}
var sel = that.sc.querySelector('.autocomplete-suggestion.selected');
if (sel && that.sc.style.display != 'none') { o.onSelect(e, sel.getAttribute('data-val'), sel); setTimeout(function(){ that.sc.style.display = 'none'; }, 20); }
}
Expand All @@ -167,7 +172,7 @@ var autoComplete = (function(){
that.last_val = val;
clearTimeout(that.timer);
if (o.cache) {
if (val in that.cache) { suggest(that.cache[val]); return; }
if (val in that.cache) {suggest(that.cache[val]); return;}
// no requests if previous suggestions were empty
for (var i=1; i<val.length-o.minChars; i++) {
var part = val.slice(0, val.length-i);
Expand Down