-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
94 lines (89 loc) · 2.24 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var search = instantsearch({
// Replace with your own values
appId: 'NJWL3M9801',
apiKey: 'd15c5363b0021b637de39ec8c61dc439', // search only API key, no ADMIN key
indexName: 'tedx_registrant',
urlSync: true
});
function app(opts) {
var search = instantsearch({
appId: opts.appId,
apiKey: opts.apiKey,
indexName: opts.indexName,
urlSync: true
});
var widgets = [
instantsearch.widgets.searchBox({
container: '#search-input',
placeholder: 'Search for products'
}),
instantsearch.widgets.hits({
container: '#hits',
hitsPerPage: 10,
templates: {
item: getTemplate('hit'),
empty: getTemplate('no-results')
}
}),
instantsearch.widgets.stats({
container: '#stats'
}),
instantsearch.widgets.sortBySelector({
container: '#sort-by',
autoHideContainer: true,
indices: [{
name: opts.indexName, label: 'Most relevant'
}, {
name: opts.indexName + '_price_asc', label: 'Lowest price'
}, {
name: opts.indexName + '_price_desc', label: 'Highest price'
}]
}),
instantsearch.widgets.pagination({
container: '#pagination',
scrollTo: '#search-input'
}),
instantsearch.widgets.refinementList({
container: '#category',
attributeName: 'categories',
limit: 10,
operator: 'or',
templates: {
header: getHeader('Category')
}
}),
instantsearch.widgets.refinementList({
container: '#brand',
attributeName: 'brand',
limit: 10,
operator: 'or',
templates: {
header: getHeader('Brand')
}
}),
instantsearch.widgets.rangeSlider({
container: '#price',
attributeName: 'price',
templates: {
header: getHeader('Price')
}
}),
instantsearch.widgets.refinementList({
container: '#type',
attributeName: 'type',
limit: 10,
operator: 'and',
templates: {
header: getHeader('Type')
}
})
];
widgets.forEach(search.addWidget, search);
search.start();
}
function getTemplate(templateName) {
return document.querySelector('#' + templateName + '-template').innerHTML;
}
function getHeader(title) {
return '<h5>' + title + '</h5>';
}