‘;
});
pollOptions.innerHTML = pollOptionsDom;
pollCount.innerHTML = totalVotes + ‘ votes’;
}
function updatePollCountOnAnswer(selectedOption) {
var pollData = null;
renderPollWidget(pollData, selectedOption, true);
}
function renderPollWidget(pollData, selectedOption, isAnswered) {
if (!pollData) return;
pollData.option1_count = pollData.option1_count || 0;
pollData.option2_count = pollData.option2_count || 0;
if (isAnswered) {
if (selectedOption == “option1”) pollData.option1_count += 1;
if (selectedOption == “option2”) pollData.option2_count += 1;
}
var totalVotes = Number(pollData.option1_count + pollData.option2_count);
if (totalVotes && !Number.isNaN(totalVotes)) {
var option1Percent = pollData.option1_count / totalVotes * 100;
var option2Percent = pollData.option2_count / totalVotes * 100;
var optionPercentages = [option1Percent, option2Percent];
var pollOptions = $(“#poll-options”);
var pollCount = $(“#poll-count”);
var pollOptionsDom = ”;
[‘option1’, ‘option2’].forEach(function (option, index) {
var clickHandler = ‘onclick=”answerPoll(event, ” + option + ”)”‘;
var optionClass = [‘poll-option’];
if (selectedOption) {
optionClass.push(‘poll-option-answered’);
clickHandler = ”;
}
if (selectedOption === option) {
optionClass.push(‘poll-option-selected’);
}
pollOptionsDom += ‘
if (selectedOption) {
var widthPercentage = optionPercentages[index] 97) {
pollOptionsDom += ‘‘;
} else {
pollOptionsDom += ‘‘;
}
} else {
if (widthPercentage > 97) {
pollOptionsDom += ‘‘;
} else {
pollOptionsDom += ‘‘;
}
}
}
pollOptionsDom += ‘
‘ + pollData[option] + ‘
‘;
if (selectedOption) {
pollOptionsDom += ‘
‘ + Math.round(optionPercentages[index]) + ‘%
‘;
}
pollOptionsDom += ‘
‘;
});
pollOptions.innerHTML = pollOptionsDom;
pollCount.innerHTML = totalVotes + ‘ votes’;
if (totalVotes > 10) {
pollCount.classList.remove(“hidden”);
}
trackArticlePollImpression(pollData);
}
}
function answerPoll(e, selectedOption) {
e.preventDefault();
try{
permutive.track(‘PollResponse’,{
“pagetype”: “Articlepage”,
“category”: “MMA”,
“answer”: {
“text”: e.target.textContent
},
“question”: {
“text”: pollDataDefault.question
}
});
} catch (err) {
console.log(err);
}
updatePollCountOnAnswer(selectedOption);
var isDesktop = “1”;
var gaPayload = {
“question” : pollDataDefault.question,
“answer” : e.target.textContent,
“answer_option” : selectedOption.replace(“option”, “Option “),
“category”: “MMA”,
“page_location”: window.location.href,
}
if (isDesktop) {
gaPayload[“device”] = “Desktop”;
} else {
gaPayload[“device”] = “Mobile”;
}
gtag(“event”, “ARTICLE_POLL_RESPONSE”, gaPayload);
var url = ‘https://a-gotham.sportskeeda.com/polls//response’;
var data = {
“poll_type”: “article”,
“option”: selectedOption
}
pureJSAjaxPost(url, data, onPollResponseSuccess.bind(this, selectedOption), onPollResponseFail.bind(this, selectedOption), null, false);
}
function trackSponsoredLinkClick(e) {
}
var articlePollImpressionTracked = false;
function trackArticlePollImpression(pollData) {
var pollElement = $(“#poll”);
var intersectionObserverForArticlePoll = new IntersectionObserver(
function(entries) {
entries.forEach(function(entry) {
if (articlePollImpressionTracked) return;
if (!entry.target || !entry.isIntersecting || entry.intersectionRatio
modalPopup.closeOnEsc = false;
modalPopup.setHeader(“Why did you not like this content?”);
modalPopup.setContentText(modalText);
modalPopup.addCancelOkButton(“Submit”, resetRatingAndFeedbackForm, sendRating);
modalPopup.removeCloseModalIcon();
modalPopup.disableDismissPopup();
modalPopup.open();
} else {
sendRating(index);
}
}
function sendRating() {
var requestPayload = {
“post_id”: 1246003,
“rating_value”: ratingValue
}
if (ratingValue > 3) {
requestPayload.rating_feedback_type = null;
requestPayload.rating_feedback = null;
} else {
if (!$(‘input[name=”drone”]:checked’) || !$(‘input[name=”drone”]:checked’).value) {
showErrorMessage(‘option’);
return;
}
if (!$(“.post-rating-feedback-note textarea”) || !$(“.post-rating-feedback-note textarea”).value) {
showErrorMessage(‘note’);
return;
}
var selectedOption = $(‘input[name=”drone”]:checked’).value;
var feedbackNote = $(“.post-rating-feedback-note textarea”).value;
requestPayload.rating_feedback_type = selectedOption;
requestPayload.rating_feedback = feedbackNote;
}
pureJSAjaxPost(addratingAPI, requestPayload, onsaveRatingSuccess, onsaveRatingFail, function() {}, true);
}
function resetRatingAndFeedbackForm() {
var activeStars = Array.from($all(‘.rating span.rating-star.active’));
for (var i=0; i = 0) {
return true;
} else {
return false;
}
}
function getRatingCountByPostId(postId) {
return new Promise(function(resolve, reject) {
pureJSAjaxGet(
getRatingCountBaseURL + postId + ‘/rating/count’,
function(data) {
try {
data = JSON.parse(data);
if (data.meta_value) {
resolve(data.meta_value);
}
reject(“Failed to fetch rating count for the post:” + postId);
} catch (err) {
reject(“Failed to fetch rating count for the post:” + postId);
}
},
function(err) {
reject(“Failed to fetch rating count for the post:” + postId);
}, true);
});
}
function showErrorMessage(messageType) {
var messageContainerId = ‘#’ + messageType + ‘-error’;
$(messageContainerId).classList.remove(‘hidden’);
window.setInterval(function () {
$(messageContainerId).classList.add(“hidden”);
}, 5000);
}
if (!isPostRatedByUser()) {
getRatingCountByPostId(1246003)
.then(function(ratingCount) {
if (ratingCount