Skip to content

Commit

Permalink
chore(flow):fix flows for spas & prefilled queries
Browse files Browse the repository at this point in the history
  • Loading branch information
divyadaglia-unbxd committed Dec 11, 2024
1 parent 976dbbc commit d0e2c3e
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions unbxdAutosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,13 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
} else if (self.$results.find(".unbxd-as-maincontent").length || self.$results.find(".unbxd-as-sidecontent").length) {
self.$results.html(self.prepareHTML());
self.showResults();
} else {
self.showResults();
}
}
// else {
// if(self.$input.val() !== "") {
// self.showResults();
// }

// }
} else if (e.target == self.$results[0]) {
self.log("clicked on results block : selecting")
self.hasFocus = false;
Expand Down Expand Up @@ -1135,9 +1139,7 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
document.body.removeChild(scrollDiv);
}
, hideResults: function () {
if(this.options.onHideResults) {
this.options.onHideResults();
}

if (this.timeout)
clearTimeout(this.timeout);

Expand All @@ -1146,6 +1148,9 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
this.timeout = setTimeout(function () { self.hideResultsNow(); }, 200);
}
, hideResultsNow: function () {
if(this.options.onHideResults) {
this.options.onHideResults();
}
this.log("hideResultsNow");
if (this.timeout) clearTimeout(this.timeout);

Expand Down Expand Up @@ -1194,7 +1199,13 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
v = this.$input.val();
}

if (v == this.previous) return;
if (v == this.previous) {
if ((this.options.trendingSearches.enabled && this.clickResults && this.clickResults.TRENDING_QUERIES.length > 0 && v === "")) {
this.showResults();
} else {
return;
}
}

this.params.q = v
this.previous = v;
Expand Down Expand Up @@ -1237,8 +1248,15 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
else {
this.$input.removeClass(this.options.loadingClass);
if (!(this.options.trendingSearches.enabled && this.clickResults && this.clickResults.TRENDING_QUERIES.length > 0 && v === "")) {
this.$results.hide();
// this.$results.hide();
this.$results.html("");
this.hideResults();
}


if ((this.options.trendingSearches.enabled && this.clickResults && this.clickResults.TRENDING_QUERIES.length > 0 && v === "")) {
this.showResults();
}
}
}
}
Expand Down Expand Up @@ -1997,9 +2015,15 @@ var unbxdAutoSuggestFunction = function ($, Handlebars, params) {
}

// recent searches will also be added on click in future.
this.clickResults = {
TRENDING_QUERIES: []

if(this.clickResults && this.clickResults.TRENDING_QUERIES.length) {
/** Do not empty again, as trending queries are fetched only once per sitekey */
} else {
this.clickResults = {
TRENDING_QUERIES: []
}
}


var infieldsCount = 0;
var key_count = 0,
Expand Down

0 comments on commit d0e2c3e

Please sign in to comment.