Morning Show Poll – Would you have the courage to embark on a special mission?

Your response has been recorded.

Sending…

jQuery(function( $ ) {
var url = “https://jovempan.com.br/wp-json/custom/v1/polls”;
if($(“.btn-vote-again”)) {
$(“.btn-vote-again”).on(“click”, function(){
document.location.reload();
})
}

function renderResult () {
var postId = document.querySelector(“.custom-polls”).getAttribute(“data-post-id”);

var data = { post_id: postId, };

if (document.querySelector(“.container-results”)) {
document.querySelector(“.container-results”).remove();
document.querySelector(“.start-label-results”).remove();
}

var startContainerResults=”

“+

‘;
var startRowInfo = ‘

‘; var endRowInfo = ‘

‘; var endBoxInfo = ‘

‘;

var startBoxPieChart=”

“;
var stopBoxPieChart=”

“;

var endContainerResults=”

“+

‘;

var labels = []; var dataChart = [];

var contentRows = “”;
var contentRowsBarChart = “”;

where myColor = [“#c92429”, “#216e94”, “#24c967”, “#2437c9”];

var contentLegend = “”;

$.ajax({
url: “https://jovempan.com.br/wp-json/custom/v1/polls/data-by-id”,
type: “POST”,
dataType: “json”,
data: data,
success: function(response) {
if (response.data) {

response.data.map((data, index) => {
var name = data.name
var votes = data.votes
var percent_string = data.percent_string
var percent_number = data.percent_number

dataChart.push(percent_number);
labels.push(“);//name

contentRows += startRowInfo;
contentRows += ‘Option: ‘+name+’‘;
contentRows += ‘Vote: ‘+votes+’‘;
contentRows += ‘Porcentagem: ‘+percent_string+’‘;
contentRows += endRowInfo;

contentLegend += ‘

‘+
‘+
‘+name+’‘+

‘;

var elementInsert=””+ ‘

‘+
‘+name+’‘+

‘+
‘+votes+’‘+
‘+percent_string+’‘+

‘+

‘+

‘;

contentRowsBarChart += elementInsert;
})

var boxPieChart=”” + ‘

‘+
”+

‘+contentLegend+’

‘+

‘;

var elementDataInfo = startContainerResults;
elementDataInfo += contentRows;
elementDataInfo += endBoxInfo;

elementDataInfo += boxPieChart;

elementDataInfo += startBoxPieChart;
elementDataInfo += contentRowsBarChart;
elementDataInfo += stopBoxPieChart;

elementDataInfo += endContainerResults;

//

var canvas = document.getElementById(“can”);
var ctx = canvas.getContext(“2d”);
var lastend = 0;
var myTotal = 0;

// canvas.legend.horizontalAlign = “right”

for(var e = 0; e < dataChart.length; e++) { myTotal += dataChart[e]; } // make the chart 10 px smaller to fit on canvas var off = 0 var w = (canvas.width - off) / 2 var h = (canvas.height - off) / 2 for (var i = 0; i < dataChart.length; i++) { ctx.fillStyle = myColor[i]; ctx.strokeStyle ="white"; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(w,h); var len = (dataChart[i]/myTotal) * 2 * Math.PI var r = h - off / 2 ctx.arc(w , h, r, lastend,lastend + len,false); ctx.lineTo(w,h); ctx.fill(); ctx.stroke(); ctx.fillStyle ="white"; ctx.font = "20px Arial"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; var mid = lastend + len / 2 ctx.fillText(labels[i],w + Math.cos(mid) * (r/2) , h + Math.sin(mid) * (r/2)); lastend += Math.PI*2*(dataChart[i]/myTotal); } } } }) } $(".item-poll").on("click", function() { if ($(".custom-polls").hasClass("block")) { return; } $(".custom-polls").addClass("block"); var postId = $(".custom-polls").attr("data-post-id"); var item = $(this).attr("data-item"); var numItems = $(".custom-polls").attr("data-number-items"); var data = { post_id: postId, meta_key: item, num_items: numItems, }; $.ajax({ url: url, type: "POST", dataType: "json", data: data, success: function(response) { $(".item-poll[data-item="+response.meta_key+"] .detail-poll .detail-text .votes").text(response.update_vote + " votos"); $(".item-poll[data-item="+response.meta_key+"]").attr("data-votes", response.update_vote) // var itens = $(".item-poll"); localStorage.setItem("poll_voted_"+postId, "true"); renderResult() // for (var index = 0; index < itens.length; index++) { // var element = itens[index]; // var votesItem = element.getAttribute("data-votes"); // var percent = ((votesItem*100)/response.total_votes).toFixed(2) +"%"; // var bg = element.querySelector(".background-porcentage"); // var elementePorcent = element.querySelector(".porcentage"); // if (bg) { // bg.style.height = percent; // } // if (elementePorcent) { // elementePorcent.textContent = percent; // elementePorcent.style.display = "block"; // } // } $(".container-loading").addClass("none") if($(".btn-vote-again")) { $(".btn-vote-again").removeClass("none"); } }, error: function(e) { console.log(e.statusText); } }) }) }); *The Jovem Pan Communication Group’s polls are not scientific in nature and only reflect the opinion of its audience.

source