@@ -10,7 +10,9 @@ var autoComplete = (function(){
1010 function autoComplete ( options ) {
1111 if ( ! document . querySelector ) return ;
1212
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+
1416 function triggerEvent ( el , type ) {
1517 if ( document . createEvent ) { var e = document . createEvent ( 'HTMLEvents' ) ; e . initEvent ( type , true , true ) ; el . dispatchEvent ( e ) ; }
1618 else { var e = document . createEventObject ( ) ; e . eventType = type ; el . fireEvent ( 'on' + e . eventType , e ) ; }
@@ -25,7 +27,7 @@ var autoComplete = (function(){
2527 function live ( container , event , elClass , cb ) {
2628 addEvent ( container , event , function ( e ) {
2729 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 ;
2931 if ( found ) cb . call ( el , e ) ;
3032 } ) ;
3133 }
@@ -101,7 +103,7 @@ var autoComplete = (function(){
101103 } ) ;
102104
103105 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
105107 var v = this . getAttribute ( 'data-val' ) ;
106108 that . value = v ;
107109 o . onSelect ( e , v , this ) ;
0 commit comments