forked from andreaskoch/allmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchjs.go
54 lines (48 loc) · 1.15 KB
/
searchjs.go
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
// Copyright 2014 Andreas Koch. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package themefiles
const SearchJs = `
// data source: titles
var titlesDataSource = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 10,
prefetch: {
url: '/titles.json',
}
});
titlesDataSource.initialize();
// data source: search
var searchDataSource = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '/search.json?q=%QUERY'
});
searchDataSource.initialize();
$('.typeahead').typeahead(
{
minLength: 1,
items: 10,
highlight: true,
},
{
name: 'item-titles',
displayKey: 'value',
source: titlesDataSource.ttAdapter(),
templates: {
header: '<h3>Items</h3>'
}
},
{
name: 'searchresults',
displayKey: 'value',
source: searchDataSource.ttAdapter(),
templates: {
header: '<h3>Search Results</h3>'
}
}
).on('typeahead:selected', function(event, datum) {
window.location = datum.route;
});
`