diff --git a/resources/assets/js/components/searchform.js b/resources/assets/js/components/searchform.js new file mode 100644 index 000000000..e23843edf --- /dev/null +++ b/resources/assets/js/components/searchform.js @@ -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: [ + '
', + 'unable to find any matches', + '
' + ].join('\n'), + suggestion: function(data) { + let type = data.type; + let res = null; + switch(type) { + case 'hashtag': + res = '' + + '
' + + '
#
' + + '
' + + '

'+data.value+'

' + + '

'+data.count+' posts

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

'+data.name+'

' + + '

'+data.value+'

' + + '
' + + '
' + + '
'; + break; + } + return res; + } + } + }); + +}); \ No newline at end of file