1(function ($) { 2 $(document).ready(function () { 3 4 $('#removeSixMonths').on('click', function(evt) { 5 evt.preventDefault(); 6 evt.stopPropagation(); 7 var d = new Date($('#input_2_60').val()); 8 d.setMonth(d.getMonth() - 6); 9 $('#input_2_60').val(formatDate(d)); 10 }); 11 12 $('#add14Days').on('click', function(evt) { 13 evt.preventDefault(); 14 evt.stopPropagation(); 15 var d = new Date($('#input_2_60').val()); 16 d.setDate(d.getDate() + 14); 17 $('#input_2_60').val(formatDate(d)); 18 }); 19 20 $('.mini-course-card-footer').on('click', function (evt) { 21 evt.preventDefault(); 22 evt.stopPropagation(); 23 parentId = $(evt.currentTarget).closest('.courses-cards').attr('id'); 24 25 toggleContainer(evt, parentId); 26 }); 27 28 function padTo2Digits(num) { 29 return num.toString().padStart(2, '0'); 30 } 31 32 function formatDate(date) { 33 return ( 34 [ 35 padTo2Digits(date.getMonth() + 1), 36 padTo2Digits(date.getDate()), 37 date.getFullYear(), 38 ].join('/') 39 ); 40 } 41 42 43 $('.certPDF').on('click', function (evt) { 44 evt.preventDefault(); 45 evt.stopPropagation(); 46 var href = $(this).prop('href'); 47 var win = window.open(href, '_blank'); 48 if (win) { 49 win.focus(); 50 } else { 51 alert('Please allow popups for this website'); 52 } 53 }); 54 55 // clicking a dropdown initiates sequence of events to load 56 // user course quiz data 57 $('.mini-course-card-dropdown').on('click', function (evt) { 58 evt.preventDefault(); 59 evt.stopPropagation(); 60 courseId = $(this).data('courseId'); 61 parentId = $(evt.currentTarget).closest('.courses-cards').attr('id'); 62 // toggle result element height 63 toggleResultMenuHeight($(this).attr('id'), evt, courseId, parentId); 64 65 //Toggle certificate complete status bar 66 $(this).find('.progress-percent').toggle(); 67 }); 68 69 $('.card-results').toggle(); 70 71 $('#viewall-courses-toggle').on('click', function () { 72 $('#viewall-courses-toggle-container').animate({ 73 height: 'toggle', 74 }, 500); 75 }); 76 77 jQuery('.mini-course-card').on('click', function (evt) { 78 79 evt.stopPropagation(); 80 81 if (!jQuery(this).data('url')) { 82 window.location.href = jQuery(this).find('a').attr('href'); 83 } else { 84 window.location.href = jQuery(this).data('url'); 85 } 86 }); 87 88 // Collapse all certificate completion on load 89 $('.progress-percent').toggle(); 90 91 92 }); 93})(jQuery); 94 95function toggleContainer(evt, parentId) { 96 elemId = jQuery(evt.currentTarget).attr('id'); 97 courseId = jQuery('#' + elemId).data('courseId'); 98 99 // if ellipsis is displayed onscreen, 100 // make ajax call to get course quiz info 101 if (jQuery('div#' + parentId + ' div.lds-ellipsis-' + courseId).length) { 102 // get course quiz info 103 user_id = jQuery('input[name="user_id"]').val(); 104 105 jQuery.ajax({ 106 url: bb_ajax_main.root + 'ldlms/v2/users/' + user_id + '/quiz-progress?course=' + courseId, 107 method: 'GET', 108 async: false, 109 beforeSend: function (xhr) { 110 xhr.setRequestHeader('X-WP-Nonce', bb_ajax_main.nonce); 111 }, 112 data: { 113 per_page: 100, 114 orderby: 'title', 115 order: 'asc' 116 }, 117 success: function (response, status, jqXHR) { 118 processResult(evt, response, status, jqXHR, courseId) 119 }, 120 }); 121 } 122} 123 124function processResult(evt, response, status, jqXHR, courseId) { 125 resultElementId = 'results-' + courseId; 126 quizId = []; 127 128 // push quiz id's onto array 129 for (quiz in response) { 130 quizId.push(response[quiz].quiz); 131 } 132 133 // ajax call to get quiz titles from custom wp 134 // rest endpoint 135 jQuery.ajax({ 136 url: bb_ajax_main.root + 'bbquizcourseapi/v1/quizinfo', 137 method: 'GET', 138 beforeSend: function (xhr) { 139 xhr.setRequestHeader('X-WP-Nonce', bb_ajax_main.nonce); 140 }, 141 async: false, 142 data: { 143 quizId: quizId, 144 }, 145 dataType: 'json', 146 success: function (data, status, jqXHR) { 147 processResultSuccess(evt, response, data, resultElementId, parentId); 148 } 149 }); 150} 151 152function processResultSuccess(evt, response, data, resultElementId, parentId) { 153 if ("No data" === data) { 154 data = '{ "err": "No data", "course_id": ' + courseId + ' }'; 155 outputResults(evt, response, JSON.parse(data), resultElementId, parentId); 156 return; 157 } 158 159 data = JSON.parse(data); 160 data['course_id'] = courseId; 161 162 outputResults(evt, response, data, resultElementId, parentId); 163} 164 165function outputResults(evt, response, data, resultElementId, parentId) { 166 167 course_id = data.course_id; 168 delete data.course_id; 169 if ('undefined' === typeof data.err) { 170 html = ""; 171 useAltColor = 1; 172 173 var url = jQuery('#mini-course-card-' + course_id).data('url'); 174 175 for (i in response) { 176 var bold = altColor = ""; 177 178 if (response[i].percentage == 100) { 179 bold = " has-text-weight-bold "; 180 } 181 182 color = " result-row-color "; 183 184 if (useAltColor % 2 == 1) { 185 color = " result-row-alt-color "; 186 } 187 188 quiz = response[i].quiz; 189 title = data[quiz].title + ""; 190 // if we haven't seen this quiz yet 191 grade = Number.parseFloat(response[i].percentage).toFixed(2); 192 if (grade < 80) { 193 textColor = " redText "; 194 } else { 195 textColor = " greenText "; 196 } 197 titleParts = title.split(' - '); 198 if (titleParts.length > 1 && titleParts[0] !== "") { 199 title = titleParts[1]; 200 } // no title parts 201 202 html += 203 '<div class="columns m-0 ' + bold + color + textColor + '">' + 204 '<div class="column is-9 ' + 205 bold + 206 '">' + 207 title + 208 '</div>' + 209 '<div class="column is-3 pl-4 ' + bold + '">' + grade + '%'; 210 if (grade < 80) { 211 html += ' (FAIL)'; 212 } else { 213 html += ' (PASS)'; 214 } 215 html += '</div>' + 216 '</div>'; 217 218 useAltColor++; 219 220 221 } 222 223 html += 224 '<div class="columns m-0">' + 225 '<div class="column is-9">' +
226 'Click anywhere to close' + 227 '</div>' + 228 '<div class="column is-3 pl-4">'; 229 html += '</div>' + 230 '</div>'; 231 232 // make sure to include parent in selector i.e. div#courseTab1 div#column-header-<course_id> 233 jQuery('div#' + parentId + ' div#column-header-' + course_id).each(function () { 234 jQuery(this).html(`<div class="column ml-4 is-8 quiz-title-normalize">Quizzes</div><div class="column is-4 quiz-title-normalize">Score</div>`); 235 }); 236 237 jQuery('div#' + parentId + ' div.lds-ellipsis-' + course_id).remove(); 238 jQuery('div#' + parentId + ' div#loading-' + course_id).remove(); 239 jQuery('div#' + parentId + ' #' + resultElementId).html(html); 240 return; 241 } else if (data.err == 'No data') { 242 jQuery('div#' + parentId + ' div.lds-ellipsis-' + course_id).remove(); 243 jQuery('div#' + parentId + ' div#loading-' + course_id).remove(); 244 jQuery('div#' + parentId + ' #' + resultElementId).html('<p class="has-text-weight-bold is-size-4 is-flex is-align-content-center is-justify-content-center" style="padding: 2rem;">Looks like you haven\'t completed any quizzes for this course!</p>'); 245 return; 246 } 247} 248 249function toggleResultMenuHeight(id, evt, courseId, parentId) { 250 idparts = (id + "").split('-'); 251 jQuery('div#' + parentId + ' div#results-' + idparts[3]).toggle(500, function () { 252 popToggleResultMenuHeightCToggleContainer(evt, parentId); 253 }); 254} 255 256function popToggleResultMenuHeightCToggleContainer(evt, parentId) { 257 toggleContainer(evt, parentId); 258} 259
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.