@@ -57,6 +57,7 @@ var DEFAULT_SETTINGS = {
57
57
58
58
// Callbacks
59
59
onResult : null ,
60
+ onCachedResult : null ,
60
61
onAdd : null ,
61
62
onFreeTaggingAdd : null ,
62
63
onDelete : null ,
@@ -888,6 +889,9 @@ $.TokenList = function (input, url_or_data, settings) {
888
889
var cache_key = query + computeURL ( ) ;
889
890
var cached_results = cache . get ( cache_key ) ;
890
891
if ( cached_results ) {
892
+ if ( $ . isFunction ( settings . onCachedResult ) ) {
893
+ cached_results = settings . onCachedResult . call ( hidden_input , cached_results ) ;
894
+ }
891
895
populate_dropdown ( query , cached_results ) ;
892
896
} else {
893
897
// Are we doing an ajax search or local data search?
@@ -919,10 +923,10 @@ $.TokenList = function (input, url_or_data, settings) {
919
923
920
924
// Attach the success callback
921
925
ajax_params . success = function ( results ) {
926
+ cache . add ( cache_key , settings . jsonContainer ? results [ settings . jsonContainer ] : results ) ;
922
927
if ( $ . isFunction ( settings . onResult ) ) {
923
928
results = settings . onResult . call ( hidden_input , results ) ;
924
929
}
925
- cache . add ( cache_key , settings . jsonContainer ? results [ settings . jsonContainer ] : results ) ;
926
930
927
931
// only populate the dropdown if the results are associated with the active search query
928
932
if ( input_box . val ( ) === query ) {
@@ -938,10 +942,10 @@ $.TokenList = function (input, url_or_data, settings) {
938
942
return row [ settings . propertyToSearch ] . toLowerCase ( ) . indexOf ( query . toLowerCase ( ) ) > - 1 ;
939
943
} ) ;
940
944
945
+ cache . add ( cache_key , results ) ;
941
946
if ( $ . isFunction ( settings . onResult ) ) {
942
947
results = settings . onResult . call ( hidden_input , results ) ;
943
948
}
944
- cache . add ( cache_key , results ) ;
945
949
populate_dropdown ( query , results ) ;
946
950
}
947
951
}
0 commit comments