var s = document.createElement('link'); s.type = 'text/css'; s.rel = 'stylesheet'; s.href= '/base/vote/style.css'; document.querySelector('head').appendChild(s); var s = document.createElement('div'); s.id = 'exp_vote_pop'; document.querySelector('body').appendChild(s); if(0){ var elements = document.querySelectorAll('.exp_area_vote'); Array.prototype.forEach.call(elements, function(el, i){ var id = el.querySelector('.vote_id').textContent; el.textContent = ''; var html = ''; var obj = el; fetch('/api/getVote/'+id).then(response => response.json()).then(data => { html = '
'+data.title+'
'; obj.insertAdjacentHTML('beforeend', html); obj.querySelector('li:first-child input').click(); var form = obj.querySelector('form'); form.addEventListener("submit", function(event){ event.preventDefault() var val = form.querySelector('input[name=t]:checked').val; form.querySelector('.exp_fl').setAttribute('disabled', 'disabled'); var milliseconds = new Date().getTime(); fetch('/api/setVote/'+id+'?t='+milliseconds, { method: 'post', headers: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: {t: val} }).then(data => { console.log(data); // if(msg!='0') data.result = msg; // obj.find('.exp_fr').click(); }); }); // console.log(form); }); // form.addEventListener("submit", function(){ // var val = form.querySelector('input[name=t]:checked').val(); // console.log(val) // var milliseconds = new Date().getTime(); // form.querySelector('.exp_fl').setAttribute('disabled', 'disabled'); // fetch('/api/setVote/'+id, { // method: 'post', // headers: { // 'Accept': 'application/json, text/plain, */*', // 'Content-Type': 'application/json' // }, // body: JSON.stringify({t: val}) // }).then(response => response.json()).then(data => { // // if(msg!='0') data.result = msg; // // obj.find('.exp_fr').click(); // }); // $.ajax({ // type: "POST", // url: '/api/setVote/'+id+'?t=', // data: {t: val}, // dataType: "html", // success: function(msg){ // if(msg!='0') data.result = msg; // obj.find('.exp_fr').click(); // } // }); // }); // $.getJSON('/api/getVote/'+id, function(data) { // // // obj.find('form').submit(function(){ // var val = $(this).find('input[name=t]:checked').val(); // var milliseconds = new Date().getTime(); // $(this).find('.exp_fl').attr('disabled', 'disabled'); // $.ajax({ // type: "POST", // url: '/api/setVote/'+id+'?t='+milliseconds, // data: {t: val}, // dataType: "html", // success: function(msg){ // if(msg!='0') data.result = msg; // obj.find('.exp_fr').click(); // } // }); // return false; // }); // obj.find('.exp_fr').click(function(){ // $('body').css('overflow', 'hidden'); // var obj = $(this).parents('.exp_area_vote'); // var htmlp = '

Kết quả thăm dò

'; // htmlp += '

'+data.title+'

'; // htmlp += '

'+data.time+'

'; // var total = 0; // if(data.result) { // var all_result = jQuery.parseJSON(data.result); // $.each(all_result, function(key, val) {total+=val;}) // } // $.each(all_ans, function(key, val) { // var percent = 0; // var voted = 0; // if(total>0) { // if(isNaN(all_result[key]) || all_result[key]==undefined) all_result[key] = 0; // percent = Math.round(((all_result[key])/total*100) * 100) / 100; // voted = all_result[key]; // } // htmlp += ''; // }); // $('#exp_vote_pop').addClass('exp_open').html('
'+htmlp+'
'+val+''+percent+'%'+voted+' phiếu
Đóng
'); // $('.exp_vote_pclose').unbind().click(function(){ // $('#exp_vote_pop').removeClass('exp_open').html(''); // $('body').css('overflow', 'auto'); // return false; // }); // return false; // }); // }); }); } $('head').append(""); $('body').append('
'); $('.exp_area_votemusic').addClass('exp_area_vote'); $('.exp_area_vote').each(function(){ var id = $(this).find('.vote_id').text(); $(this).html(''); var html = ''; var obj = $(this); $.getJSON('/api/getVote/'+id, function(data) { console.log(data); html = '
'+data.title+'
'; obj.append(html); obj.find('li:eq(0) input').click(); obj.find('form').submit(function(){ var val = $(this).find('input[name=t]:checked').val(); console.log(val) var milliseconds = new Date().getTime(); $(this).find('.exp_fl').attr('disabled', 'disabled'); $.ajax({ type: "POST", url: '/api/setVote/'+id+'?time='+milliseconds, data: {t: val}, dataType: "html", success: function(msg){ if(msg!='0') data.result = msg; obj.find('.exp_fr').click(); } }); return false; }); obj.find('.exp_fr').click(function(){ $('body').css('overflow', 'hidden'); var obj = $(this).parents('.exp_area_vote'); var htmlp = '

Kết quả thăm dò

'; htmlp += '

'+data.title+'

'; htmlp += '

'+data.time+'

'; var total = 0; if(data.result) { var all_result = jQuery.parseJSON(data.result); $.each(all_result, function(key, val) {total+=val;}) } $.each(all_ans, function(key, val) { var percent = 0; var voted = 0; if(total>0) { if(isNaN(all_result[key]) || all_result[key]==undefined) all_result[key] = 0; percent = Math.round(((all_result[key])/total*100) * 100) / 100; voted = all_result[key]; } htmlp += ''; }); $('#exp_vote_pop').addClass('exp_open').html('
'+htmlp+'
'+val+''+percent+'%'+voted+' phiếu
Đóng
'); $('.exp_vote_pclose').unbind().click(function(){ $('#exp_vote_pop').removeClass('exp_open').html(''); $('body').css('overflow', 'auto'); return false; }); return false; }); }); });