Skip to content

Commit 2297dc8

Browse files
committed
Merge branch 'AdvancedSearch'
2 parents 112376c + 480e751 commit 2297dc8

File tree

5 files changed

+429
-235
lines changed

5 files changed

+429
-235
lines changed

cors.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@
33
// adapted from https://www.html5rocks.com/en/tutorials/cors/
44
// Create the XHR object.
55
function createCORSRequest(method, url) {
6-
var xhr = new XMLHttpRequest();
7-
if ("withCredentials" in xhr) {
8-
// XHR for Chrome/Firefox/Opera/Safari.
9-
xhr.open(method, url, true);
10-
} else if (typeof XDomainRequest != "undefined") {
11-
// XDomainRequest for IE.
12-
xhr = new XDomainRequest();
13-
xhr.open(method, url);
14-
} else {
15-
// CORS not supported.
16-
xhr = null;
17-
}
18-
return xhr;
6+
var xhr = new XMLHttpRequest();
7+
if ("withCredentials" in xhr) {
8+
// XHR for Chrome/Firefox/Opera/Safari.
9+
xhr.open(method, url, true);
10+
} else if (typeof XDomainRequest != "undefined") {
11+
// XDomainRequest for IE.
12+
xhr = new XDomainRequest();
13+
xhr.open(method, url);
14+
} else {
15+
// CORS not supported.
16+
xhr = null;
17+
}
18+
return xhr;
1919
}
2020

2121
// Make the actual CORS request.
2222
function makeCorsRequest(url, successCallback, errorCallback) {
23-
var xhr = createCORSRequest("GET", url);
24-
if (!xhr) {
25-
alert("CORS not supported");
26-
return;
27-
}
23+
var xhr = createCORSRequest("GET", url);
24+
if (!xhr) {
25+
alert("CORS not supported");
26+
return;
27+
}
2828

29-
// Response handlers.
30-
xhr.onload = function() {
31-
var headers = xhr.getAllResponseHeaders().split("\n");
32-
var header_dict = {};
33-
for (var i = 0; i < headers.length; i++) {
34-
var parts = headers[i].split(": ");
35-
header_dict[parts[0].toLowerCase()] = parts[1];
36-
}
29+
// Response handlers.
30+
xhr.onload = function () {
31+
var headers = xhr.getAllResponseHeaders().split("\n");
32+
var header_dict = {};
33+
for (var i = 0; i < headers.length; i++) {
34+
var parts = headers[i].split(": ");
35+
header_dict[parts[0].toLowerCase()] = parts[1];
36+
}
3737

38-
successCallback(header_dict, xhr.responseText);
39-
};
38+
successCallback(header_dict, xhr.responseText);
39+
};
4040

41-
xhr.onerror = function() {
42-
errorCallback();
43-
};
41+
xhr.onerror = function () {
42+
errorCallback();
43+
};
4444

45-
xhr.send();
45+
xhr.send();
4646
}

pagination.js

Lines changed: 90 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,111 +3,113 @@
33

44
// https://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter
55
function updateQueryStringParameter(uri, key, value) {
6-
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
7-
var separator = uri.indexOf("?") !== -1 ? "&" : "?";
8-
if (uri.match(re)) {
9-
return uri.replace(re, "$1" + key + "=" + value + "$2");
10-
}
11-
else {
12-
return uri + separator + key + "=" + value;
13-
}
6+
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
7+
var separator = uri.indexOf("?") !== -1 ? "&" : "?";
8+
if (uri.match(re)) {
9+
return uri.replace(re, "$1" + key + "=" + value + "$2");
10+
}
11+
else {
12+
return uri + separator + key + "=" + value;
13+
}
1414
}
1515

1616

1717
function makePageLink(currentUrl, currentStart, start, linkText) {
18-
var uri = updateQueryStringParameter(currentUrl, "start", start);
19-
var tagStart = '<a href="';
20-
if (currentStart == start) {
21-
uri = "#";
22-
if (!linkText.toString().substring(0, 1) === "&") { // Don't modify arrows
23-
tagStart = '<a class="active" href="';
24-
}
25-
}
26-
var link = tagStart + uri + '">' + linkText + '</a>';
27-
return link;
18+
var uri = updateQueryStringParameter(currentUrl, "start", start);
19+
var tagStart = '<a href="';
20+
if (currentStart == start) {
21+
uri = "#";
22+
if (linkText.toString().substring(0, 1) !== "&") { // Don't modify arrows
23+
tagStart = '<a class="active" href="';
24+
}
25+
}
26+
var link = tagStart + uri + '">' + linkText + '</a>';
27+
return link;
2828
}
2929

