diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 8572cf708..63aa7a8f1 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -6,10 +6,12 @@ function contact_search(term, callback, backend_url, type, extra_channels) { // Check if there is a cached result that contains the same information we would get with a full server-side search // Assume type hasn't changed + var lterm = term.toLowerCase(); // Ignore case for(t in contact_search.cache) { - if(term.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results + if(lterm.indexOf(t) >= 0) { // A more broad search has been performed already, so use those results // Filter old results locally - var matching = contact_search.cache[t].filter(function (x) { return (x.name.indexOf(term) >= 0 || x.nick.indexOf(term) >= 0); }); + var matching = contact_search.cache[t].filter(function (x) { return (x.name.toLowerCase().indexOf(lterm) >= 0 || x.nick.toLowerCase().indexOf(lterm) >= 0); }); + matching.unshift({taggable:false, text: term, replace: term}); callback(matching); return; } @@ -33,20 +35,30 @@ function contact_search(term, callback, backend_url, type, extra_channels) { success:function(data){ // Cache results if we got them all (more information would not improve results) // data.count represents the maximum number of items - if(data.items.length < data.count) { - contact_search.cache[term] = data.items; + if(data.items.length -1 < data.count) { + contact_search.cache[lterm] = data.items; } - callback(data.items); + var items = data.items.slice(0); + items.unshift({taggable:false, text: term, replace: term}); + callback(items); }, }).fail(function () {callback([]); }); // Callback must be invoked even if something went wrong. } contact_search.cache = {}; + function contact_format(item) { - return "