@@ -57,6 +57,7 @@ var DEFAULT_SETTINGS = {
5757
5858 // Callbacks
5959 onResult : null ,
60+ onCachedResult : null ,
6061 onAdd : null ,
6162 onFreeTaggingAdd : null ,
6263 onDelete : null ,
@@ -888,6 +889,9 @@ $.TokenList = function (input, url_or_data, settings) {
888889 var cache_key = query + computeURL ( ) ;
889890 var cached_results = cache . get ( cache_key ) ;
890891 if ( cached_results ) {
892+ if ( $ . isFunction ( settings . onCachedResult ) ) {
893+ cached_results = settings . onCachedResult . call ( hidden_input , cached_results ) ;
894+ }
891895 populate_dropdown ( query , cached_results ) ;
892896 } else {
893897 // Are we doing an ajax search or local data search?
@@ -919,10 +923,10 @@ $.TokenList = function (input, url_or_data, settings) {
919923
920924 // Attach the success callback
921925 ajax_params . success = function ( results ) {
926+ cache . add ( cache_key , settings . jsonContainer ? results [ settings . jsonContainer ] : results ) ;
922927 if ( $ . isFunction ( settings . onResult ) ) {
923928 results = settings . onResult . call ( hidden_input , results ) ;
924929 }
925- cache . add ( cache_key , settings . jsonContainer ? results [ settings . jsonContainer ] : results ) ;
926930
927931 // only populate the dropdown if the results are associated with the active search query
928932 if ( input_box . val ( ) === query ) {
@@ -938,10 +942,10 @@ $.TokenList = function (input, url_or_data, settings) {
938942 return row [ settings . propertyToSearch ] . toLowerCase ( ) . indexOf ( query . toLowerCase ( ) ) > - 1 ;
939943 } ) ;
940944
945+ cache . add ( cache_key , results ) ;
941946 if ( $ . isFunction ( settings . onResult ) ) {
942947 results = settings . onResult . call ( hidden_input , results ) ;
943948 }
944- cache . add ( cache_key , results ) ;
945949 populate_dropdown ( query , results ) ;
946950 }
947951 }
0 commit comments