var HMRateCount = HMRateCount || {}; HMRateCount.rate = function () { var rateCountBox = $('#course-rate-count'); var courseId = rateCountBox.data('course'); $.post('/course/rating/get-count.php', {courseid:courseId}, function(response) { if (response.status == 'success') { var html = HMRateCount.getBoxHtml(response); rateCountBox.html(html); rateCountBox.find('.average-star').each(function (index) { var score = parseFloat($(this).data('score')); $(this).rateYo({ rating: score, readOnly: true }); }); } }, 'JSON'); }; HMRateCount.getBoxHtml = function(data) { var html = '
' + '
' + '

Nhận xét

' + '

Đánh giá trung bình

' + '
' + '
'+ data.score +'
' + '
'+ '
' + '
' + '

Chi tiết

' + '
' + '
    '; for (var i in data.detail) { html += '
  • ' + ''+ data.detail[i].name +'' + '
    '+ '
    '+ '
    ' + '
    ' + ''+ data.detail[i].percent +'' + '
  • '; } html += '
'; html += '
'; html += '
'; return html; }; HMRateCount.init = function () { if (typeof $.fn.rateYo !== 'undefined') { HMRateCount.rate(); } else { var checkElement = $('#hm-raty-test'); if (checkElement.length) { setTimeout(function () { HMRateCount.init(); }, 100); } else { $('body').append('
'); // load javascript lib $.ajax({ url: "/course/rating/js/jquery.rateyo.js", dataType: "script", cache: true }).done(function () { HMRateCount.rate(); }); } } }; $(function () { HMRateCount.init(); });