1jQuery(document).ready(function ($) { 2 var $poll = $('#poll-voting'); 3 var $show = $poll.find('.view-results'); 4 var $results = $('#poll-results'); 5 6 // calculate and display poll results 7 function calc(poll) { 8 var poll = JSON.parse(poll); 9 var total = 0; 10 // calc 11 for (var i = 0; i < poll.length; i++) { 12 poll[i].votes = Number(poll[i].votes); 13 total = total + poll[i].votes; 14 } 15 // display 16 for (var i = 0; i < poll.length; i++) { 17 var z = i + 1; 18 var percent = Math.floor(poll[i].votes / total * 100); 19 $results.find('li:nth-child(' + z + ')').find('.option-bar-value').css({'width' : percent + '%'}); 20 } 21 } 22 23 // update the vote on click 24 $poll.on('submit', function (e) { 25 e.preventDefault(); 26 27 var post = $poll.attr('data-post'); 28 var vote = $poll.find(':checked').val(); 29 30 if (typeof vote !== 'undefined') { 31 32 // send the result to the server, update the vote count 33 $.ajax({ 34 type: 'POST', 35 url: window.ajaxUrl, 36 data: { 37 post: post, 38 vote: vote, 39 nonce: poll_vote.nonce, 40 action: 'poll_voting' 41 } 42 }).done(function (res) { 43 calc(res); 44 $poll.parent().addClass('show-results'); 45 }); 46 47 } 48 }); 49 50 // show results 51 $show.on('click', function (e) { 52 e.preventDefault(); 53 54 // ask the server for the vote totals 55 $.ajax({
56 type: 'POST', 57 url: window.ajaxUrl, 58 data: { 59 post: $poll.attr('data-poll'), 60 nonce: poll_vote.nonce, 61 action: 'poll_calc' 62 } 63 }).done(function (res) { 64 calc(res); 65 $poll.parent().addClass('show-results'); 66 }); 67 }); 68});
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.