-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
71 lines (63 loc) · 1.43 KB
/
app.js
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
function hitTemplate(hit) {
return `
<div class="hit">
<div class="hit-content">
<div onclick="getPage(${hit.catalog_num})">
<h4>${hit._highlightResult.title.value}</h4>
<p>${hit._highlightResult.instructor.value}, ${hit._highlightResult.term.value}</p>
</div>
</div>
</div>
`;
}
var currentHits = [];
function wipeCurrentHits(event) {
var x = event.which || event.keyCode;
if (x != 13) {
currentHits = [];
}
}
function enterEvent(event) {
var x = event.which || event.keyCode;
if (currentHits) {
if (x == 13) {
getPage(currentHits[0].course_id)
}
}
}
function getPage(id){
window.location.href = './productpage.html?course_id=' + id;
}
const search = instantsearch({
appId: "C2ZUSONNI6",
apiKey: "ace8178d8d8f86f292f600e2e324e5fe",
indexName: "EECS_courses",
searchFunction: function(helper) {
if (helper.state.query === '') {
document.querySelector('#hits').innerHTML = '';
return;
}
helper.search();
}
});
search.addWidget(
instantsearch.widgets.hits({
container: "#hits",
hitsPerPage: 10,
templates: {
empty: "No results.",
item: function(hit) {
currentHits.push(hit);
return hitTemplate(hit);
}
}
})
);
search.addWidget(
instantsearch.widgets.searchBox({
container: "#searchbox",
placeholder: "SEARCH FOR CLASSES",
autofocus: false
})
);
search.start();