-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbsearch.html
More file actions
216 lines (176 loc) · 5.36 KB
/
cbsearch.html
File metadata and controls
216 lines (176 loc) · 5.36 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Search CycleBlaze</title>
<!-- <link href="https://www.cycleblaze.com/assets/styles.css?v=50" rel="stylesheet"> -->
<!-- <link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700|Merriweather:400,700,400italic,700italic" rel="stylesheet" type="text/css"> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/algoliasearch@3/dist/algoliasearchLite.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/algoliasearch-helper@2.24.0/dist/algoliasearch.helper.min.js"></script
</head>
<body class='text-block'>
<style>
<!-- * { -->
<!-- font-family: 'helvetica', sans-serif; -->
<!-- } -->
.content-type {
display: table;
}
.content-title {
display: table;
}
.content-url {
display: table;
}
.content-snippet {
display: table;
}
#search-box {
margin: 1em 1em 3em;
width: calc(100% - 2em);
padding: 1em;
border: 1px solid #ccc;
border-radius: 2px;
box-sizing: border-box;
}
#container {
max-width: 150px;
width: 100%;
float: left;
padding: 0 1em;
margin: 0;
list-style: none;
}
#container {
max-width: calc(100% - 4em);
}
#container .hit {
padding: 8px 0;
}
</style>
<input autocomplete="off" id="search-box" id="q" placeholder="Search..." type="text" spellcheck="false"/>
<div class="hits-wrapper" id=container>
<h3><span id="results-header">Results</span></h3>
<div id="hits"></div>
<br>
<div id="pagination">
<a id='first-page' href='#'>First</a>
<a id='previous-page' href='#'>Previous</a>
<a id='next-page' href='#'>Next</a>
<a id='last-page' href='#'>Last</a>
</div>
</div>
<script>
// Algolia client. Mandatory to instantiate the Helper.
var algolia = algoliasearch('ODTKY0RQS9', '214775945fb76f1b04edceeba62db21c');
// Algolia Helper
var helper = algoliasearchHelper(algolia, 'CycleBlaze', {
hitsPerPage: 5,
getRankingInfo: true
});
$( document ).ready(function() {
$("#first-page").click(function() {
helper.setPage(0).search();
});
$("#previous-page").click(function() {
var currentPage = helper.getPage();
if (currentPage > 0) {
helper.setPage(currentPage - 1).search();
}
});
$("#next-page").click(function() {
var currentPage = helper.getPage();
if (currentPage < helper.lastResults.nbPages - 1) {
helper.setPage(currentPage + 1).search();
}
});
$("#last-page").click(function() {
helper.setPage(helper.lastResults.nbPages - 1).search();
});
$("#results-header").hide();
$("#first-page").hide();
$("#previous-page").hide();
$("#next-page").hide();
$("#last-page").hide();
// Bind the result event to a function that will update the results
helper.on("result", searchCallback);
// The different parts of the UI that we want to use in this example
var $inputfield = $("#search-box");
var $hits = $('#hits');
// When there is a new character input:
// - update the query
// - trigger the search
$inputfield.keyup(function(e) {
var searchTerm = $.trim($inputfield.val());
console.log('"' + searchTerm + '"' );
if (searchTerm === '') {
$("#results-header").hide();
$("#first-page").hide();
$("#previous-page").hide();
$("#next-page").hide();
$("#last-page").hide();
$hits.html("");
} else {
helper.setQuery(searchTerm).search();
}
});
// Trigger a first search, so that we have a page with results
// from the start.
//helper.search();
// Result event callback
function searchCallback(content) {
if (content.hits.length === 0) {
// If there is no result we display a friendly message
// instead of an empty page.
$hits.empty().html("No results :(");
$("#results-header").hide();
$("#first-page").hide();
$("#previous-page").hide();
$("#next-page").hide();
$("#last-page").hide();
return;
}
// Hits/results rendering
renderHits($hits, content);
}
function renderHits($hits, results) {
$("#results-header").html(results.nbHits + " result" + (results.nbHits == 1 ? "" : "s"));
var s = "";
for (var i = 0; i < results.hits.length; ++i) {
s += '<div class="search-result">';
s += '<span class="content-type">Profile</span>';
s += '<span class="content-title"><a href="https://www.cycleblaze.com/profile/' + results.hits[i].username + '/">' + results.hits[i]._snippetResult.fname.value + ' ' + results.hits[i]._snippetResult.lname.value + '</a></span>';
s += '<span class="content-url"><a href="https://www.cycleblaze.com/profile/' + results.hits[i].username + '/">' + 'www.cycleblaze.com/profile/' + results.hits[i]._snippetResult.username.value + '</a></span>';
if (results.hits[i]._snippetResult.Profile.matchLevel !== "none") {
s += '<span class="content-snippet">' + results.hits[i]._snippetResult.Profile.value + '</span>';
}
s += '</div>';
s += '<br>';
}
$hits.html(s);
if (results.hits.length > 0) {
$("#results-header").show();
$("#first-page").show();
$("#previous-page").show();
$("#next-page").show();
$("#last-page").show();
if (results.page === 0) {
$("#first-page").hide();
$("#previous-page").hide();
}
if (results.page === results.nbPages - 1) {
$("#next-page").hide();
$("#last-page").hide();
}
}else {
$("#results-header").hide();
$("#first-page").hide();
$("#previous-page").hide();
$("#next-page").hide();
$("#last-page").hide();
}
}
});
</script>
</body>
</html>