source: main/trunk/greenstone3/web/interfaces/default/js/facet-scripts.js@ 33016

Last change on this file since 33016 was 33016, checked in by ak19, 5 years ago

Getting facet searching working again in tomcat 8, where it had broken due to reserved and unsafe chars in the URL. The fix required using the recent makeURLSafe() and makeURLComponentSafe() methods in facet-scripts.js. This meant that these functions and their helper functions needed to be moved into their own script file, newly introducing utility_scripts.js, rather than remain in document_scripts.js since doc_scripts.js is not included on the query.xsl page which includes facet-scripts.js

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1function performRefinedSearch()
2{
3 var allCheckBoxes = $("#facetSelector input");
4 var counts = new Array();
5 for(var i = 0; i < allCheckBoxes.length; i++)
6 {
7 var current = $(allCheckBoxes[i]);
8 if(current.prop("checked"))
9 {
10 counts.push(current.parent().parent().attr("indexName") + ":(\"" + current.siblings("span").first().html() + "\")");
11 }
12 }
13
14 var searchString = "";
15 for(var key in gs.cgiParams)
16 {
17 if (gs.cgiParams.hasOwnProperty(key))
18 {
19 searchString += key.replace(/_/g, ".") + "=" + gs.cgiParams[key] + "&";
20 }
21 }
22
23 var countsString = "s1.facetQueries=";
24 if(counts.length > 0)
25 {
26 var countsStringBuffer = "[";
27 for(var i = 0; i < counts.length; i++)
28 {
29 // escape any apostrophes in facet query terms
30 // (ext/solr's Greenstone3SearchHandler does the other half of handling them)
31 //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
32 // calling makeURLSafe() here will ensure percent signs are escaped away too
33 // by the end of makeURLComponentSafe() call below
34 countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\"";
35 if(i < counts.length - 1)
36 {
37 countsStringBuffer += ", ";
38 }
39 }
40
41 countsStringBuffer += "]";
42
43 // We need to ensure that the *value* of s1.facetQueries (so everything after
44 // s1.facetQueries= and before the connecting &) are safe, which requires escaping,
45 // and are further also escaped to not be mistaken for their reserved meaning.
46 // : is a reserved character in URLs, [] are unsafe characters. All need escaping.
47 // So call makeURLComponentSafe(), not makeURLSafe()
48 countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1);
49 }
50
51 countsString += "&";
52 console.log("STRING IS " + countsString);
53
54 $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea")
55 .done(function(response)
56 {
57 $("#resultsArea").html("");
58 $("#resultsArea").html(response.substring(response.indexOf(">") + 1, response.lastIndexOf("<")));
59 });
60}
61
62function expandFacetList(indexName, countSize)
63{
64 var tables = $(".facetTable");
65
66 for(var i = 0; i < tables.length; i++)
67 {
68 var current = $(tables[i]);
69 if(current.attr("indexName") == indexName)
70 {
71 var items = current.children("li");
72
73 for(var j = 0; j < items.length; j++)
74 {
75 $(items[j]).css("display", "block");
76 }
77
78 break;
79 }
80 }
81
82 // the above code has made both see more and see less links display=block, so we need to hide
83 // see more
84 var morelink = $(".expandFacetList" + indexName);
85 morelink.css("display", "none");
86
87}
88
89function collapseFacetList(indexName, countSize)
90{
91 var tables = $(".facetTable");
92
93 for(var i = 0; i < tables.length; i++)
94 {
95 var current = $(tables[i]);
96 if(current.attr("indexName") == indexName)
97 {
98 var items = current.children("li");
99
100 for(var j = 0; j < items.length; j++)
101 {
102 if(j > countSize)
103 {
104 $(items[j]).css("display", "none");
105 }
106 }
107
108 break;
109 }
110 }
111
112 // the above code has hidden both the see more and see less links.
113 // display the see more one
114 var morelink = $(".expandFacetList" + indexName);
115 morelink.css("display", "block");
116
117}
118
Note: See TracBrowser for help on using the repository browser.