Friday, March 5
Shadow

Coronavirus: Hot or Cold, weather doesn’t play significant role in COVID-19 spread – Asianet News English

Today’s Poll

Please select an option to vote

Which team has a better chance of ending their 13-year IPL title drought this season?

${pollQuestion}

Thank you for voting, your vote has been recorded

`
options.forEach(result=>{
html+=`

${result.name}

${(result.value*100/totalVotes).toFixed(2)}%

`
})
html+=`

`;
$(`#poll-options-${urlPath.split(‘/’).join(‘-‘)}`).css(“display”, “none”)
$(`#poll-result-${urlPath.split(‘/’).join(‘-‘)}`).empty()
$(`#poll-result-${urlPath.split(‘/’).join(‘-‘)}`).append(html)
$(`#poll-result-${urlPath.split(‘/’).join(‘-‘)}`).css(“display”, “block”)
}
setCookie = (url) => {
let cookies = JSON.parse($.cookie(“user-info-poll”) == null?”[]”:$.cookie(“user-info-poll”))
if(!cookies.includes(“poll-“+url)) cookies.push(“poll-“+url)
$.cookie(“user-info-poll”, JSON.stringify(cookies), {path:”/”})
}
submitAnswer = (event, question, urlPath, id, filterdPollOptions) => {
var pollanswer = document.querySelector(‘input[name=”option-‘+urlPath.split(‘/’).join(“-“)+'”]:checked’)
if(pollanswer == null) {
$(“#errormsg-“+urlPath.split(‘/’).join(‘-‘)).css(“display”, “block”)
} else {
event.target.disabled = true;
event.target.classList.add(‘button-disabled’);
$(“#errormsg-“+urlPath.split(‘/’).join(‘-‘)).css(“display”, “none”)
$.ajax({
             url: “/pollSubmit?”+”pollId=”+encodeURIComponent(id)+”&answer=”+encodeURIComponent(pollanswer.value)+”&time=”+encodeURIComponent(new Date().getTime()),
             type: “get”,
             success: function(result) {
setCookie(urlPath.split(‘/’).join(“-“))
pollData = JSON.parse(filterdPollOptions)
pollData.forEach(v=>{if(v.name == pollanswer.value) v.value+=1})
constructPollResultData(urlPath, question, pollData)
             },
                error: function (err) {
                 console.log(“Poll could not be submitted: ” + JSON.stringify(err, null, 2));
                }
         });
return ga(‘send’, ‘event’, ‘Poll’, id, $(window)[0].location.href);
}
}

displayPoll = (pollId, pollClass, urlPath) => {
let cookies = JSON.parse($.cookie(“user-info-poll”) == null?”[]”:$.cookie(“user-info-poll”))
// check for cookies
if(cookies.includes(`poll-${urlPath.split(“/”).join(“-“)}`)) {
// send ajax request to get poll
$.ajax({
             url: “/getPoll?”+”pollId=”+encodeURIComponent(pollId)+”&time=”+encodeURIComponent(new Date().getTime()),
             type: “get”,
             success: function(result) {
let filterdPollOptions = []
result.data.answers.forEach((answer)=>{
if(result.data.results && JSON.parse(result.data.results).find(result=>result.name==answer)) filterdPollOptions.push(JSON.parse(result.data.results).find(res=>res.name==answer))
else filterdPollOptions.push({name:answer, value:0})
})
constructPollResultData(urlPath, result.data.question, filterdPollOptions)
             },
                error: function (err) {
                 console.log(“could not get the poll: ” + JSON.stringify(err, null, 2));
                }
         });

} else {
// enable the question
$(`#poll-options-${urlPath.split(‘/’).join(‘-‘)}`).css(“display”, “block”)
$(`#poll-result-${urlPath.split(‘/’).join(‘-‘)}`).css(“display”, “none”)
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *