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

Last change on this file since 33286 was 33286, checked in by kjdon, 5 years ago

standardising the basket names. berryBasket, favouriteBasket, documentBasket. variables etc will all follow this pattern. cgi params berrybasket, favouritebasket. etc

  • Property svn:executable set to *
File size: 3.7 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 if(gs.cgiParams.berrybasket == "on") {
60 berryCheckout(); // called to add back in berries (if berrybasket active)
61 }
62 if(gs.cgiParams.favouritebasket == "on") {
63 favouritesCheckout(); // called to add back in favourites icons (if favouritebasket active)
64 }
65 });
66}
67
68function expandFacetList(indexName, countSize)
69{
70 var tables = $(".facetTable");
71
72 for(var i = 0; i < tables.length; i++)
73 {
74 var current = $(tables[i]);
75 if(current.attr("indexName") == indexName)
76 {
77 var items = current.children("li");
78
79 for(var j = 0; j < items.length; j++)
80 {
81 $(items[j]).css("display", "block");
82 }
83
84 break;
85 }
86 }
87
88 // the above code has made both see more and see less links display=block, so we need to hide
89 // see more
90 var morelink = $(".expandFacetList" + indexName);
91 morelink.css("display", "none");
92
93}
94
95function collapseFacetList(indexName, countSize)
96{
97 var tables = $(".facetTable");
98
99 for(var i = 0; i < tables.length; i++)
100 {
101 var current = $(tables[i]);
102 if(current.attr("indexName") == indexName)
103 {
104 var items = current.children("li");
105
106 for(var j = 0; j < items.length; j++)
107 {
108 if(j > countSize)
109 {
110 $(items[j]).css("display", "none");
111 }
112 }
113
114 break;
115 }
116 }
117
118 // the above code has hidden both the see more and see less links.
119 // display the see more one
120 var morelink = $(".expandFacetList" + indexName);
121 morelink.css("display", "block");
122
123}
124
Note: See TracBrowser for help on using the repository browser.