function deleteCookie(name) { document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT'; } function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;Domain=maddiesfund.org"; } function setCookie2(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } //var pollQuestion = '

Poll Question

Do you wrap gifts for your pet(s)?

' var pollQuestion = '
Do you wrap gifts for your pet(s)?

' var pollLink = '

' var pollForm = '


'; $(document).ready(function(){ $("#pollQuestion").append(pollQuestion); //buildBarChart(); deleteCookie('poll'); deleteCookie('hidePollModal'); let pollTaken = getCookie("poll"); let hidePollModal = getCookie("hidePollModal"); console.log('pollID: 169'); console.log('pollTaken:'+pollTaken); console.log('hidePollModal:'+hidePollModal); if (pollTaken == 169 || hidePollModal == 169) { buildBarChart(); } else { $("#pollQuestion").append(pollForm); $("#pollResults").hide(); $("#pollResultsRespondents").hide(); $('#myModal').modal('show'); //setCookie('poll',169,1); setCookie('hidePollModal',169,30); } }); function buildBarChart() { var options = { series: [], chart: { height: 250, type: 'bar', toolbar: {show: false}, fontFamily: 'Lato, sans-serif' }, dataLabels: {enabled: false}, noData: {text: 'Loading...'}, colors: ['#7FCACF', '#B3B8B8', '#DD7E6F','#E4B87E', '#8582BE'], plotOptions: { bar: { barHeight: '100%', distributed: true, horizontal: true, dataLabels: {position: 'bottom'}, } }, dataLabels: { enabled: true, textAnchor: 'start', formatter: function (val, opt) { let series = opt.w.config.series let idx = opt.dataPointIndex let count = series[0].data[idx].z; return ' ' + val + '%'; }, offsetX: 0, dropShadow: {enabled: false}, style: { fontSize: '14px', fontFamily: 'Lato, sans-serif' , fontWeight: 'normal', colors: '#222222' }, }, stroke: { width: 2, colors: ['#fff'] }, yaxis: { labels:{show:true}, axisBorder:{show:true}, tooltip:{enabled:true}, labels: { show: true, minWidth: 0, maxWidth: 160, style: { fontSize: '14px', fontFamily: 'Lato, sans-serif' , fontWeight: 'normal', colors: '#222222' } } }, xaxis: { labels:{show:true}, axisBorder:{show:true}, tooltip:{enabled:true} }, legend: { show: false}, tooltip: { enabled: false }, grid: { show:false, padding: { top: -10, right: 0, bottom: 0, left: 0 } }, tooltip: { custom: function({ series, seriesIndex, dataPointIndex, w }) { return ( '
' + "" + w.globals.labels[dataPointIndex] + "
" + series[seriesIndex][dataPointIndex] + "%
" + "
" ); } } }; var chart = new ApexCharts(document.querySelector("#pollResults"), options); chart.render(); $.getJSON('/poll/poll-results?pollID=169', function(response) { chart.updateSeries([{ name: 'Responders', data: response }]) $('#respondents').html('Responses: '+response[0].respondents); console.log('get poll results: '+ response[0].respondents); }); }; function sendData(form){ $('form#pollForm').on('submit', function (e) { e.preventDefault(); setCookie('poll',169,30); var formData = { pollID: 169, answer: $(".form-check-input:checked").val() }; var pollID = $("#pollID").val(); var answer = $(".form-check-input:checked").val(); $.ajax({ type: 'post', url: '/tally-poll?pollID='+pollID+'&answer='+answer, data: formData, success: function () { $("#pollForm").hide(); $("#pollResults").show(); $("#pollResultsRespondents").show(); console.log('/poll/poll-results?pollID='+pollID+'&answer='+answer); buildBarChart(); }, error : function(result){ $("#pollForm").hide(); form.parent().replaceWith(pollAnswerBad); // should replace the form's parent div with the result } }); }); };