11/*
2- JavaScript autoComplete v1.0.0
2+ JavaScript autoComplete v1.0.1
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
@@ -13,10 +13,6 @@ var autoComplete = (function(){
1313 // helpers
1414 function hasClass ( el , className ) { return el . classList ? el . classList . contains ( className ) : new RegExp ( '\\b' + className + '\\b' ) . test ( el . className ) ; }
1515
16- function triggerEvent ( el , type ) {
17- if ( document . createEvent ) { var e = document . createEvent ( 'HTMLEvents' ) ; e . initEvent ( type , true , true ) ; el . dispatchEvent ( e ) ; }
18- else { var e = document . createEventObject ( ) ; e . eventType = type ; el . fireEvent ( 'on' + e . eventType , e ) ; }
19- }
2016 function addEvent ( el , type , handler ) {
2117 if ( el . attachEvent ) el . attachEvent ( 'on' + type , handler ) ; else el . addEventListener ( type , handler ) ;
2218 }
@@ -111,16 +107,10 @@ var autoComplete = (function(){
111107 if ( ! over_sb ) {
112108 that . last_val = that . value ;
113109 that . sc . style . display = 'none' ;
114- } else that . focus ( ) ;
110+ } else if ( that !== document . activeElement ) that . focus ( ) ;
115111 } ;
116112 addEvent ( that , 'blur' , that . blurHandler ) ;
117113
118- that . focusHandler = function ( ) {
119- that . last_val = '\n' ;
120- triggerEvent ( that , 'keyup' ) ;
121- } ;
122- if ( ! o . minChars ) addEvent ( that , 'focus' , that . focusHandler ) ;
123-
124114 var suggest = function ( data ) {
125115 var val = that . value ;
126116 that . cache [ val ] = data ;
@@ -190,6 +180,12 @@ var autoComplete = (function(){
190180 }
191181 } ;
192182 addEvent ( that , 'keyup' , that . keyupHandler ) ;
183+
184+ that . focusHandler = function ( e ) {
185+ that . last_val = '\n' ;
186+ that . keyupHandler ( e )
187+ } ;
188+ if ( ! o . minChars ) addEvent ( that , 'focus' , that . focusHandler ) ;
193189 }
194190
195191 // public destroy method
0 commit comments