-
Notifications
You must be signed in to change notification settings - Fork 50
/
custom_dropdown.html
57 lines (53 loc) · 2.2 KB
/
custom_dropdown.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
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type='text/javascript' src='jquery.swiftype.autocomplete.js'></script>
<link type='text/css' rel='stylesheet' href='autocomplete.css' media='all' />
<script type='text/javascript'>
$(function() {
var customResultRenderFunction = function(ctx, data) {
var withSections = [],
noSections = [];
$.each(data, function(docType, results) {
$.each(results, function(idx, result) {
if (result.sections && result.sections.length > 15) {
withSections.push(result);
} else {
noSections.push(result);
}
});
});
var withSectionsList = $('<ul class="with_sections"></ul>'),
noSectionsList = $('<ul class="no_sections"></ul>');
$.each(withSections, function(idx, item) {
ctx.registerResult($('<li class="result"><p>' + item.highlight['title'] + '</p></li>').appendTo(withSectionsList), item);
});
$.each(noSections, function(idx, item) {
ctx.registerResult($('<li class="result"><p>' + item.highlight['title'] + '</p></li>').appendTo(noSectionsList), item);
});
if (withSections.length > 0) {
withSectionsList.appendTo(ctx.list);
}
if (noSections.length > 0) {
noSectionsList.appendTo(ctx.list);
}
};
$('#st-search-input').swiftype({
engineKey: '5jZG1gmmCTFYbSSDjpqq',
resultRenderFunction: customResultRenderFunction,
suggestionListType: 'div',
resultListSelector: '.result',
highlightFields: {'page': {'title': {'size': 100, 'fallback': true }}},
fetchFields: {page: ['url']}
});
});
</script>
</head>
<body>
<form>
<h1>Example Swiftype Autocomplete installation</h1>
Search your site: <input type='text' id='st-search-input' class='st-search-input' />
</form>
</body>
</html>