1(function( $ ) { 2 'use strict'; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 32 function forRadioType( item, id, dataFlag ){ 33 var chartContent; 34 if( dataFlag == 'quiz' ){ 35 chartContent = 'ays_quiz_quiz-question_frontend_statistics_chart_'+id; 36 }else if( dataFlag == 'question' ){ 37 chartContent = 'ays_quiz_question_frontend_statistics_chart_'+id; 38 } 39 var dataTypes = [[ aysQuizFrontendStatisticsPublicChartLangObj.answers , aysQuizFrontendStatisticsPublicChartLangObj.percent ]]; 40 var answerName = item.answer_name; 41 var answerCount = item.answer_count; 42 var type = item.type; 43 for (var key in answerCount) { 44 if( answerName[key] == undefined ){ 45 answerName[key] = 'Not answered'; 46 } 47 dataTypes.push([ 48 answerName[key] + '', answerCount[key] 49 ]); 50 } 51 google.charts.load('current', {'packages':['corechart']}); 52 google.charts.setOnLoadCallback(drawChart); 53 54 function drawChart() { 55 56 var data = google.visualization.arrayToDataTable(dataTypes); 57 var options = { 58 height: 250, 59 fontSize: 16, 60 chartArea: { 61 width: '80%', 62 height: '80%' 63 } 64 }; 65 66 var chart = new google.visualization.PieChart( document.getElementById( chartContent ) ); 67 68 chart.draw(data, options); 69 70 //create trigger to resizeEnd event 71 jQuery(window).resize(function() { 72 if(this.resizeTO) clearTimeout(this.resizeTO); 73 this.resizeTO = setTimeout(function() { 74 jQuery(this).trigger('resizeEnd'); 75 }, 500); 76 }); 77 78 //redraw graph when window resize is completed 79 jQuery(window).on('resizeEnd', function() { 80 chart.draw(data, options); 81 }); 82 } 83 } 84 85 function forCheckboxType( item, id, dataFlag ){ 86 var chartContent; 87 var dataTypes = [[ aysQuizFrontendStatisticsPublicChartLangObj.answers , aysQuizFrontendStatisticsPublicChartLangObj.count ]]; 88 if( dataFlag == 'quiz' ){ 89 var answerName = item.answer_name; 90 var answerCount = item.answer_count; 91 if( ! jQuery.isEmptyObject( item ) ){ 92 for (var key in answerCount) { 93 if( answerName[key] == undefined ){ 94 answerName[key] = 'Not answered'; 95 } 96 dataTypes.push([ 97 answerName[key] + '', answerCount[key] 98 ]); 99 } 100 }else{ 101 dataTypes.push([ 102 '', 0 103 ]); 104 } 105 chartContent = 'ays_quiz_quiz-question_frontend_statistics_chart_'+id; 106 }else if( dataFlag == 'question' ){ 107 var answerName = item.answer_name; 108 var answerCount = item.answer_count; 109 var type = item.type; 110 if( ! jQuery.isEmptyObject( item ) ){ 111 for (var key in answerCount) { 112 if( answerName[key] == undefined ){ 113 answerName[key] = 'Not answered'; 114 } 115 dataTypes.push([ 116 answerName[key] + '', answerCount[key] 117 ]); 118 } 119 }else{ 120 dataTypes.push([ 121 '', 0 122 ]); 123 } 124 chartContent = 'ays_quiz_question_frontend_statistics_chart_'+id; 125 } 126 127 google.charts.load('current', {packages: ['corechart', 'bar']}); 128 google.charts.setOnLoadCallback(drawBasic); 129 130 function drawBasic() { 131 132 var data = google.visualization.arrayToDataTable(dataTypes); 133 var groupData = google.visualization.data.group( 134 data, 135 [{column: 0, modifier: function () {return 'total'}, type:'string'}], 136 [{column: 1, aggregation: google.visualization.data.sum, type: 'number'}] 137 ); 138 139 var formatPercent = new google.visualization.NumberFormat({ 140 pattern: '#%' 141 }); 142 143 var formatShort = new google.visualization.NumberFormat({ 144 pattern: 'short' 145 }); 146 147 var view = new google.visualization.DataView(data); 148 view.setColumns([0, 1, { 149 calc: function (dt, row) { 150 if( jQuery.isEmptyObject( item.answers ) ){ 151 return amount; 152 } 153 var amount = formatShort.formatValue(dt.getValue(row, 1)); 154 var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1)); 155 return amount + ' (' + percent + ')'; 156 }, 157 type: 'string', 158 role: 'annotation' 159 }]); 160 161 var options = { 162 height: 300, 163 fontSize: 14, 164 chartArea: { 165 width: '50%', 166 height: '80%' 167 }, 168 annotations: { 169 alwaysOutside: true 170 }, 171 bars: 'horizontal', 172 bar: { groupWidth: "50%" }, 173 }; 174 175 var chart = new google.visualization.BarChart( document.getElementById( chartContent ) ); 176 177 chart.draw(view, options); 178 179 //create trigger to resizeEnd event 180 jQuery(window).resize(function() { 181 if(this.resizeTO) clearTimeout(this.resizeTO); 182 this.resizeTO = setTimeout(function() { 183 jQuery(this).trigger('resizeEnd'); 184 }, 500); 185 }); 186 187 //redraw graph when window resize is completed 188 jQuery(window).on('resizeEnd', function() { 189 chart.draw(view, options); 190 }); 191 } 192 } 193
194 $(document).ready(function(){ 195 /**======================================== 196 * ========== Question chart start ========= 197 *==========================================*/ 198 var questionSummaryContainer = $(document).find('.ays-quiz-frontend-statistics-question-summary-container'); 199 var questionSummaryContainerLength = $(document).find('.ays-quiz-frontend-statistics-question-summary-container').length; 200 for (var index = 0; index < questionSummaryContainerLength; index++) { 201 var dataFlag = questionSummaryContainer.eq(index).data('flag'); 202 var uniqueId = questionSummaryContainer.eq(index).attr('data-unique-id'); 203 var id = questionSummaryContainer.eq(index).data('id'); 204 var aysQuizFrontendStatistics = JSON.parse( atob( window.aysQuizFrontendStatistics[ uniqueId ] ) ); 205 206 if(dataFlag == 'quiz'){ 207 for(var i in aysQuizFrontendStatistics){ 208 var questionType = aysQuizFrontendStatistics[i].type; 209 switch ( questionType ) { 210 case 'radio': 211 case 'select': 212 case 'true_or_false': 213 forRadioType( aysQuizFrontendStatistics[i], i, dataFlag ) 214 break; 215 case 'checkbox': 216 forCheckboxType( aysQuizFrontendStatistics[i], i, dataFlag ) 217 break; 218 case 'text': 219 case 'short_text': 220 case 'number': 221 case 'date': 222 // forTextType( answerCount, questionType ) 223 break; 224 default: 225 break; 226 } 227 } 228 }else if(dataFlag == 'question'){ 229 var questionType = aysQuizFrontendStatistics.type; 230 switch ( questionType ) { 231 case 'radio': 232 case 'select': 233 case 'true_or_false': 234 forRadioType( aysQuizFrontendStatistics, id, dataFlag ) 235 break; 236 case 'checkbox': 237 forCheckboxType( aysQuizFrontendStatistics, id, dataFlag ) 238 break; 239 case 'text': 240 case 'short_text': 241 case 'number': 242 case 'date': 243 // forTextType( answerCount, questionType ) 244 break; 245 default: 246 break; 247 } 248 } 249 // } 250 } 251 /**======================================== 252 * ========== Question chart end ========= 253 *==========================================*/ 254 }); 255 256})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.