From 83116467ea317839a6659cdce6f16ea7103a0714 Mon Sep 17 00:00:00 2001 From: agrath Date: Thu, 21 Jan 2021 08:29:30 +1300 Subject: [PATCH 1/3] Add onloading/onloaded callbacks --- jquery.swiftype.autocomplete.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jquery.swiftype.autocomplete.js b/jquery.swiftype.autocomplete.js index 2c52431..fe7f066 100644 --- a/jquery.swiftype.autocomplete.js +++ b/jquery.swiftype.autocomplete.js @@ -108,6 +108,9 @@ if (handleFunctionParam(config.disableAutocomplete) === false) { $listContainer.show(); } + if (config.onLoaded) { + config.onLoaded(); + } }; $this.hideList = function(sync) { @@ -347,6 +350,10 @@ $this.showNoResults(); return; } + var config = $this.data('swiftype-config-autocomplete'); + if (config.onLoading) { + config.onLoading(); + } var cached = $this.cache.get(norm); if (cached) { processData($this, cached, term); @@ -409,7 +416,8 @@ var defaultOnComplete = function(item, prefix) { window.location = item['url']; }; - + var defaultOnLoading = function () { }; + var defaultOnLoaded = function () { }; var defaultDropdownStylesFunction = function($this) { var config = $this.data('swiftype-config-autocomplete'); var $attachEl = config.attachTo ? $(config.attachTo) : $this; @@ -552,6 +560,8 @@ noResultsClass: 'noResults', noResultsMessage: undefined, onComplete: defaultOnComplete, + onLoading: defaultOnLoading, + onLoaded: defaultOnLoaded, resultRenderFunction: defaultResultRenderFunction, renderFunction: defaultRenderFunction, dropdownStylesFunction: defaultDropdownStylesFunction, From dc862a4f4554ff32f76d544e14e2f9bdbb9347c8 Mon Sep 17 00:00:00 2001 From: agrath Date: Fri, 29 Jan 2021 09:10:14 +1300 Subject: [PATCH 2/3] Add onShow/onHide callbacks, move onLoaded callback to actual loaded --- jquery.swiftype.autocomplete.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/jquery.swiftype.autocomplete.js b/jquery.swiftype.autocomplete.js index fe7f066..c455ff3 100644 --- a/jquery.swiftype.autocomplete.js +++ b/jquery.swiftype.autocomplete.js @@ -108,16 +108,24 @@ if (handleFunctionParam(config.disableAutocomplete) === false) { $listContainer.show(); } - if (config.onLoaded) { - config.onLoaded(); + if (config.onShow) { + config.onShow(); } }; $this.hideList = function(sync) { if (sync) { $listContainer.hide(); + if(config.onHide) { + config.onHide(); + } } else { - setTimeout(function() { $listContainer.hide(); }, 10); + setTimeout(function() { + $listContainer.hide(); + if(config.onHide) { + config.onHide(); + } + }, 10); } }; @@ -332,6 +340,9 @@ url: endpoint, data: params }).done(function(data) { + if(config.onLoaded) { + config.onLoaded(); + } var norm = normalize(term); if (data.record_count > 0) { $this.cache.put(norm, data.records); @@ -418,6 +429,8 @@ }; var defaultOnLoading = function () { }; var defaultOnLoaded = function () { }; + var defaultOnShow = function () { }; + var defaultOnHide = function () { }; var defaultDropdownStylesFunction = function($this) { var config = $this.data('swiftype-config-autocomplete'); var $attachEl = config.attachTo ? $(config.attachTo) : $this; @@ -562,6 +575,8 @@ onComplete: defaultOnComplete, onLoading: defaultOnLoading, onLoaded: defaultOnLoaded, + onShow: defaultOnShow, + onHide: defaultOnHide, resultRenderFunction: defaultResultRenderFunction, renderFunction: defaultRenderFunction, dropdownStylesFunction: defaultDropdownStylesFunction, From 9e80198d26324a638af6eeb9a1b9a761a3e084a9 Mon Sep 17 00:00:00 2001 From: agrath Date: Fri, 29 Jan 2021 09:14:54 +1300 Subject: [PATCH 3/3] Add config setting to control if the active item is persistent on mouseout Allows control of if the enter key submits an autocomplete or a normal search following a mouse interaction --- jquery.swiftype.autocomplete.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jquery.swiftype.autocomplete.js b/jquery.swiftype.autocomplete.js index c455ff3..0de210a 100644 --- a/jquery.swiftype.autocomplete.js +++ b/jquery.swiftype.autocomplete.js @@ -192,6 +192,10 @@ $element.click($this.selectedCallback(data)).mouseover(function () { $this.listResults().removeClass(config.activeItemClass); $element.addClass(config.activeItemClass); + }).mouseout(function () { + if (!config.persistentActiveItem) { + $this.listResults().removeClass(config.activeItemClass); + } }); }; @@ -560,6 +564,7 @@ $.fn.swiftype.defaults = { activeItemClass: 'active', + persistentActiveItem: true, attachTo: undefined, documentTypes: undefined, filters: undefined,