From 38c2a3d35e22a3b464b10878677544212be4dcc0 Mon Sep 17 00:00:00 2001 From: Chris Hallberg <crhallberg@gmail.com> Date: Wed, 25 May 2016 10:06:37 -0400 Subject: [PATCH] Fix to autocomplete targetting wrong element and saving strings to config. --- themes/bootstrap3/js/autocomplete.js | 8 ++++---- themes/bootstrap3/js/common.js | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/themes/bootstrap3/js/autocomplete.js b/themes/bootstrap3/js/autocomplete.js index 0747fa8b77f..43f84437b92 100644 --- a/themes/bootstrap3/js/autocomplete.js +++ b/themes/bootstrap3/js/autocomplete.js @@ -1,6 +1,6 @@ /*global jQuery, window, document, console, setTimeout, clearTimeout */ /** - * crhallberg/autocomplete.js 0.14.1 + * crhallberg/autocomplete.js 0.15 * ~ @crhallberg */ (function ( $ ) { @@ -104,7 +104,7 @@ createList(cache[cid][term], input); } } else { - options.handler(input.val(), function(data) { + options.handler(input, function(data) { cache[cid][term] = data; if (data.length === 0) { hide(); @@ -240,7 +240,6 @@ $.fn.autocomplete = function(settings) { - options = $.extend( {}, options, settings ); return this.each(function() { @@ -252,7 +251,7 @@ align(input); } else if (settings === "hide") { hide(); - } else if (settings === "clear cache" && options.cache) { + } else if (options.cache && settings === "clear cache") { var cid = parseInt(input.data('cache-id'), 10); cache[cid] = {}; } @@ -261,6 +260,7 @@ console.error('handler function not provided for autocomplete'); return this; } else { + options = $.extend( {}, options, settings ); element = $('.autocomplete-results'); if (element.length == 0) { element = setup(input); diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index b355cbe945c..9531bfc310a 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -165,10 +165,11 @@ function setupAutocomplete() { $(op).autocomplete({ maxResults: 10, loadingString: VuFind.translate('loading')+'...', - handler: function(query, cb) { - var searcher = extractClassParams(op); + handler: function(input, cb) { + var query = input.val(); + var searcher = extractClassParams(input); var hiddenFilters = []; - $(op).closest('.searchForm').find('input[name="hiddenFilters[]"]').each(function() { + $(input).closest('.searchForm').find('input[name="hiddenFilters[]"]').each(function() { hiddenFilters.push($(this).val()); }); $.fn.autocomplete.ajax({ @@ -177,7 +178,7 @@ function setupAutocomplete() { q:query, method:'getACSuggestions', searcher:searcher['searcher'], - type:searcher['type'] ? searcher['type'] : $(op).closest('.searchForm').find('.searchForm_type').val(), + type:searcher['type'] ? searcher['type'] : $(input).closest('.searchForm').find('.searchForm_type').val(), hiddenFilters:hiddenFilters }, dataType:'json', -- GitLab