| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- $(function(){
- function isMatch(candidate, text) {
- if (candidate.name.toLowerCase().includes(text))
- return true;
-
- if (candidate.username.toLowerCase().includes(text))
- return true;
-
- if (("" + candidate.skymanager_id).includes(text))
- return true;
-
- if (candidate.voting_id && ("" + candidate.voting_id).includes(text))
- return true;
-
- return false;
- }
-
- function createChild(candidate) {
- var li = document.createElement('li');
- li.className = 'candidate';
-
- var profileimgsect = document.createElement('div');
- profileimgsect.className = 'profile-icon';
-
- var profileimg = document.createElement('img');
- profileimg.src = 'https://www.gravatar.com/avatar/' + candidate.gravatar_hash + '.png?d=mp&s=64';
- profileimgsect.appendChild(profileimg);
-
- var profiletext = document.createElement('div');
- profiletext.className = 'profile';
-
- var profilename = document.createElement('h2');
- profilename.className = 'profile-name';
- profilename.textContent = candidate.name;
-
- var profileid = document.createElement('h4');
- profileid.className = 'profile-id';
- profileid.textContent = candidate.voting_id;
- if (!candidate.voting_id || candidate.delegate) {
- profiletext.className += ' ineligible';
- profileid.textContent += " (Ineligible)";
- }
-
- profiletext.appendChild(profilename);
- profiletext.appendChild(profileid);
-
- if (candidate.proxies) {
- var proxies = document.createElement('div');
- proxies.className = 'proxies';
- proxies.textContent = 'Proxy Votes: ' + candidate.proxies.replace(',', ', ');
- profiletext.appendChild(proxies);
- }
-
-
- li.appendChild(profileimgsect);
- li.appendChild(profiletext);
-
- li.addEventListener('click', function() {
- var csc = document.getElementById("selectedVoter");
- while (csc.firstChild) {
- csc.removeChild(csc.firstChild);
- }
-
- csc.appendChild(profileimgsect);
- csc.appendChild(profiletext);
- document.getElementById('voter-input').value = candidate.voting_id;
- document.getElementById('voter-searchbox').value = "";
- search('');
- });
-
-
- return li;
- }
-
- function search(text) {
- var list = document.createElement('ul');
-
- var matches = 0;
- for (var i = 0; text.length > 0 && i < voters.length; i++) {
- if (isMatch(voters[i], text.toLowerCase())) {
- list.appendChild(createChild(voters[i]));
- if (++matches > 4)
- break;
- }
- }
-
- var container = document.getElementById('voter-results');
- while (container.firstChild) {
- container.removeChild(container.firstChild);
- }
-
- if (matches)
- container.appendChild(list);
- }
-
- $('#voter-searchbox').bind('textInput input', function() { search(this.value); });
- });
|