1var lastPollUpdated = null; 2 3function pollAll(selector) { 4 return Array.prototype.slice.call(document.querySelectorAll(selector)); 5} 6 7function pollScope(formID) { 8 return 'form[data-id="' + formID + '"] '; 9} 10 11function pollCheck(formID, id) { 12 var option = document.querySelector('.poll-area-' + formID + ' .' + id); 13 14 if (option && option.classList.contains('selected')) { 15 pollAll(pollScope(formID) + '.' + id).forEach(function (el) { el.classList.remove('selected'); }); 16 pollAll(pollScope(formID) + '.' + id + ' .circle').forEach(function (el) { el.classList.remove('selected'); }); 17 pollAll(pollScope(formID) + '.poll-captcha').forEach(function (el) { el.classList.add('d-none'); }); 18 pollAll(pollScope(formID) + '.voteBtn').forEach(function (el) { el.disabled = true; }); 19 20 if (lastPollUpdated != formID && GRECAPTCHA_CONTAINERS[formID]) { 21 lastPollUpdated = formID; 22 if (typeof grecaptcha !== 'undefined') { grecaptcha.reset(GRECAPTCHA_CONTAINERS[formID]); } 23 } 24 25 return; 26 } 27 28 var form = document.querySelector('.module-12 form[data-id="' + formID + '"]'); 29 30 if (form && form.getAttribute('data-multiple') === 'false') { 31 clearPoll(formID); 32 } 33 34 pollAll(pollScope(formID) + '.' + id).forEach(function (el) { el.classList.add('selected'); }); 35 pollAll(pollScope(formID) + '.' + id + ' .circle').forEach(function (el) { el.classList.add('selected'); }); 36 pollAll(pollScope(formID) + '.poll-captcha').forEach(function (el) { el.classList.remove('d-none'); }); 37 pollAll(pollScope(formID) + '.voteBtn').forEach(function (el) { el.disabled = false; }); 38} 39 40// Scoped to one poll: without formID it would clear every poll on the page 41function clearPoll(formID) { 42 var scope = (formID ? pollScope(formID) : ''); 43 44 pollAll(scope + '.poll-area label').forEach(function (el) { el.classList.remove('selected'); }); 45 pollAll(scope + '.poll-area label .circle').forEach(function (el) { el.classList.remove('selected'); }); 46} 47 48function pollGet(url, done) { 49 fetch(url, { credentials: 'same-origin' }) 50 .then(function (response) { return response.ok ? response.text() : ''; }) 51 .then(done) 52 .catch(function () {}); 53} 54 55function parcialPoll(id, back = null, voted = null, multiple = null) { 56 if (!back) { 57 clearPoll(id); 58 pollAll('.poll-area-' + id + ' .poll-captcha').forEach(function (el) { el.classList.add('d-none'); }); 59 60 pollGet('/parcial-poll/' + id + '/' + voted, function (data) { 61 pollAll('.poll-area-' + id).forEach(function (area) { 62 area.classList.add('d-none'); 63 area.insertAdjacentHTML('afterend', '<div class="parcial-' + id + ' bg-block rounded p-2 mb-3">' + data + '</div>'); 64 }); 65 66 if (!voted) { 67 pollAll('.pollSend-' + id).forEach(function (el) { 68 el.classList.add('pollSend--wide'); 69 el.innerHTML = '<button type="button" class="btn btn--primary bg-block color2" onclick="parcialPoll(\'' + id + '\',true);">Voltar</button>'; 70 }); 71 } else if (voted && multiple) { 72 pollAll('.pollSend-' + id).forEach(function (el) { 73 el.classList.add('pollSend--wide'); 74 el.innerHTML = '<button type="button" class="btn btn--primary bg-block color2" onclick="parcialPoll(\'' + id + '\',true);">Votar novamente</button>'; 75 }); 76 } else { 77 pollAll('.pollSend-' + id).forEach(function (el) { el.remove(); }); 78 pollAll('.parcialSee-' + id).forEach(function (el) { el.remove(); }); 79 } 80 81 pollAll('.parcialSee-' + id).forEach(function (el) { el.classList.add('d-none'); }); 82 }); 83 84 return; 85 } 86 87 pollAll('.msgSuc').forEach(function (el) { el.remove(); }); 88 pollAll('.parcial-' + id).forEach(function (el) { el.remove(); }); 89 pollAll('.poll-area-' + id).forEach(function (el) { el.classList.remove('d-none'); }); 90 91 pollAll('.pollSend-' + id).forEach(function (el) { 92 el.classList.remove('pollSend--wide'); 93 el.innerHTML = '<button type="submit" class="btn btn--primary bg-block color2 voteBtn" disabled="disabled">Votar</button>'; 94 }); 95 96 pollAll('.parcialSee-' + id).forEach(function (el) { el.classList.remove('d-none'); }); 97} 98 99function getPartial(id) { 100 pollGet('/parcial-poll/' + id + '/null', function (data) {
101 pollAll('.partial-' + id).forEach(function (el) { 102 el.innerHTML = '<div class="parcial-' + id + ' bg-block rounded p-2 mb-3">' + data + '</div>'; 103 }); 104 }); 105} 106 107document.addEventListener('click', function (e) { 108 var input = e.target.closest('.module-12 input[type=checkbox]'); 109 if (!input) return; 110 111 var area = input.closest('.poll-area'); 112 if (!area) return; 113 114 pollCheck(area.getAttribute('data-poll'), input.id); 115});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.