From 2f6bce3b5e4cd34879d6b93563fda5fd1576c23f Mon Sep 17 00:00:00 2001 From: MarkEEaton Date: Sat, 30 Apr 2022 00:24:55 -0400 Subject: [PATCH] store facet and search terms in sessionStorage --- groups/home/LibAnswers-3-js-css.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/groups/home/LibAnswers-3-js-css.html b/groups/home/LibAnswers-3-js-css.html index e3f80b2..c4ba2e5 100644 --- a/groups/home/LibAnswers-3-js-css.html +++ b/groups/home/LibAnswers-3-js-css.html @@ -457,7 +457,21 @@ function customizeSearch(facet) { } else { console.log("no match"); } + + // store the facet, for use on page reload + sessionStorage.facet = facet; } + +// if the stored facet exists on page load, render the dropdown with that facet, then clear the stored facet +window.onload = function() { + if (sessionStorage.facet && sessionStorage.searchTerms) { + stored_terms = sessionStorage.searchTerms; + document.getElementById("primoQueryTemp").value = stored_terms; + stored_facet = sessionStorage.facet; + customizeSearch(stored_facet); + } + sessionStorage.clear(); +}; @@ -475,9 +489,12 @@ function addPrimoQuery(e) { return true; }; + // save the search terms, for use on page reload + sessionStorage.searchTerms = document.getElementById("primoQueryTemp").value; + // original OLS widget document.getElementById("primoQuery").value = "any,contains," + document.getElementById("primoQueryTemp").value.replace(/[,]/g, " "); - /* If you changed the form name at the top, change it below to match */ + // If you changed the form name at the top, change it below to match document.forms.searchPrimoForm1.submit(); }