1 | var facetSortOptions = {
|
---|
2 | valueNames: [ 'facet', 'count' ]
|
---|
3 | }
|
---|
4 |
|
---|
5 | function setUpFacetList(indexname)
|
---|
6 | {
|
---|
7 | var newList = new List(indexname, facetSortOptions);
|
---|
8 | enableMoreButtonIfNeeded(indexname);
|
---|
9 | }
|
---|
10 |
|
---|
11 | function enableMoreButtonIfNeeded(indexname) {
|
---|
12 | var morelink = $(".expandFacetList" + indexname);
|
---|
13 | var tables = $(".facetTable");
|
---|
14 | for(var i = 0; i < tables.length; i++)
|
---|
15 | {
|
---|
16 | var $current = $(tables[i]);
|
---|
17 | if($current.attr("indexname") == indexname) {
|
---|
18 | var current = $current[0];
|
---|
19 | if (current.clientHeight < current.scrollHeight) {
|
---|
20 | morelink.css("display", "block");
|
---|
21 | }
|
---|
22 | break;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | }
|
---|
27 |
|
---|
28 | function getFacetQueryString(facetsThatAreChecked)
|
---|
29 | {
|
---|
30 |
|
---|
31 | // if we have come here from eg next/prev page buttons, we won't have options selected in the
|
---|
32 | // facet list, we need to use the cgi param s1.facetQueries
|
---|
33 | if (gs.cgiParams.s1_facetQueries !== undefined) {
|
---|
34 | var facets = gs.cgiParams.s1_facetQueries;
|
---|
35 | // for some reason, we end up with " in here. Replace these back, so then we can call
|
---|
36 | // makeURLComponentSafe, and get back to the same encoded value we had originally
|
---|
37 | facets = facets.replace(/"/g, "\"");
|
---|
38 | return "s1.facetQueries="+makeURLComponentSafe(facets, 0)+"&";
|
---|
39 | }
|
---|
40 |
|
---|
41 | var allCheckBoxes = $("#facetSelector input");
|
---|
42 | var counts = new Array();
|
---|
43 |
|
---|
44 | for(var i = 0; i < allCheckBoxes.length; i++)
|
---|
45 | {
|
---|
46 | var current = $(allCheckBoxes[i]);
|
---|
47 | if(current.prop("checked"))
|
---|
48 | {
|
---|
49 | counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")");
|
---|
50 | if (facetsThatAreChecked !== undefined) {
|
---|
51 | facetsThatAreChecked.add(current.parent().parent().attr("indexName"));
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | var countsString = "s1.facetQueries=";
|
---|
57 | if(counts.length > 0)
|
---|
58 | {
|
---|
59 | var countsStringBuffer = "[";
|
---|
60 | for(var i = 0; i < counts.length; i++)
|
---|
61 | {
|
---|
62 | // escape any apostrophes in facet query terms
|
---|
63 | // (ext/solr's Greenstone3SearchHandler does the other half of handling them)
|
---|
64 | //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
65 | // calling makeURLSafe() here will ensure percent signs are escaped away too
|
---|
66 | // by the end of makeURLComponentSafe() call below
|
---|
67 | // Note that apostrophe's in URLs should get encoded, https://www.techwalla.com/articles/how-to-encode-an-apostrophe-in-a-url
|
---|
68 | // though the apostrophe is not in that other list of invalid and unsafe chars in urls dealt with in utility_scripts.js
|
---|
69 | countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
70 | if(i < counts.length - 1)
|
---|
71 | {
|
---|
72 | countsStringBuffer += ", ";
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | countsStringBuffer += "]";
|
---|
77 | // We need to ensure that the *value* of s1.facetQueries (so everything after
|
---|
78 | // s1.facetQueries= and before the connecting &) are safe, which requires escaping,
|
---|
79 | // and are further also escaped to not be mistaken for their reserved meaning.
|
---|
80 | // : is a reserved character in URLs, [] are unsafe characters. All need escaping.
|
---|
81 | // So call makeURLComponentSafe(), not makeURLSafe()
|
---|
82 | countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1);
|
---|
83 | }
|
---|
84 |
|
---|
85 | countsString += "&";
|
---|
86 | return countsString;
|
---|
87 | }
|
---|
88 |
|
---|
89 | function performRefinedSearch()
|
---|
90 | {
|
---|
91 | var allCheckBoxes = $("#facetSelector input");
|
---|
92 | var facetsThatAreChecked = new Set();
|
---|
93 | var facetQueryString = getFacetQueryString(facetsThatAreChecked);
|
---|
94 |
|
---|
95 | var searchString = "";
|
---|
96 | for(var key in gs.cgiParams)
|
---|
97 | {
|
---|
98 | if (gs.cgiParams.hasOwnProperty(key))
|
---|
99 | {
|
---|
100 | // reset the startPage to 1, as we can't keep the previous value as we are changing the search results list
|
---|
101 | if (key == "s1_startPage") {
|
---|
102 | searchString += "s1.startPage=1&";
|
---|
103 | } else {
|
---|
104 | searchString += key.replace(/_/g, ".") + "=" + makeURLComponentSafe(gs.cgiParams[key]) + "&";
|
---|
105 | }
|
---|
106 | // console.log("PARAM FOR key " + key + ":" + gs.cgiParams[key]);
|
---|
107 | // console.log("SAFE PARAM FOR " + key + ":" + makeURLComponentSafe(gs.cgiParams[key]));
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + facetQueryString + "excerptid=gs_content")
|
---|
112 | .done(function(response)
|
---|
113 | {
|
---|
114 | var $response = $(response);
|
---|
115 | $("#resultsArea").replaceWith($response.find('#resultsArea'));
|
---|
116 | $("#matchdocs").replaceWith($response.find('#matchdocs'));
|
---|
117 | // the term lists don't need to be updated, as we don't get back any term freq info
|
---|
118 | // for facet terms
|
---|
119 |
|
---|
120 | // only replace the facets that haven't been selected
|
---|
121 | var $current_facets = $(".facetContainer");
|
---|
122 |
|
---|
123 | for (var i=0; i<$current_facets.length; i++) {
|
---|
124 | var $current = $($current_facets[i]);
|
---|
125 | var indexName = $current.attr("indexName");
|
---|
126 |
|
---|
127 | if (!facetsThatAreChecked.has(indexName)) {
|
---|
128 | var $newNode =$response.find('#'+indexName);
|
---|
129 | $current.replaceWith($newNode);
|
---|
130 | enableMoreButtonIfNeeded(indexName);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | if(gs.cgiParams.favouritebasket == "on") {
|
---|
135 | // this will highlight the stars on the docs that are in favourites
|
---|
136 | favouritesCheckout();
|
---|
137 | }
|
---|
138 | if(typeof mapEnabled !== 'undefined') {
|
---|
139 |
|
---|
140 | facetedMapSearch(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + facetQueryString);
|
---|
141 |
|
---|
142 | }
|
---|
143 | });
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | function updateNextPrevLinks(facetQueryString) {
|
---|
148 |
|
---|
149 | if (facetQueryString === undefined) {
|
---|
150 | facetQueryString = getFacetQueryString();
|
---|
151 | }
|
---|
152 |
|
---|
153 | $("#nextTD,#nextArrowTD,#prevTD,#prevArrowTD").children("a").each(function() {
|
---|
154 | $(this).attr("href", $(this).attr("href") + "&"+facetQueryString);
|
---|
155 | });
|
---|
156 |
|
---|
157 | }
|
---|
158 |
|
---|
159 | function performRefinedSearchORIG()
|
---|
160 | {
|
---|
161 | var allCheckBoxes = $("#facetSelector input");
|
---|
162 | var counts = new Array();
|
---|
163 | for(var i = 0; i < allCheckBoxes.length; i++)
|
---|
164 | {
|
---|
165 | var current = $(allCheckBoxes[i]);
|
---|
166 | if(current.prop("checked"))
|
---|
167 | {
|
---|
168 | counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")");
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | var searchString = "";
|
---|
173 | for(var key in gs.cgiParams)
|
---|
174 | {
|
---|
175 | if (gs.cgiParams.hasOwnProperty(key))
|
---|
176 | {
|
---|
177 | searchString += key.replace(/_/g, ".") + "=" + makeURLComponentSafe(gs.cgiParams[key]) + "&";
|
---|
178 | //console.log("PARAM FOR key " + key + ":" + gs.cgiParams[key]);
|
---|
179 | //console.log("SAFE PARAM FOR " + key + ":" + makeURLComponentSafe(gs.cgiParams[key]));
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | var countsString = "s1.facetQueries=";
|
---|
184 | if(counts.length > 0)
|
---|
185 | {
|
---|
186 | var countsStringBuffer = "[";
|
---|
187 | for(var i = 0; i < counts.length; i++)
|
---|
188 | {
|
---|
189 | // escape any apostrophes in facet query terms
|
---|
190 | // (ext/solr's Greenstone3SearchHandler does the other half of handling them)
|
---|
191 | //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
192 | // calling makeURLSafe() here will ensure percent signs are escaped away too
|
---|
193 | // by the end of makeURLComponentSafe() call below
|
---|
194 | // Note that apostrophe's in URLs should get encoded, https://www.techwalla.com/articles/how-to-encode-an-apostrophe-in-a-url
|
---|
195 | // though the apostrophe is not in that other list of invalid and unsafe chars in urls dealt with in utility_scripts.js
|
---|
196 | countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\"";
|
---|
197 | if(i < counts.length - 1)
|
---|
198 | {
|
---|
199 | countsStringBuffer += ", ";
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | countsStringBuffer += "]";
|
---|
204 |
|
---|
205 | // We need to ensure that the *value* of s1.facetQueries (so everything after
|
---|
206 | // s1.facetQueries= and before the connecting &) are safe, which requires escaping,
|
---|
207 | // and are further also escaped to not be mistaken for their reserved meaning.
|
---|
208 | // : is a reserved character in URLs, [] are unsafe characters. All need escaping.
|
---|
209 | // So call makeURLComponentSafe(), not makeURLSafe()
|
---|
210 | countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1);
|
---|
211 | }
|
---|
212 |
|
---|
213 | countsString += "&";
|
---|
214 | console.log("STRING IS " + countsString);
|
---|
215 |
|
---|
216 | $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea")
|
---|
217 | .done(function(response)
|
---|
218 | {
|
---|
219 | $("#resultsArea").html("");
|
---|
220 | $("#resultsArea").html(response.substring(response.indexOf(">") + 1, response.lastIndexOf("<")));
|
---|
221 | if(gs.cgiParams.favouritebasket == "on") {
|
---|
222 | favouritesCheckout(); // called to add back in favourites icons (if favouritebasket active)
|
---|
223 | }
|
---|
224 | if(typeof mapEnabled !== 'undefined') {
|
---|
225 |
|
---|
226 | facetedMapSearch(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString);
|
---|
227 |
|
---|
228 | }
|
---|
229 | });
|
---|
230 |
|
---|
231 | }
|
---|
232 | var savedFacetHeight;
|
---|
233 | function expandFacets(indexname)
|
---|
234 | {
|
---|
235 | var tables = $(".facetTable");
|
---|
236 | for(var i = 0; i < tables.length; i++)
|
---|
237 | {
|
---|
238 | var current = $(tables[i]);
|
---|
239 | if(current.attr("indexname") == indexname)
|
---|
240 | {
|
---|
241 | savedFacetHeight = current.css("max-height");
|
---|
242 | current.css("max-height", "none");
|
---|
243 | break;
|
---|
244 | }
|
---|
245 |
|
---|
246 | }
|
---|
247 |
|
---|
248 | var morelink = $(".expandFacetList" + indexname);
|
---|
249 | morelink.css("display", "none");
|
---|
250 | var lesslink = $(".collapseFacetList" + indexname);
|
---|
251 | lesslink.css("display", "block");
|
---|
252 |
|
---|
253 |
|
---|
254 | }
|
---|
255 |
|
---|
256 | function collapseFacets(indexname)
|
---|
257 | {
|
---|
258 | console.log("collapse "+indexname);
|
---|
259 | var tables = $(".facetTable");
|
---|
260 |
|
---|
261 | for(var i = 0; i < tables.length; i++)
|
---|
262 | {
|
---|
263 | var current = $(tables[i]);
|
---|
264 | if(current.attr("indexname") == indexname)
|
---|
265 | {
|
---|
266 | current.css("max-height", savedFacetHeight);
|
---|
267 | break;
|
---|
268 | }
|
---|
269 |
|
---|
270 | }
|
---|
271 |
|
---|
272 | // the above code has hidden both the see more and see less links.
|
---|
273 | // display the see more one
|
---|
274 | var morelink = $(".expandFacetList" + indexname);
|
---|
275 | morelink.css("display", "block");
|
---|
276 | var lesslink = $(".collapseFacetList" + indexname);
|
---|
277 | lesslink.css("display", "none");
|
---|
278 |
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 |
|
---|
283 | function expandFacetListORIG(indexName, countSize)
|
---|
284 | {
|
---|
285 | var tables = $(".facetTable");
|
---|
286 |
|
---|
287 | for(var i = 0; i < tables.length; i++)
|
---|
288 | {
|
---|
289 | var current = $(tables[i]);
|
---|
290 | if(current.attr("indexName") == indexName)
|
---|
291 | {
|
---|
292 | var items = current.children("li");
|
---|
293 |
|
---|
294 | for(var j = 0; j < items.length; j++)
|
---|
295 | {
|
---|
296 | $(items[j]).css("display", "block");
|
---|
297 | }
|
---|
298 |
|
---|
299 | break;
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | // the above code has made both see more and see less links display=block, so we need to hide
|
---|
304 | // see more
|
---|
305 | var morelink = $(".expandFacetList" + indexName);
|
---|
306 | morelink.css("display", "none");
|
---|
307 | var lesslink = $(".collapseFacetList" + indexName);
|
---|
308 | lesslink.css("display", "block");
|
---|
309 |
|
---|
310 |
|
---|
311 | }
|
---|
312 |
|
---|
313 | function collapseFacetListORIG(indexName, countSize)
|
---|
314 | {
|
---|
315 | var tables = $(".facetTable");
|
---|
316 |
|
---|
317 | for(var i = 0; i < tables.length; i++)
|
---|
318 | {
|
---|
319 | var current = $(tables[i]);
|
---|
320 | if(current.attr("indexName") == indexName)
|
---|
321 | {
|
---|
322 | var items = current.children("li");
|
---|
323 |
|
---|
324 | for(var j = 0; j < items.length; j++)
|
---|
325 | {
|
---|
326 | if(j > countSize)
|
---|
327 | {
|
---|
328 | $(items[j]).css("display", "none");
|
---|
329 | }
|
---|
330 | }
|
---|
331 |
|
---|
332 | break;
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | // the above code has hidden both the see more and see less links.
|
---|
337 | // display the see more one
|
---|
338 | var morelink = $(".expandFacetList" + indexName);
|
---|
339 | morelink.css("display", "block");
|
---|
340 | var lesslink = $(".collapseFacetList" + indexName);
|
---|
341 | lesslink.css("display", "none");
|
---|
342 |
|
---|
343 | }
|
---|
344 |
|
---|