// function dynamicColors() { // var r = Math.floor(Math.random() * 255); // var g = Math.floor(Math.random() * 255); // var b = Math.floor(Math.random() * 255); // return "rgb(" + r + "," + g + "," + b + ")"; // } var base = $("base").attr("href"); $('[data-fancybox]').fancybox({ toolbar : false, smallBtn : true, buttons : ['close'], iframe : { preload : false } }) // $(".voteView").click(function() { // var type="POST"; // var url= base +"/vote/modalVote"; // // var data= $(this).serialize(); // $.ajax({type:type,url:url, // success:function(data){ // console.log(data); // $('#vote_modal_chart').find('.body').html(data); // $('#vote_modal_chart').modal('show'); // // $.noConflict(); // // $.fancybox.open(data); // } // }).done(function() { // }); // }); $('.emailSubscribe').keypress(function(e) { if (e.which == 13) { var emailSub = $('.emailSubscribe').val(); // alert(emailSub); if (!isEmail(emailSub)) { $('.emailSubscribe').css({ 'border-color': '#FF0000' }); // $html = '
คุณกรอกอีเมล์ไม่ถูกต้อง
กรุณากรอกอีเมล์ใหม่อีกครั้ง
'; // alertpopup("#popup-success", "คุณกรอกอีเมล์ไม่ถูกต้อง", false, "home", $html); // inputEmail.focus(); // clickBoosScrollTop('inputEmail'); return false; } else { $('.emailSubscribe').css('border-color', '#ebebeb'); $('#newsletter-modal').modal('show'); $("#subEmail").val(emailSub); return false; } } }); $('.btnSubscribe').click(function(e) { var emailSub = $('.emailSubscribe').val(); if (emailSub != "") { if (!isEmail(emailSub)) { $('.emailSubscribe').css({ 'border-color': '#FF0000' }); // $html = '
คุณกรอกอีเมล์ไม่ถูกต้อง
กรุณากรอกอีเมล์ใหม่อีกครั้ง
'; // alertpopup("#popup-success", "คุณกรอกอีเมล์ไม่ถูกต้อง", false, "home", $html); // inputEmail.focus(); // clickBoosScrollTop('inputEmail'); return false; } else { $('.emailSubscribe').css('border-color', '#ebebeb'); $('#newsletter-modal').modal('show'); $("#subEmail").val(emailSub); return false; } } else { $('#newsletter-modal-noemail').modal('show'); return false; } }); function isEmail(str) { //alert(str); var supported = 0; if (window.RegExp) { var tempStr = "a"; var tempReg = new RegExp(tempStr); if (tempReg.test(tempStr)) supported = 1; } //alert(str + '1'); if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)"); var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); return (!r1.test(str) && r2.test(str)); } // $(document).ready(function(){ // $('#vote_modal').modal('show'); // }); $('#voteform').validator().on('submit', function (e) { if (e.isDefaultPrevented()) { $('#voteform').validator('validate'); } else { e.preventDefault(); // if ($('#submit-contact').hasClass('disabled')) return false; $('.form-button').hide(); $('.btnLoading').show(); // $("#submit-vote").attr("disabled", true); var type="POST"; var url= base +"/vote/addVote"; var data= $(this).serialize(); $.ajax({type:type,url:url,data:data, success:function(data){ var data = JSON.parse(data); // console.log(data); switch (data.status) { case 'Success': $('#vote_modal').find('.title').html(data.msg); $('#vote_modal').find('.desc').html(data.msg_desc); $('#vote_modal_icon_success').show(); $('#vote_modal').modal('show'); break; default: $('#vote_modal').find('.title').html(data.msg); $('#vote_modal').find('.desc').html(data.msg_desc); $('#vote_modal_icon_error').show(); $('#vote_modal').modal('show'); break; } } }).done(function() { // // // $("#modal_failed").on("hidden.bs.modal", function () { // // // // window.location = base +"/member"; // // // $('#modal_member').modal('show'); // // // }); $("#vote_modal").on("hidden.bs.modal", function () { $('#voteform')[0].reset(); $('#voteform').validator('validate'); $('.form-button').show(); $('.btnLoading').hide(); // window.location = base +"home"; }); // $("#modal_failed").on("hidden.bs.modal", function () { // window.location = base +"/home"; // }); }); } }); $(document).ready(function () { var path = $("base").attr("href"); console.log(path); $('.firstKeygroup').first().addClass('active'); $('.firstKeylist').first().addClass('active in'); }); $(document).on('click','.clickLink',function () { var path = $("base").attr("href"); var id = $(this).data('id'); var dataSet = { method : 'update', id : id, }; $.ajax({ type: "POST", url: path+"home/api-update-view/", data: dataSet, success: function (data) { } }); }); $(document).ready(function () { $('.fancybox-container').addClass('fancybox-popup'); }); // start view vote const path = $("base").attr("href"); $('#btnVoteResults').click(async function () { const settings = { "url": `${path}/vote2`, "type": "POST", "timeout": 0, }; try { const response = await $.ajax(settings); if (response?.code === 200) { $('#modelVoteResults .h2.title strong').text(response?.item?.vote?.subject); voteChart(response?.item?.answer); $('#modelVoteResults').modal('show'); }else{ $('#modelVoteResults').modal('hide'); } } catch (error) { $('#modelVoteResults').modal('hide'); console.log('error ', error); } }); function voteChart(dataset) { $('#highcharts').empty(); let highcharts = document.getElementById('highcharts'); const colors = [ '#2d651e', '#7fc25b', '#5b91cf', '#efad4c', '#a52021' ]; highcharts = new Highcharts.Chart({ chart: { renderTo: 'highcharts', plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, borderWidth: 0, height: '100%', style: { fontFamily: "Noto Sans Thai, sans-serif", } }, credits: { enabled: false }, legend: { navigation: { enabled: true }, borderWidth: 0, labelFormatter: function () { return '
' + this.name + '' + Highcharts.numberFormat(this.y, 0, '.', ',') + '
'; }, useHTML: true, verticalAlign: 'bottom', x: 0, y: 0, layout: 'horizontal', itemMarginBottom: 20, align: 'center', symbolWidth: 20, symbolHeight: 20 }, title: { text: '' }, tooltip: { backgroundColor: '#fff', borderColor: '#ebebeb', borderRadius: 10, borderWidth: 1, style: { "color": "#777", "fontSize": "14px", "fontWeight": "400" }, }, colors: colors, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', center: ["50%", "50%"], dataLabels: { enabled: false, }, showInLegend: true, size: '100%', height: '100%', innerSize: '30%' } }, series: [{ type: 'pie', name: 'จำนวน', data: dataset }] }); } // mockup highcharts // $(document).ready(function () { // const highcharts = document.getElementById('highcharts'); // const colors = [ // '#004AC9', // '#33AFE4', // '#E44756', // '#FFAB23', // '#08517E' // ]; // highcharts = new Highcharts.Chart({ // chart: { // renderTo: 'highcharts', // plotBackgroundColor: null, // plotBorderWidth: null, // plotShadow: false, // borderWidth: 0, // height:'100%', // style: { // fontFamily: "Noto Sans Thai, sans-serif", // } // }, // credits: { // enabled: false // }, // legend: { // navigation: { // enabled: true // }, // borderWidth: 0, // labelFormatter: function() { // return '
' + this.name + '' + Highcharts.numberFormat(this.y, 0, '.', ',') + '
'; // }, // useHTML: true, // verticalAlign: 'bottom', // x: 0, // y: 0, // layout: 'horizontal', // itemMarginBottom: 20, // align: 'center', // symbolWidth: 20, // symbolHeight: 20 // }, // title: { // text: '' // }, // tooltip: { // backgroundColor: '#fff', // borderColor: '#ebebeb', // borderRadius: 10, // borderWidth: 1, // style: { // "color": "#777", // "fontSize": "14px", // "fontWeight": "400" // }, // }, // colors: colors, // plotOptions: { // pie: { // allowPointSelect: true, // cursor: 'pointer', // center: ["50%", "50%"], // dataLabels: { // enabled: false, // }, // showInLegend: true, // size: '100%', // height:'100%', // innerSize: '30%' // } // }, // series: [{ // type: 'pie', // name: 'จำนวน', // data: [ // { // name: 'พึงพอใจมากที่สุด', // y: 200 // }, { // name: 'พึงพอใจมาก', // y: 150 // }, { // name: 'พึงพอใจปานกลาง', // y: 100 // }, { // name: 'พึงพอใจน้อย', // y: 50 // }, { // name: 'พึงพอใจน้อยที่สุด', // y: 20 // } // ] // }] // }); // });