1
1
/*
2
- JavaScript autoComplete v1.0.0
2
+ JavaScript autoComplete v1.0.1
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
@@ -13,10 +13,6 @@ var autoComplete = (function(){
13
13
// helpers
14
14
function hasClass ( el , className ) { return el . classList ? el . classList . contains ( className ) : new RegExp ( '\\b' + className + '\\b' ) . test ( el . className ) ; }
15
15
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
- }
20
16
function addEvent ( el , type , handler ) {
21
17
if ( el . attachEvent ) el . attachEvent ( 'on' + type , handler ) ; else el . addEventListener ( type , handler ) ;
22
18
}
@@ -111,16 +107,10 @@ var autoComplete = (function(){
111
107
if ( ! over_sb ) {
112
108
that . last_val = that . value ;
113
109
that . sc . style . display = 'none' ;
114
- } else that . focus ( ) ;
110
+ } else if ( that !== document . activeElement ) that . focus ( ) ;
115
111
} ;
116
112
addEvent ( that , 'blur' , that . blurHandler ) ;
117
113
118
- that . focusHandler = function ( ) {
119
- that . last_val = '\n' ;
120
- triggerEvent ( that , 'keyup' ) ;
121
- } ;
122
- if ( ! o . minChars ) addEvent ( that , 'focus' , that . focusHandler ) ;
123
-
124
114
var suggest = function ( data ) {
125
115
var val = that . value ;
126
116
that . cache [ val ] = data ;
@@ -190,6 +180,12 @@ var autoComplete = (function(){
190
180
}
191
181
} ;
192
182
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 ) ;
193
189
}
194
190
195
191
// public destroy method
0 commit comments