1
1
/*
2
- JavaScript autoComplete v1.0.1
2
+ JavaScript autoComplete v1.0.2
3
3
Copyright (c) 2014 Simon Steinberger / Pixabay
4
4
GitHub: https://github.com/Pixabay/JavaScript-autoComplete
5
5
License: http://www.opensource.org/licenses/mit-license.php
@@ -92,7 +92,7 @@ var autoComplete = (function(){
92
92
this . className += ' selected' ;
93
93
} , that . sc ) ;
94
94
95
- live ( 'autocomplete-suggestion' , 'mouseup ' , function ( e ) {
95
+ live ( 'autocomplete-suggestion' , 'mousedown ' , function ( e ) {
96
96
if ( hasClass ( this , 'autocomplete-suggestion' ) ) { // else outside click
97
97
var v = this . getAttribute ( 'data-val' ) ;
98
98
that . value = v ;
@@ -106,7 +106,8 @@ var autoComplete = (function(){
106
106
if ( ! over_sb ) {
107
107
that . last_val = that . value ;
108
108
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 ) ;
110
111
} ;
111
112
addEvent ( that , 'blur' , that . blurHandler ) ;
112
113
@@ -147,9 +148,9 @@ var autoComplete = (function(){
147
148
// esc
148
149
else if ( key == 27 ) { that . value = that . last_val ; that . sc . style . display = 'none' ; }
149
150
// enter
150
- else if ( key == 13 ) {
151
+ else if ( key == 13 || key == 9 ) {
151
152
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 ) ; }
153
154
}
154
155
} ;
155
156
addEvent ( that , 'keydown' , that . keydownHandler ) ;
0 commit comments