mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add searchform.js
This commit is contained in:
parent
f65ce65ddd
commit
cb88a07f8e
1 changed files with 55 additions and 0 deletions
55
resources/assets/js/components/searchform.js
vendored
Normal file
55
resources/assets/js/components/searchform.js
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
let queryEngine = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: process.env.MIX_API_SEARCH + '/%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
});
|
||||
|
||||
$('.search-form .search-form-input').typeahead(null, {
|
||||
name: 'search',
|
||||
display: 'value',
|
||||
source: queryEngine,
|
||||
limit: 20,
|
||||
templates: {
|
||||
empty: [
|
||||
'<div class="alert alert-danger mb-0">',
|
||||
'unable to find any matches',
|
||||
'</div>'
|
||||
].join('\n'),
|
||||
suggestion: function(data) {
|
||||
let type = data.type;
|
||||
let res = null;
|
||||
switch(type) {
|
||||
case 'hashtag':
|
||||
res = '<a href="'+data.url+'">' +
|
||||
'<div class="media d-flex align-items-center">' +
|
||||
'<div class="mr-3 h4 text-muted">#</div>' +
|
||||
'<div class="media-body text-truncate">' +
|
||||
'<p class="mt-0 mb-0 font-weight-bold">'+data.value+'</p>' +
|
||||
'<p class="text-muted mb-0">'+data.count+' posts</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</a>';
|
||||
break;
|
||||
case 'profile':
|
||||
res = '<a href="'+data.url+'">' +
|
||||
'<div class="media d-flex align-items-center">' +
|
||||
'<div class="mr-3 h4 text-muted"><span class="icon-user"></span></div>' +
|
||||
'<div class="media-body text-truncate">' +
|
||||
'<p class="mt-0 mb-0 font-weight-bold">'+data.name+'</p>' +
|
||||
'<p class="text-muted mb-0">'+data.value+'</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</a>';
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in a new issue