search.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. function searchlocalfill() {
  2. if(current_search_history.length > 0) {
  3. var dropdown = $("<ul>").addClass("account_list");
  4. var searchsuggestions = new Array();
  5. current_search_history.reverse();
  6. for(var i=0;i<current_search_history.length;i++) {
  7. if(searchsuggestions.length == 10) break;
  8. if(searchsuggestions.indexOf(current_search_history[i]) == -1) {
  9. dropdown.append($("<li>").data("value",current_search_history[i]).addClass("account_box").append($("<div>").addClass("icon_box").append($("<span>").addClass("emoji_poss").html("#️⃣").css("float","left").css("font-size","32px")))
  10. .append($("<div>").addClass("label_box").append($("<span>").addClass("dn").append($("<h3>").html("#"+current_search_history[i])))).click(function() {
  11. window.location.href = "/search?q="+encodeURIComponent($(this).data("value"));
  12. }));
  13. searchsuggestions.push(current_search_history[i]);
  14. }
  15. }
  16. current_search_history.reverse();
  17. $(".header_search_suggestions").empty().removeClass("invisible").append(dropdown);
  18. replace_emoji();
  19. }
  20. }
  21. function searchremotefill(text) {
  22. if(text == "@") searchlocalfill();
  23. else {
  24. api.search("q="+encodeURIComponent(text)+"&resolve=false&limit=5",function(data) {
  25. if(data.hashtags.length == 0 && data.accounts.length == 0) $(".header_search_suggestions").addClass("invisible");
  26. else {
  27. var dropdown = $("<ul>").addClass("account_list");
  28. for(var i=0;i<data.hashtags.length;i++) {
  29. if(i == 5) break;
  30. dropdown.append($("<li>").data("value",data.hashtags[i].name).addClass("account_box").append($("<div>").addClass("icon_box").append($("<span>").addClass("emoji_poss").html("#️⃣").css("float","left").css("font-size","32px")))
  31. .append($("<div>").addClass("label_box").append($("<span>").addClass("dn").append($("<h3>").html("#"+data.hashtags[i].name)))).click(function() {
  32. window.location.href = "/search?q="+encodeURIComponent($(this).data("value"));
  33. }));
  34. }
  35. for(var i=0;i<data.accounts.length;i++) {
  36. if(i == 5) break;
  37. if(data.accounts[i].display_name == "") data.accounts[i].display_name = data.accounts[i].username;
  38. for(var a=0;a<data.accounts[i].emojis.length;a++) {
  39. data.accounts[i].display_name = data.accounts[i].display_name.replace(new RegExp(":"+data.accounts[i].emojis[a].shortcode+":","g"),"<img src='"+data.accounts[i].emojis[a].url+"' class='emoji'>");
  40. }
  41. var account_link;
  42. if(data.accounts[i].acct.indexOf("@") == -1) account_link = "/@"+data.accounts[i].acct+"@"+current_instance+"?mid="+data.accounts[i].id;
  43. else account_link = "/@"+data.accounts[i].acct+"?mid="+data.accounts[i].id;
  44. dropdown.append($("<li>").data("value",account_link).addClass("account_box").append($("<div>").addClass("icon_box").append($("<img>").attr("src",data.accounts[i].avatar).css("float","left")))
  45. .append($("<div>").addClass("label_box").css("width","unset").append($("<span>").addClass("dn").append($("<h3>").html(data.accounts[i].display_name).addClass("emoji_poss"))).append($("<span>").addClass("un").html(data.accounts[i].acct))).click(function() {
  46. window.location.href = $(this).data("value");
  47. }));
  48. }
  49. $(".header_search_suggestions").empty().removeClass("invisible").append(dropdown);
  50. replace_emoji();
  51. }
  52. });
  53. }
  54. }
  55. function searchredirect(text) {
  56. if(text[0] == "@") window.location.href = "/search/users?q="+encodeURIComponent(text.substr(1));
  57. else if(text[0] == "#") window.location.href = "/search?q="+encodeURIComponent(text.substr(1));
  58. else if(text.substr(0,8) == "https://") openStatus(text);
  59. else window.location.href = "/search?q="+encodeURIComponent(text);
  60. }