-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (54 loc) · 2.15 KB
/
main.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
var client = algoliasearch('IZIZ178186', '68e27258c4cea10d47853b6c3dab5d20');
var helper = algoliasearchHelper(client, 'dev_DENVER_RESTAURANTS_ENRICHED', {
facets: ['food_types', 'payment_options', 'stars_count']
});
helper.on('result', function(content) {
renderFacetList(content);
renderHits(content);
});
function renderHits(content) {
$('#container').html(function() {
return $.map(content.hits, function(hit) {
console.log(hit._highlightResult);
return '<li><strong>' + hit._highlightResult.name.value + '</strong>' +
'<div><span>' + hit._highlightResult.stars_count.value + ' (' + hit._highlightResult.reviews_count.value + ' reviews)' + '</span></div>' +
'<div><span>' + hit._highlightResult.food_types.value + ' | '
+ hit._highlightResult.neighborhood.value + ' | ' +
hit._highlightResult.price_range.value + '</span></div>' +
'</li>';
});
});
}
$('#facet-cuisine').on('click', 'input[type=checkbox]', function(e) {
var facetValue = $(this).data('facet');
helper.toggleRefinement('food_types', facetValue).search();
});
function renderFacetList(content) {
$('#facet-cuisine').html(function() {
return $.map(content.getFacetValues('food_types'), function(facet) {
var checkbox = $('<input type=checkbox>')
.data('facet', facet.name)
.attr('id', 'fl-' + facet.name);
if(facet.isRefined) checkbox.attr('checked', 'checked');
var label = $('<label>').html(facet.name + ' (' + facet.count + ')')
.attr('for', 'fl-' + facet.name);
return $('<li>').append(checkbox).append(label);
});
});
/*$('#facet-payment-option').html(function() {
return $.map(content.getFacetValues('payment_options'), function(facet) {
var checkbox = $('<input type=checkbox>')
.data('facet', facet.name)
.attr('id', 'fl-' + facet.name);
if(facet.isRefined) checkbox.attr('checked', 'checked');
var label = $('<label>').html(facet.name + ' (' + facet.count + ')')
.attr('for', 'fl-' + facet.name);
return $('<li>').append(checkbox).append(label);
});
});*/
}
$('#search-box').on('keyup', function() {
helper.setQuery($(this).val())
.search();
});
helper.search();