11/**
2- * Ajax Autocomplete for jQuery, version 1.2.4
2+ * Ajax Autocomplete for jQuery, version 1.2.5
33* (c) 2013 Tomas Kirda
44*
55* Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
8989 onSearchComplete : noop ,
9090 containerClass : 'autocomplete-suggestions' ,
9191 tabDisabled : false ,
92- dataType : 'text' ,
92+ dataType : 'text' ,
9393 lookupFilter : function ( suggestion , originalQuery , queryLowerCase ) {
9494 return suggestion . value . toLowerCase ( ) . indexOf ( queryLowerCase ) !== - 1 ;
9595 } ,
9696 paramName : 'query' ,
9797 transformResult : function ( response ) {
98- return response . suggestions ;
98+ return typeof response === 'string' ? $ . parseJSON ( response ) : response ;
9999 }
100100 } ;
101101
244244 }
245245
246246 offset = that . el . offset ( ) ;
247-
247+
248248 $ ( that . suggestionsContainer ) . css ( {
249249 top : ( offset . top + that . el . outerHeight ( ) ) + 'px' ,
250250 left : offset . left + 'px'
401401 that . suggestions = response . suggestions ;
402402 that . suggest ( ) ;
403403 } else if ( ! that . isBadQuery ( q ) ) {
404- options . onSearchStart . call ( that . element , q ) ;
405404 options . params [ options . paramName ] = q ;
405+ options . onSearchStart . call ( that . element , options . params ) ;
406406 $ . ajax ( {
407407 url : options . serviceUrl ,
408408 data : options . params ,
409409 type : options . type ,
410410 dataType : options . dataType
411- } ) . done ( function ( txt ) {
412- that . processResponse ( txt ) ;
411+ } ) . done ( function ( data ) {
412+ that . processResponse ( data , q ) ;
413413 options . onSearchComplete . call ( that . element , q ) ;
414414 } ) ;
415415 }
475475 return suggestions ;
476476 } ,
477477
478- processResponse : function ( text ) {
478+ processResponse : function ( response , originalQuery ) {
479479 var that = this ,
480- response = typeof text == 'string' ? $ . parseJSON ( text ) : text ;
480+ options = that . options ,
481+ result = options . transformResult ( response , originalQuery ) ;
481482
482- response . suggestions = that . verifySuggestionsFormat ( that . options . transformResult ( response ) ) ;
483+ result . suggestions = that . verifySuggestionsFormat ( result . suggestions ) ;
483484
484485 // 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 ] ) ;
489490 }
490491 }
491492
492493 // 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 ;
495496 that . suggest ( ) ;
496497 }
497498 } ,
631632 }
632633 } ) ;
633634 } ;
634- } ) ) ;
635+ } ) ) ;
0 commit comments