@@ -24,8 +24,8 @@ var autoComplete = (function(){
24
24
// if (el.removeEventListener) not working in IE11
25
25
if ( el . detachEvent ) el . detachEvent ( 'on' + type , handler ) ; else el . removeEventListener ( type , handler ) ;
26
26
}
27
- function live ( container , event , elClass , cb ) {
28
- addEvent ( container , event , function ( e ) {
27
+ function live ( event , elClass , cb , context ) {
28
+ addEvent ( context || document , event , function ( e ) {
29
29
var found , el = e . target || e . srcElement ;
30
30
while ( el && ! ( found = hasClass ( el , elClass ) ) ) el = el . parentElement ;
31
31
if ( found ) cb . call ( el , e ) ;
@@ -91,26 +91,26 @@ var autoComplete = (function(){
91
91
addEvent ( window , 'resize' , that . updateSC ) ;
92
92
document . body . appendChild ( that . sc ) ;
93
93
94
- live ( that . sc , 'mouseleave' , 'autocomplete-suggestion' , function ( e ) {
94
+ live ( 'mouseleave' , 'autocomplete-suggestion' , function ( e ) {
95
95
var sel = that . sc . querySelector ( '.autocomplete-suggestion.selected' ) ;
96
96
if ( sel ) setTimeout ( function ( ) { sel . className = sel . className . replace ( 'selected' , '' ) ; } , 20 ) ;
97
- } ) ;
97
+ } , that . sc ) ;
98
98
99
- live ( that . sc , 'mouseover' , 'autocomplete-suggestion' , function ( e ) {
99
+ live ( 'mouseover' , 'autocomplete-suggestion' , function ( e ) {
100
100
var sel = that . sc . querySelector ( '.autocomplete-suggestion.selected' ) ;
101
101
if ( sel ) sel . className = sel . className . replace ( 'selected' , '' ) ;
102
102
this . className += ' selected' ;
103
- } ) ;
103
+ } , that . sc ) ;
104
104
105
- live ( that . sc , 'mouseup' , 'autocomplete-suggestion' , function ( e ) {
105
+ live ( 'mouseup' , 'autocomplete-suggestion' , function ( e ) {
106
106
if ( hasClass ( this , 'autocomplete-suggestion' ) ) { // else outside click
107
107
var v = this . getAttribute ( 'data-val' ) ;
108
108
that . value = v ;
109
109
o . onSelect ( e , v , this ) ;
110
110
that . focus ( ) ;
111
111
that . sc . style . display = 'none' ;
112
112
}
113
- } ) ;
113
+ } , that . sc ) ;
114
114
115
115
that . blurHandler = function ( ) {
116
116
try { var over_sb = document . querySelector ( '.autocomplete-suggestions:hover' ) ; } catch ( e ) { var over_sb = 0 ; }
0 commit comments