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 ) ;
0 commit comments