Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

admin-search.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. $(function(){
  2. function isMatch(candidate, text) {
  3. if (candidate.name.toLowerCase().includes(text))
  4. return true;
  5. if (candidate.username.toLowerCase().includes(text))
  6. return true;
  7. if (("" + candidate.skymanager_id).includes(text))
  8. return true;
  9. if (candidate.voting_id && ("" + candidate.voting_id).includes(text))
  10. return true;
  11. return false;
  12. }
  13. function createChild(candidate) {
  14. var li = document.createElement('li');
  15. li.className = 'candidate';
  16. var profileimgsect = document.createElement('div');
  17. profileimgsect.className = 'profile-icon';
  18. var profileimg = document.createElement('img');
  19. profileimg.src = 'https://www.gravatar.com/avatar/' + candidate.gravatar_hash + '.png?d=mp&s=64';
  20. profileimgsect.appendChild(profileimg);
  21. var profiletext = document.createElement('div');
  22. profiletext.className = 'profile';
  23. var profilename = document.createElement('h2');
  24. profilename.className = 'profile-name';
  25. profilename.textContent = candidate.name;
  26. var profileid = document.createElement('h4');
  27. profileid.className = 'profile-id';
  28. profileid.textContent = candidate.voting_id;
  29. if (!candidate.voting_id || candidate.delegate) {
  30. profiletext.className += ' ineligible';
  31. profileid.textContent += " (Ineligible)";
  32. }
  33. profiletext.appendChild(profilename);
  34. profiletext.appendChild(profileid);
  35. if (candidate.proxies) {
  36. var proxies = document.createElement('div');
  37. proxies.className = 'proxies';
  38. proxies.textContent = 'Proxy Votes: ' + candidate.proxies.replace(',', ', ');
  39. profiletext.appendChild(proxies);
  40. }
  41. li.appendChild(profileimgsect);
  42. li.appendChild(profiletext);
  43. li.addEventListener('click', function() {
  44. var csc = document.getElementById("selectedVoter");
  45. while (csc.firstChild) {
  46. csc.removeChild(csc.firstChild);
  47. }
  48. csc.appendChild(profileimgsect);
  49. csc.appendChild(profiletext);
  50. document.getElementById('voter-input').value = candidate.voting_id;
  51. document.getElementById('voter-searchbox').value = "";
  52. search('');
  53. });
  54. return li;
  55. }
  56. function search(text) {
  57. var list = document.createElement('ul');
  58. var matches = 0;
  59. for (var i = 0; text.length > 0 && i < voters.length; i++) {
  60. if (isMatch(voters[i], text.toLowerCase())) {
  61. list.appendChild(createChild(voters[i]));
  62. if (++matches > 4)
  63. break;
  64. }
  65. }
  66. var container = document.getElementById('voter-results');
  67. while (container.firstChild) {
  68. container.removeChild(container.firstChild);
  69. }
  70. if (matches)
  71. container.appendChild(list);
  72. }
  73. $('#voter-searchbox').bind('textInput input', function() { search(this.value); });
  74. });