-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
244 lines (234 loc) · 9.33 KB
/
search.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
title: "Search"
help_section: "search"
---
<!doctype html>
<html>
<head lang="en">
{{> head.html }}
<style>
::placeholder {
color: #ccc;
font-size: 80%;
font-style: italic;
}
.reset-icon {
display: inline-block;
width: 1em;
height: 1em;
position: relative;
z-index: 1;
right: 2.7em;
top: 0;
bottom: .3em;
text-align: center;
padding-bottom: .3em;
font-family: sans-serif;
font-size: 2em;
color: #888;
cursor: pointer;
}
#bottom {
text-align: center;
color: #888;
display: none;
height: 3em;
}
#more {
color: #888;
}
#more:hover {
color: blue;
}
</style>
</head>
<body onload="search()">
<div class="header">
{{> closebutton.html }}
{{> helpbutton.html }}
<h1>
<div class="header-left">
<a href="/">
<img id="small-logo" src="/images/naturecompanion.svg" />
</a>
<span>Search</span>
</div>
</h1>
</div>
<div style="margin-left: 3vw; margin-top: 3vw;">
<label for="search"></label>
<div style="position: relative;">
<!-- inputmode="search" on Android breaks Enter key -->
<input type="text" id="query" autofocus
placeholder="enter words to search for"
style="font-size: 150%; padding: .3em; width: 70%;">
<img src="/images/search.svg"
style="width: 1.7em; height: 1.7em; vertical-align: text-bottom;
padding-left: .5em; padding-right: .5em; cursor: pointer;"
onclick="search()" />
<span class="reset-icon" onclick="reset()">x</span>
</div>
<div style="margin-top: .3em;">
<input type="checkbox" onchange="search()" class="hidden" id="_bc">
<label class="term" for="_bc">BC</label>
<input type="checkbox" onchange="search()" class="hidden" id="_ab">
<label class="term" for="_ab">AB</label>
<input type="checkbox" onchange="search()" class="hidden" id="_sk">
<label class="term" for="_sk">SK</label>
<input type="checkbox" onchange="search()" class="hidden" id="_mb">
<label class="term" for="_mb">MB</label>
<input type="checkbox" onchange="search()" class="hidden" id="_desert">
<label class="term" for="_desert">desert</label>
<input type="checkbox" onchange="search()" class="hidden" id="_forest">
<label class="term" for="_forest">forest</label>
<input type="checkbox" onchange="search()" class="hidden" id="_grassland">
<label class="term" for="_grassland">grassland</label>
<input type="checkbox" onchange="search()" class="hidden" id="_mountain">
<label class="term" for="_mountain">mountain</label>
<input type="checkbox" onchange="search()" class="hidden" id="_ocean">
<label class="term" for="_ocean">ocean</label>
<input type="checkbox" onchange="search()" class="hidden" id="_urban">
<label class="term" for="_urban">urban</label>
<input type="checkbox" onchange="search()" class="hidden" id="_wetland">
<label class="term" for="_wetland">wetland</label>
<input type="checkbox" onchange="search()" class="hidden" id="_birds">
<label class="term" for="_birds">Birds</label>
<input type="checkbox" onchange="search()" class="hidden" id="_animals">
<label class="term" for="_animals">Animals</label>
<input type="checkbox" onchange="search()" class="hidden" id="_plants">
<label class="term" for="_plants">Plants</label>
<input type="checkbox" onchange="search()" class="hidden" id="_herps">
<label class="term" for="_herps">Reptiles&</label>
<input type="checkbox" onchange="search()" class="hidden" id="_insects">
<label class="term" for="_insects">Insects&</label>
<input type="checkbox" onchange="search()" class="hidden" id="_trees">
<label class="term" for="_trees">Trees&</label>
</div>
</div>
<div id="results" class="list">
</div>
<div id="bottom">
<span id="showing"></span>
<a id="more" href="javascript:void(0)" onclick="more()">Show More</a>
</div>
<script src="/lunr.js"></script>
<script src="/map.js"></script>
<script src="/idx.js"></script>
<script>
var pipelineFunction = function (token) {
if (token.toString() == "grey")
return token.update(function () { return "gray" });
else if (token.toString() == "harbour")
return token.update(function () { return "harbor" });
else
return token;
}
lunr.Pipeline.registerFunction(pipelineFunction, 'normaliseSpelling');
let index = lunr.Index.load(idx);
const hasTouch = 'ontouchstart' in window
const q = document.getElementById("query");
q.addEventListener("keyup", function (event) {
if (event.key === "Enter")
search();
});
let nShow = 10;
function search() {
nShow = 10;
search2();
}
function search2() {
if (q.value == "")
return;
if (hasTouch)
q.blur();
document.getElementById("results").innerHTML = "";
document.getElementById("bottom").style.display = "none";
let results = index.search(q.value);
let sel = getSel();
results = results.filter((r) => filter(r, sel));
const nMatched = results.length;
results = results.slice(0, nShow);
results.forEach(r => addItem(r.ref));
if (nShow < nMatched) {
document.getElementById("bottom").style.display = "block";
let showing = document.getElementById('showing');
showing.innerText = "Showing first " + nShow + " of " + nMatched + " matches.";
}
}
function more() {
nShow += 10;
search2();
setTimeout(function () { window.scrollTo(0, 9999); }, 50)
}
function getSel() {
let secSel = [];
for (let sec of ['birds', 'animals', 'plants', 'herps',
'insects', 'trees']) {
let elem = document.getElementById('_' + sec);
if (elem.checked)
secSel.push(sec);
}
let habSel = [];
for (let hab of ['desert', 'forest', 'grassland', 'mountain',
'ocean', 'urban', 'wetland']) {
let elem = document.getElementById('_' + hab);
if (elem.checked)
habSel.push(hab);
}
let locSel = [];
for (let loc of ['bc', 'ab', 'sk', 'mb']) {
let elem = document.getElementById('_' + loc);
if (elem.checked)
locSel.push(loc);
}
return {"sec": secSel, "hab": habSel, "loc": locSel};
}
function filter(r, sel) {
let item = map[r.ref];
let section = [item[0]];
let habitats = item[2];
let locations = item[3];
return matches(section, sel.sec) &&
matches(habitats, sel.hab) && matches(locations, sel.loc);
}
function matches(set, sel) {
if (sel.length == 0)
return true;
for (let x of sel)
if (set.includes(x))
return true;
return false;
}
function addItem(id) {
const dir = map[id][0] + '/';
const name = map[id][1];
let item = document.createElement("div");
item.setAttribute('class', "item");
let a = document.createElement("a");
a.setAttribute('href', "/" + dir + id + "/");
let img = document.createElement("img");
img.setAttribute('src', "/photos/" + dir + "small/" + id + ".jpg");
img.setAttribute('class', "small");
a.appendChild(img);
let nameDiv = document.createElement("div");
nameDiv.setAttribute('class', "name");
nameDiv.innerHTML = name;
a.appendChild(nameDiv);
item.appendChild(a);
let results = document.getElementById("results");
results.appendChild(item);
}
function reset() {
q.value = ""
for (let id of ['birds', 'animals', 'plants', 'herps',
'insects', 'trees', 'desert', 'forest', 'grassland', 'mountain',
'ocean', 'urban', 'wetland', 'bc', 'ab', 'sk', 'mb'])
document.getElementById('_' + id).checked = false;
document.getElementById("results").innerHTML = "";
document.getElementById("bottom").style.display = "none";
if (!hasTouch)
q.focus();
}
</script>
</body>
</html>