3030

3131
// Creates links to additional pages of search results.
3232
// Requires a start URI argument indicating start index of search results
3333
// as passed to the server providing the search results.
3434
function showPageLinks(total, limit, showPages, currentStart, domElementId) {
35-
if (total <= limit) {
36-
return "";
37-
}
38-
39-
var currentUrl = window.location.href;
40-
var numPages = Math.ceil(total / limit);
41-
var currentPage = Math.floor(currentStart / limit) + 1;
42-
var pagesLeftRight = Math.floor(showPages / 2);
43-
var startPage = currentPage - pagesLeftRight;
44-
var endPage = currentPage + pagesLeftRight;
45-
46-
if (endPage > numPages) {
47-
endPage = numPages;
48-
startPage = endPage - showPages + 1;
49-
}
50-
if (startPage <= 0) {
51-
startPage = 1;
52-
endPage = showPages;
53-
if (endPage > numPages) {
54-
endPage = numPages;
55-
}
56-
}
57-
58-
var link_list = [];
59-
link_list.push(makePageLink(currentUrl, currentStart, 0, "&laquo;"));
60-
for (var i = startPage; i <= endPage; i++) {
61-
var startIndex = (i - 1) * limit;
62-
link_list.push(makePageLink(currentUrl, currentStart, startIndex, i));
63-
}
64-
var lastIndex = (numPages - 1) * limit;
65-
link_list.push(
66-
makePageLink(currentUrl, currentStart, lastIndex, "&raquo;"));
67-
68-
var html = link_list.join("");
69-
document.getElementById(domElementId).innerHTML = html;
35+
if (total <= limit) {
36+
return "";
37+
}
38+
39+
var el = document.getElementById(domElementId);
40+
if (!el) return;
41+
42+
var currentUrl = window.location.href;
43+
var numPages = Math.ceil(total / limit);
44+
var currentPage = Math.floor(currentStart / limit) + 1;
45+
var pagesLeftRight = Math.floor(showPages / 2);
46+
var startPage = currentPage - pagesLeftRight;
47+
var endPage = currentPage + pagesLeftRight;
48+
49+
if (endPage > numPages) {
50+
endPage = numPages;
51+
startPage = endPage - showPages + 1;
52+
}
53+
if (startPage <= 0) {
54+
startPage = 1;
55+
endPage = showPages;
56+
if (endPage > numPages) {
57+
endPage = numPages;
58+
}
59+
}
60+
61+
var link_list = [];
62+
link_list.push(makePageLink(currentUrl, currentStart, 0, "&laquo;"));
63+
for (var i = startPage; i <= endPage; i++) {
64+
var startIndex = (i - 1) * limit;
65+
link_list.push(makePageLink(currentUrl, currentStart, startIndex, i));
66+
}
67+
var lastIndex = (numPages - 1) * limit;
68+
link_list.push(
69+
makePageLink(currentUrl, currentStart, lastIndex, "&raquo;"));
70+
71+
el.innerHTML = link_list.join("");
7072
}
7173

7274

