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 ae18252f03620c4e91cdead08efb696e2fe12570 Mon Sep 17 00:00:00 2001 From: agrath Date: Tue, 2 Feb 2021 16:50:43 +1300 Subject: [PATCH 3/3] pass data to onLoaded callback --- jquery.swiftype.autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.swiftype.autocomplete.js b/jquery.swiftype.autocomplete.js index c455ff3..a08ace8 100644 --- a/jquery.swiftype.autocomplete.js +++ b/jquery.swiftype.autocomplete.js @@ -341,7 +341,7 @@ data: params }).done(function(data) { if(config.onLoaded) { - config.onLoaded(); + config.onLoaded(data); } var norm = normalize(term); if (data.record_count > 0) {