testing-result.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. $(document).ready(function(){
  2. moveActiveBar($('.testing-result-tabs li:first-child a[data-toggle="tab"]'));
  3. $('.testing-result-tabs a[data-toggle="tab"]').on('show.bs.tab', function (e) {
  4. moveActiveBar($(e.target));
  5. });
  6. $(".create-voca-input .input-content .dropdown-menu li").click(function(event) {
  7. $(this).parents(".create-voca-input").find('#voca-type').val($(this).attr('val'));
  8. $(this).parents(".create-voca-input").find('.input-content .dropdown button span').text($(this).text());
  9. });
  10. $("#modal-create-voca").on('shown.bs.modal', function () {
  11. $('#voca-name').focus();
  12. })
  13. });
  14. function moveActiveBar(element){
  15. var pos = $(element).parent('li').position().left;
  16. var width = $(element).innerWidth();
  17. var bar = $('.testing-result-tabs .active-bar');
  18. $(bar).innerWidth(width);
  19. $(bar).css('left', pos);
  20. }
  21. $(document).ready(function(){
  22. // CHART
  23. var cQuantity = parseInt($(".md-result-chart-content").attr('quantity'));
  24. var cRow = parseInt($(".md-result-chart-content").attr('row'));
  25. var dataRoot = $.parseJSON($(".md-result-chart-content").attr('data'));
  26. var data = Array();
  27. for(var i = 0; i < dataRoot.length; i++){
  28. var distanceFirst = 50;
  29. var distanceLast = 50;
  30. var distanceMiddle = 50;
  31. if(i == 0){
  32. data.push({ name: '', percent: Math.max(dataRoot[i].percent - distanceFirst,1), textShow: [] });
  33. }
  34. if(i == dataRoot.length - 1){
  35. data.push(dataRoot[i]);
  36. data.push({ name: '', percent: Math.max(dataRoot[i].percent - distanceLast,1), textShow: [] });
  37. }else{
  38. data.push(dataRoot[i]);
  39. data.push({ name: '', percent: Math.max(Math.min(dataRoot[i].percent,dataRoot[i+1].percent) - distanceMiddle, 1), textShow: [] });
  40. }
  41. }
  42. $(".md-result-chart-content .md-result-row").empty();
  43. for(var i = cRow - 1; i >= 0; i--){
  44. $(".md-result-chart-content .md-result-row").append('<span class="row-child" val="' + (Math.round(cQuantity / (cRow - 1) * i)) + '"></span>');
  45. }
  46. $(".md-result-chart-content .md-result-col").empty();
  47. for(var i = 0; i < data.length; i++){
  48. $(".md-result-chart-content .md-result-col").append('<span class="col-child ' + (data[i].class == undefined ? "": data[i].class) + '">' + data[i].name + '</span>');
  49. }
  50. $(".md-result-chart-content .md-result-point").empty();
  51. for(var i = 0; i < data.length; i++){
  52. $(".md-result-chart-content .md-result-point").append('<span class="point-child"><span class="point-item" style="bottom: ' + data[i].percent + '%;' + (data[i].name == ''?'display: none':'') + '"><span class="point-detail"></span></span></span>');
  53. for (var j = 0; j < data[i].textShow.length; j++) {
  54. $(".md-result-chart-content .md-result-point .point-child:last-child .point-item .point-detail").append("<p>" + data[i].textShow[j] + "</p>");
  55. }
  56. }
  57. var cWidth = 410;
  58. var cHeight = 260;
  59. var cPolygon = "";
  60. var cPolyline = "";
  61. var cWidthItem = 410/data.length;
  62. for(var i = 0; i < data.length; i++){
  63. var cXItem = cWidthItem * i + cWidthItem/2;
  64. var cYItem = cHeight*(100 - data[i].percent)/100;
  65. var temp = "";
  66. if(i == 0){
  67. temp = "M0," + cHeight*(100 - data[i].percent)/100;
  68. cPolygon += "L0," + cHeight*(100 - data[i].percent)/100;
  69. }else{
  70. var cXItem1 = cWidthItem * i;
  71. var cYItem1 = cHeight*(100 - data[i-1].percent)/100;
  72. var cXItem2 = cWidthItem * i;
  73. var cYItem2 = cHeight*(100 - data[i].percent)/100;
  74. if(i == data.length - 1){
  75. temp = " C" + cXItem1 + "," + cYItem1 + " " + cXItem2 + "," + Math.min((cYItem2+ cHeight*0.1),cHeight) + " " + cWidthItem * (i + 1) + "," + cYItem + " ";
  76. }else if(i == 1){
  77. temp = " C" + cXItem1 + "," + Math.min((cYItem1+ cHeight*0.1),cHeight) + " " + cXItem2 + "," + cYItem2 + " " + cXItem + "," + cYItem + " ";
  78. }else{
  79. temp = " C" + cXItem1 + "," + cYItem1 + " " + cXItem2 + "," + cYItem2 + " " + cXItem + "," + cYItem + " ";
  80. }
  81. cPolygon += temp;
  82. }
  83. cPolyline += temp;
  84. }
  85. cPolygon = "M0" + "," + cHeight + " " + cPolygon + " L" + cWidth + "," + cHeight + 'Z';
  86. $("#chart-polyline").attr('d', cPolyline);
  87. $("#chart-polygon").attr('d', cPolygon);
  88. $(window).on('resize',function(event) {
  89. $(".md-result-chart-content").innerHeight($(".md-result-chart-content").innerWidth()*310/450);
  90. if($(".md-result-chart-content").innerWidth() == 0 ){
  91. $(".md-result-chart-content").innerHeight(310);
  92. }
  93. });
  94. $(document).ready(function(){
  95. $(".md-result-chart-content").innerHeight($(".md-result-chart-content").innerWidth()*310/450);
  96. if($(".md-result-chart-content").innerWidth() == 0 ){
  97. $(".md-result-chart-content").innerHeight(310);
  98. }
  99. });
  100. if(dataRoot.length > 1){
  101. setTimeout(function(){
  102. document.getElementById('chart-polyline-animate').beginElement();
  103. }, 1000);
  104. }
  105. });
  106. // END CHART
  107. // Flip Word
  108. $(document).on('click', '.testing-result-word-item .item-cover',function(){
  109. var element = $(this).parents('.testing-result-word-item');
  110. if( $(element).hasClass('item-flipper') ){
  111. $(element).removeClass('item-flipper');
  112. }else{
  113. $(element).addClass('item-flipper');
  114. $(element).find('.item-sound').trigger('click');
  115. }
  116. $('.item-tip.alert').fadeOut();
  117. });
  118. $(document).on('click', '.testing-result-word-item .item-sound', function(event){
  119. event.stopPropagation();
  120. });