don't match again if user input does no change anything
@@ -13,6 +13,7 @@ c3nav = {
init_typeahead: function () {
c3nav.typeahead_locations = [];
+ c3nav._last_typeahead_words_key = null;
$.getJSON('/api/locations/?searchable', function (data) {
for (var i = 0; i < data.length; i++) {
var location = data[i];
@@ -37,6 +38,7 @@ c3nav = {
val = $(this).val(),
val_trimmed = $.trim(val),
val_words = val_trimmed.toLowerCase().split(/\s+/),
+ val_words_key = ' '.join(val_words),
$autocomplete = $('#autocomplete');
$(this).parent().removeClass('selected').toggleClass('empty', (val === ''));
@@ -44,6 +46,9 @@ c3nav = {
$autocomplete.html('');
return;
}
+ if (val_words_key === c3nav._last_typeahead_words_key) {
+ return;
+ }
for (var i = 0; i < c3nav.typeahead_locations.length; i++) {
var location = c3nav.typeahead_locations[i],
