'; if (selectedOption) { var widthPercentage = optionPercentages[index] < 5 && optionPercentages[index] != 0 ? 5 : optionPercentages[index]; if (selectedOption === option) { if (widthPercentage > 97) { pollOptionsDom += ''; } else { pollOptionsDom += ''; } } else { if (widthPercentage > 97) { pollOptionsDom += ''; } else { pollOptionsDom += ''; } } } pollOptionsDom += '
'; }); pollOptions.innerHTML = pollOptionsDom; pollCount.innerHTML = totalVotes + ' votes'; if (totalVotes > 10) { pollCount.classList.remove("hidden"); } } trackArticlePollImpression(pollData); } function answerPoll(e, selectedOption) { e.preventDefault(); updatePollCountOnAnswer(selectedOption); var isDesktop = "1"; var gaPayload = { "question" : pollDataDefault.question, "answer" : e.target.textContent, "answer_option" : selectedOption.replace("option", "Option "), "category": "Esports & Gaming", "page_location": window.location.href, } if (pollTaglinePosition && pollTaglinePosition != "") { gaPayload["poll_position"] = pollTaglinePosition; } if (isDesktop) { gaPayload["device"] = "Desktop"; } else { gaPayload["device"] = "Mobile"; } gtag("event", "ARTICLE_POLL_RESPONSE", gaPayload); var url = ' var data = { "poll_type": "article", "option": selectedOption } pureJSAjaxPost(url, data, onPollResponseSuccess.bind(this, selectedOption), onPollResponseFail.bind(this, selectedOption), null, false); } function trackSponsoredLinkClick(e) { var pollTheme = "default"; gtag('event', 'click', { 'event_category': 'PollSponsoredLink', 'event_label': pollTheme }); } 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 < 0.5) return; setTimeout(function() { if (isInViewport(entry.target)) { articlePollImpressionTracked = true; var isDesktop = "1"; var gaPayload = { "question" : pollData.question, "category": "Esports & Gaming", "page_url": window.location.href, } if (isDesktop) { gaPayload["device"] = "Desktop"; } else { gaPayload["device"] = "Mobile"; } if (pollTaglinePosition && pollTaglinePosition != "") { gaPayload["poll_position"] = pollTaglinePosition; } gtag("event", "ARTICLE_POLL_IMPRESSION", gaPayload); intersectionObserverForArticlePoll.unobserve(entry.target); } }, 1000); }); }, { threshold: 0.5 } ); if (pollElement){ var isAnswered = pollElement.querySelector(".poll-option-answered"); if (!isAnswered) { intersectionObserverForArticlePoll.observe(pollElement); } } } ' + pollData[option] + '
'; if (selectedOption) { pollOptionsDom += '' + Math.round(optionPercentages[index]) + '%
'; } pollOptionsDom += ' " 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": 1355464, "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 < activeStars.length; i++) { activeStars[i].classList.remove("active"); } if ($('input[name="drone"]:checked')) { $('input[name="drone"]:checked').checked = false; } var userNote = document.querySelector(".post-rating-feedback-note textarea"); userNote.value = ''; modalPopup.close(); } function onsaveRatingSuccess() { modalPopup.close(); savePostIdInUserRatedPostsCookie(); $("#post-rating-layout").classList.add("hidden"); $("#post-rating-message").classList.remove("hidden"); window.setInterval(function showMessage() { $("#post-rating-widget").classList.add("hidden"); }, 3000); } function onsaveRatingFail() { console.error('Saving post rating failed!'); modalPopup.close(); } function savePostIdInUserRatedPostsCookie() { userRatedPostIds.push(1355464); var expiryTime = new Date(); expiryTime.setMonth(expiryTime.getMonth() + 12); // Expiry after 1 year setCookie("user_rated_post_ids", JSON.stringify(userRatedPostIds), expiryTime); } function isPostRatedByUser() { var userRatedPostIds = getCookie('user_rated_post_ids'); if (userRatedPostIds) { try { userRatedPostIds = JSON.parse(userRatedPostIds); } catch (err) { console.error(err); return false; } } else { return false; } if(userRatedPostIds.indexOf(1355464) >= 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); } (function() { var callFired = false; function lazyLoadPostRating() { if (callFired) return; callFired = true; if (!isPostRatedByUser()) { getRatingCountByPostId(1355464) .then(function(ratingCount) { if (ratingCount < 10) { $("#post-rating-widget").classList.remove("hidden"); } }) .catch(function(err){ console.error(err); }); } } document.addEventListener("scroll", lazyLoadPostRating, { passive: true, once: true }); document.addEventListener("mousemove", lazyLoadPostRating, { passive: true, once: true }); document.addEventListener("touchmove", lazyLoadPostRating, { passive: true, once: true }); })();