search.js 3.3 KB

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