Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var client = algoliasearch("<%= ENV['ALGOLIA_API'] %>", "<%= ENV['ALGOLIA_SECRET'] %>");
- var index = client.initIndex('User');
- //initialize autocomplete on search input (ID selector must match)
- autocomplete('#aa-search-input',
- { hint: false }, [{
- source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
- //value to be displayed in input control after user's suggestion selection
- displayKey: function(suggestion) { return suggestion.first_name + " " + suggestion.last_name},
- //hash of templates used when rendering dataset
- templates: {
- //'suggestion' templating function used to render a single suggestion
- suggestion: function(suggestion) {
- var link = "<form action='<%= ENV['HOST'] %>users/" + suggestion.id + "/friend_requests' method='post' id='addfriend' style='color: lightgreen'> <input name='authenticity_token' value='<%= form_authenticity_token %>' type='hidden'> <button type='submit' name='user_id' value='" + suggestion.id + "' class='btn-link'>Add</button></form>";
- var card = "<span>" + "<img src=http://res.cloudinary.com/dkyjujcrz/image/upload/w_400,h_400/" + suggestion.photo.path + " alt='' class='avatar'> " +
- suggestion._highlightResult.first_name.value + " " + suggestion._highlightResult.last_name.value + "</span><span>" + link +"</span>";
- return card
- }
- }
- }]).on('autocomplete:selected', function(event, suggestion, dataset) {
- var url = "<%= ENV['HOST'] %>users/";
- window.location.assign(url + suggestion.id)});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement