Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. var client = algoliasearch("<%= ENV['ALGOLIA_API'] %>", "<%= ENV['ALGOLIA_SECRET'] %>");
  2. var index = client.initIndex('User');
  3.  
  4. //initialize autocomplete on search input (ID selector must match)
  5. autocomplete('#aa-search-input',
  6. { hint: false }, [{
  7. source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
  8. //value to be displayed in input control after user's suggestion selection
  9. displayKey: function(suggestion) { return suggestion.first_name + " " + suggestion.last_name},
  10. //hash of templates used when rendering dataset
  11. templates: {
  12. //'suggestion' templating function used to render a single suggestion
  13. suggestion: function(suggestion) {
  14. 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>";
  15. var card = "<span>" + "<img src=http://res.cloudinary.com/dkyjujcrz/image/upload/w_400,h_400/" + suggestion.photo.path + " alt='' class='avatar'> " +
  16. suggestion._highlightResult.first_name.value + " " + suggestion._highlightResult.last_name.value + "</span><span>" + link +"</span>";
  17.  
  18. return card
  19.  
  20. }
  21. }
  22. }]).on('autocomplete:selected', function(event, suggestion, dataset) {
  23. var url = "<%= ENV['HOST'] %>users/";
  24. window.location.assign(url + suggestion.id)});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement