Skip to content
Snippets Groups Projects
Commit 38c2a3d3 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Fix to autocomplete targetting wrong element and saving strings to config.

parent 0387c043
No related merge requests found
/*global jQuery, window, document, console, setTimeout, clearTimeout */ /*global jQuery, window, document, console, setTimeout, clearTimeout */
/** /**
* crhallberg/autocomplete.js 0.14.1 * crhallberg/autocomplete.js 0.15
* ~ @crhallberg * ~ @crhallberg
*/ */
(function ( $ ) { (function ( $ ) {
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
createList(cache[cid][term], input); createList(cache[cid][term], input);
} }
} else { } else {
options.handler(input.val(), function(data) { options.handler(input, function(data) {
cache[cid][term] = data; cache[cid][term] = data;
if (data.length === 0) { if (data.length === 0) {
hide(); hide();
...@@ -240,7 +240,6 @@ ...@@ -240,7 +240,6 @@
$.fn.autocomplete = function(settings) { $.fn.autocomplete = function(settings) {
options = $.extend( {}, options, settings );
return this.each(function() { return this.each(function() {
...@@ -252,7 +251,7 @@ ...@@ -252,7 +251,7 @@
align(input); align(input);
} else if (settings === "hide") { } else if (settings === "hide") {
hide(); hide();
} else if (settings === "clear cache" && options.cache) { } else if (options.cache && settings === "clear cache") {
var cid = parseInt(input.data('cache-id'), 10); var cid = parseInt(input.data('cache-id'), 10);
cache[cid] = {}; cache[cid] = {};
} }
...@@ -261,6 +260,7 @@ ...@@ -261,6 +260,7 @@
console.error('handler function not provided for autocomplete'); console.error('handler function not provided for autocomplete');
return this; return this;
} else { } else {
options = $.extend( {}, options, settings );
element = $('.autocomplete-results'); element = $('.autocomplete-results');
if (element.length == 0) { if (element.length == 0) {
element = setup(input); element = setup(input);
......
...@@ -165,10 +165,11 @@ function setupAutocomplete() { ...@@ -165,10 +165,11 @@ function setupAutocomplete() {
$(op).autocomplete({ $(op).autocomplete({
maxResults: 10, maxResults: 10,
loadingString: VuFind.translate('loading')+'...', loadingString: VuFind.translate('loading')+'...',
handler: function(query, cb) { handler: function(input, cb) {
var searcher = extractClassParams(op); var query = input.val();
var searcher = extractClassParams(input);
var hiddenFilters = []; var hiddenFilters = [];
$(op).closest('.searchForm').find('input[name="hiddenFilters[]"]').each(function() { $(input).closest('.searchForm').find('input[name="hiddenFilters[]"]').each(function() {
hiddenFilters.push($(this).val()); hiddenFilters.push($(this).val());
}); });
$.fn.autocomplete.ajax({ $.fn.autocomplete.ajax({
...@@ -177,7 +178,7 @@ function setupAutocomplete() { ...@@ -177,7 +178,7 @@ function setupAutocomplete() {
q:query, q:query,
method:'getACSuggestions', method:'getACSuggestions',
searcher:searcher['searcher'], 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 hiddenFilters:hiddenFilters
}, },
dataType:'json', dataType:'json',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment