Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.

Commit a00b201

Browse files
committed
Cache raw results and filter cached results in a separate callback
1 parent 6db1b01 commit a00b201

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/jquery.tokeninput.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)