$(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: 40, templates: { empty: [ '
', 'No Results Found', '
' ].join('\n'), suggestion: function(data) { let type = data.type; let res = false; switch(type) { case 'hashtag': res = '' + '
' + '
' + '
' + '

'+data.value+'

' + '

'+data.count+' posts

' + '
' + '
' + '
'; break; case 'profile': res = '' + '
' + '
' + '
' + '

'+data.name+'

' + '

'+data.value+'

' + '
' + '
' + '
'; break; case 'status': res = '' + '
' + '
' + '
' + '

'+data.name+'

' + '

'+data.value+'

' + '
' + '
' + '
'; break; default: res = false; break; } if(res !== false) { return res; } } } }); });