@@ -10,7 +10,9 @@ var autoComplete = (function(){
10
10
function autoComplete ( options ) {
11
11
if ( ! document . querySelector ) return ;
12
12
13
- // event helpers
13
+ // helpers
14
+ function hasClass ( el , className ) { return el . classList ? el . classList . contains ( className ) : new RegExp ( '\\b' + className + '\\b' ) . test ( el . className ) ; }
15
+
14
16
function triggerEvent ( el , type ) {
15
17
if ( document . createEvent ) { var e = document . createEvent ( 'HTMLEvents' ) ; e . initEvent ( type , true , true ) ; el . dispatchEvent ( e ) ; }
16
18
else { var e = document . createEventObject ( ) ; e . eventType = type ; el . fireEvent ( 'on' + e . eventType , e ) ; }
@@ -25,7 +27,7 @@ var autoComplete = (function(){
25
27
function live ( container , event , elClass , cb ) {
26
28
addEvent ( container , event , function ( e ) {
27
29
var found , el = e . target || e . srcElement ;
28
- while ( el && ! ( found = ~ el . className . indexOf ( elClass ) ) ) el = el . parentElement ;
30
+ while ( el && ! ( found = hasClass ( el , elClass ) ) ) el = el . parentElement ;
29
31
if ( found ) cb . call ( el , e ) ;
30
32
} ) ;
31
33
}
@@ -101,7 +103,7 @@ var autoComplete = (function(){
101
103
} ) ;
102
104
103
105
live ( that . sc , 'mouseup' , 'autocomplete-suggestion' , function ( e ) {
104
- if ( ~ this . className . indexOf ( 'autocomplete-suggestion' ) ) { // else outside click
106
+ if ( hasClass ( this , 'autocomplete-suggestion' ) ) { // else outside click
105
107
var v = this . getAttribute ( 'data-val' ) ;
106
108
that . value = v ;
107
109
o . onSelect ( e , v , this ) ;
0 commit comments