1
1
/**
2
- * Ajax Autocomplete for jQuery, version 1.2.4
2
+ * Ajax Autocomplete for jQuery, version 1.2.5
3
3
* (c) 2013 Tomas Kirda
4
4
*
5
5
* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
89
89
onSearchComplete : noop ,
90
90
containerClass : 'autocomplete-suggestions' ,
91
91
tabDisabled : false ,
92
- dataType : 'text' ,
92
+ dataType : 'text' ,
93
93
lookupFilter : function ( suggestion , originalQuery , queryLowerCase ) {
94
94
return suggestion . value . toLowerCase ( ) . indexOf ( queryLowerCase ) !== - 1 ;
95
95
} ,
96
96
paramName : 'query' ,
97
97
transformResult : function ( response ) {
98
- return response . suggestions ;
98
+ return typeof response === 'string' ? $ . parseJSON ( response ) : response ;
99
99
}
100
100
} ;
101
101
244
244
}
245
245
246
246
offset = that . el . offset ( ) ;
247
-
247
+
248
248
$ ( that . suggestionsContainer ) . css ( {
249
249
top : ( offset . top + that . el . outerHeight ( ) ) + 'px' ,
250
250
left : offset . left + 'px'
401
401
that . suggestions = response . suggestions ;
402
402
that . suggest ( ) ;
403
403
} else if ( ! that . isBadQuery ( q ) ) {
404
- options . onSearchStart . call ( that . element , q ) ;
405
404
options . params [ options . paramName ] = q ;
405
+ options . onSearchStart . call ( that . element , options . params ) ;
406
406
$ . ajax ( {
407
407
url : options . serviceUrl ,
408
408
data : options . params ,
409
409
type : options . type ,
410
410
dataType : options . dataType
411
- } ) . done ( function ( txt ) {
412
- that . processResponse ( txt ) ;
411
+ } ) . done ( function ( data ) {
412
+ that . processResponse ( data , q ) ;
413
413
options . onSearchComplete . call ( that . element , q ) ;
414
414
} ) ;
415
415
}
475
475
return suggestions ;
476
476
} ,
477
477
478
- processResponse : function ( text ) {
478
+ processResponse : function ( response , originalQuery ) {
479
479
var that = this ,
480
- response = typeof text == 'string' ? $ . parseJSON ( text ) : text ;
480
+ options = that . options ,
481
+ result = options . transformResult ( response , originalQuery ) ;
481
482
482
- response . suggestions = that . verifySuggestionsFormat ( that . options . transformResult ( response ) ) ;
483
+ result . suggestions = that . verifySuggestionsFormat ( result . suggestions ) ;
483
484
484
485
// Cache results if cache is not disabled:
485
- if ( ! that . options . noCache ) {
486
- that . cachedResponse [ response [ that . options . paramName ] ] = response ;
487
- if ( response . suggestions . length === 0 ) {
488
- that . badQueries . push ( response [ that . options . paramName ] ) ;
486
+ if ( ! options . noCache ) {
487
+ that . cachedResponse [ result [ options . paramName ] ] = result ;
488
+ if ( result . suggestions . length === 0 ) {
489
+ that . badQueries . push ( result [ options . paramName ] ) ;
489
490
}
490
491
}
491
492
492
493
// Display suggestions only if returned query matches current value:
493
- if ( response [ that . options . paramName ] === that . getQuery ( that . currentValue ) ) {
494
- that . suggestions = response . suggestions ;
494
+ if ( originalQuery === that . getQuery ( that . currentValue ) ) {
495
+ that . suggestions = result . suggestions ;
495
496
that . suggest ( ) ;
496
497
}
497
498
} ,
631
632
}
632
633
} ) ;
633
634
} ;
634
- } ) ) ;
635
+ } ) ) ;
0 commit comments