7375
function escapeHtml(unsafe) {
74-
return unsafe
75-
.replace(/&/g, "&amp;")
76-
.replace(/</g, "&lt;")
77-
.replace(/>/g, "&gt;")
78-
.replace(/"/g, "&quot;")
79-
.replace(/'/g, "&#039;");
76+
return unsafe
77+
.replace(/&/g, "&amp;")
78+
.replace(/</g, "&lt;")
79+
.replace(/>/g, "&gt;")
80+
.replace(/"/g, "&quot;")
81+
.replace(/'/g, "&#039;");
8082
}
8183

8284

8385
function showResultCount(query, total, limitPerPage, currentStartIndex, domElementId) {
84-
if (total == 0) {
85-
return;
86-
}
87-
88-
var s = "";
89-
if (total > 1) {
90-
s = "s";
91-
}
92-
var found = "<p>Found " + total + " result" + s;
93-
if (query != "" && query != null) {
94-
query = escapeHtml(query);
95-
var forQuery = ' for <span class="result-query">' + query + '</span>';
96-
}
97-
else {
98-
var forQuery = "";
99-
}
100-
if (total <= limitPerPage) {
101-
var showing = "</p>";
102-
}
103-
else {
104-
var fromCount = currentStartIndex + 1;
105-
var toCount = currentStartIndex + limitPerPage;
106-
if (toCount > total) {
107-
toCount = total;
108-
}
109-
var showing = (". Showing results " + fromCount + " to " + toCount + ".</p>");
110-
}
111-
var element = document.getElementById(domElementId);
112-
element.innerHTML = found + forQuery + showing;
86+
var element = document.getElementById(domElementId);
87+
if (total == 0 || !element) {
88+
return;
89+
}
90+
91+
var s = "";
92+
if (total > 1) {
93+
s = "s";
94+
}
95+
var found = "<p>Found " + total + " result" + s;
96+
if (query != "" && query != null) {
97+
query = escapeHtml(query);
98+
var forQuery = ' for <span class="result-query">' + query + '</span>';
99+
}
100+
else {
101+
var forQuery = "";
102+
}
103+
if (limitPerPage === null || total <= limitPerPage) {
104+
var showing = "</p>";
105+
}
106+
else {
107+
var fromCount = currentStartIndex + 1;
108+
var toCount = currentStartIndex + limitPerPage;
109+
if (toCount > total) {
110+
toCount = total;
111+
}
112+
var showing = (". Showing results " + fromCount + " to " + toCount + ".</p>");
113+
}
114+
element.innerHTML = found + forQuery + showing;
113115
}

search.css

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
.loading {
2-
display: none;
32
width: 100px;
4-
height: 100px;
5-
6-
position: absolute;
7-
top:0;
8-
bottom: 0;
9-
left: 0;
10-
right: 0;
11-
123
margin: auto;
134
}
145

156
.search-input {
167
width: 250px;
8+
margin-bottom: 10px;
179
}
1810

1911
.resultCount {
@@ -24,8 +16,11 @@
2416
font-weight: bold;
2517
}
2618

19+
#searchResults {
20+
margin-top: 10px;
21+
}
22+
2723
.pagination {
28-
text-align: center;
2924
margin: 16px 8px 16px 8px;
3025
}
3126
.pagination a {
@@ -34,9 +29,61 @@
3429
text-decoration: none;
3530
}
3631
.pagination a.active {
37-
background-color: #4CAF50;
32+
background-color: #0d3760;
3833
color: white;
3934
}
4035
.pagination a:hover:not(.active) {
4136
background-color: #ddd;
37+
}
38+
39+
/* collapsible */
40+
input[type='checkbox'].collapse-toggle {
41+
display: none;
42+
}
43+
44+
.lbl-toggle {
45+
cursor: pointer;
46+
transition: all 0.25s ease-out;
47+
}
48+
49+
.lbl-toggle::before {
50+
content: ' ';
51+
display: inline-block;
52+
53+
border-top: 5px solid transparent;
54+
border-bottom: 5px solid transparent;
55+
border-left: 5px solid currentColor;
56+
57+
vertical-align: middle;
58+
margin-right: .1rem;
59+
transform: translateY(-2px);
60+
61+
transition: transform .2s ease-out;
62+
}
63+
64+
.collapse-toggle:checked + .lbl-toggle::before {
65+
transform: rotate(90deg) translateX(-3px);
66+
}
67+
68+
.collapse-toggle:checked + .lbl-toggle {
69+
border-bottom-right-radius: 0;
70+
border-bottom-left-radius: 0;
71+
}
72+
73+
.collapsible {
74+
padding: 0 11px;
75+
max-height: 0;
76+
overflow: hidden;
77+
transition: max-height .25s ease-in-out;
78+
}
79+
80+
.input-block {
81+
border-bottom: 1px dashed gray;
82+
margin-bottom: 5px;
83+
max-width: 256px;
84+
}
85+
86+
.group-label {
87+
font-weight: bold;
88+
margin-left: 7px;
4289
}

0 commit comments

Comments
 (0)