| 1 |
/******/ (function() { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ "./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js": |
| 5 |
/*!**********************************************************************!*\ |
| 6 |
!*** ./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js ***! |
| 7 |
\**********************************************************************/ |
| 8 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 9 |
|
| 10 |
"use strict"; |
| 11 |
__webpack_require__.r(__webpack_exports__); |
| 12 |
/* harmony import */ var _utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/lp-modal-overlay */ "./assets/src/apps/js/utils/lp-modal-overlay.js"); |
| 13 |
|
| 14 |
const lpModalOverlayCompleteItem = { |
| 15 |
elBtnFinishCourse: null, |
| 16 |
elBtnCompleteItem: null, |
| 17 |
|
| 18 |
init() { |
| 19 |
if (!_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].init()) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
if (undefined === lpGlobalSettings || 'yes' !== lpGlobalSettings.option_enable_popup_confirm_finish) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
this.elBtnFinishCourse = document.querySelectorAll('.lp-btn-finish-course'); |
| 28 |
this.elBtnCompleteItem = document.querySelector('.lp-btn-complete-item'); |
| 29 |
|
| 30 |
if (this.elBtnCompleteItem) { |
| 31 |
this.elBtnCompleteItem.addEventListener('click', e => { |
| 32 |
e.preventDefault(); |
| 33 |
const form = e.target.closest('form'); |
| 34 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].elLPOverlay.show(); |
| 35 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setTitleModal(form.dataset.title); |
| 36 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setContentModal('<div class="pd-2em">' + form.dataset.confirm + '</div>'); |
| 37 |
|
| 38 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].callBackYes = () => { |
| 39 |
form.submit(); |
| 40 |
}; |
| 41 |
}); |
| 42 |
} |
| 43 |
|
| 44 |
if (this.elBtnFinishCourse) { |
| 45 |
this.elBtnFinishCourse.forEach(element => element.addEventListener('click', e => { |
| 46 |
e.preventDefault(); |
| 47 |
const form = e.target.closest('form'); |
| 48 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].elLPOverlay.show(); |
| 49 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setTitleModal(form.dataset.title); |
| 50 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setContentModal('<div class="pd-2em">' + form.dataset.confirm + '</div>'); |
| 51 |
|
| 52 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].callBackYes = () => { |
| 53 |
form.submit(); |
| 54 |
}; |
| 55 |
})); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
}; |
| 60 |
/* harmony default export */ __webpack_exports__["default"] = (lpModalOverlayCompleteItem); |
| 61 |
|
| 62 |
/***/ }), |
| 63 |
|
| 64 |
/***/ "./assets/src/apps/js/frontend/single-course/index.js": |
| 65 |
/*!************************************************************!*\ |
| 66 |
!*** ./assets/src/apps/js/frontend/single-course/index.js ***! |
| 67 |
\************************************************************/ |
| 68 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 69 |
|
| 70 |
"use strict"; |
| 71 |
__webpack_require__.r(__webpack_exports__); |
| 72 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 73 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); |
| 74 |
/* harmony import */ var _learnpress_quiz__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @learnpress/quiz */ "@learnpress/quiz"); |
| 75 |
/* harmony import */ var _learnpress_quiz__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_learnpress_quiz__WEBPACK_IMPORTED_MODULE_1__); |
| 76 |
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./assets/src/apps/js/frontend/single-course/store/index.js"); |
| 77 |
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_store__WEBPACK_IMPORTED_MODULE_2__); |
| 78 |
/* harmony import */ var _single_curriculum_components_sidebar__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../single-curriculum/components/sidebar */ "./assets/src/apps/js/frontend/single-curriculum/components/sidebar.js"); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
// Use toggle in Curriculum tab. |
| 84 |
|
| 85 |
class SingleCourse extends _wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Component { |
| 86 |
render() { |
| 87 |
return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null); |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
/* harmony default export */ __webpack_exports__["default"] = (SingleCourse); |
| 93 |
|
| 94 |
function run() { |
| 95 |
(0,_single_curriculum_components_sidebar__WEBPACK_IMPORTED_MODULE_3__.Sidebar)(); |
| 96 |
} |
| 97 |
|
| 98 |
document.addEventListener('DOMContentLoaded', () => { |
| 99 |
run(); |
| 100 |
}); |
| 101 |
|
| 102 |
/***/ }), |
| 103 |
|
| 104 |
/***/ "./assets/src/apps/js/frontend/single-course/store/index.js": |
| 105 |
/*!******************************************************************!*\ |
| 106 |
!*** ./assets/src/apps/js/frontend/single-course/store/index.js ***! |
| 107 |
\******************************************************************/ |
| 108 |
/***/ (function() { |
| 109 |
|
| 110 |
/** |
| 111 |
* Created by tu on 9/19/19. |
| 112 |
*/ |
| 113 |
|
| 114 |
/***/ }), |
| 115 |
|
| 116 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/components/search.js": |
| 117 |
/*!****************************************************************************!*\ |
| 118 |
!*** ./assets/src/apps/js/frontend/single-curriculum/components/search.js ***! |
| 119 |
\****************************************************************************/ |
| 120 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 121 |
|
| 122 |
"use strict"; |
| 123 |
__webpack_require__.r(__webpack_exports__); |
| 124 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 125 |
/* harmony export */ "searchCourseContent": function() { return /* binding */ searchCourseContent; } |
| 126 |
/* harmony export */ }); |
| 127 |
const searchCourseContent = () => { |
| 128 |
const popup = document.querySelector('#popup-course'); |
| 129 |
const list = document.querySelector('#learn-press-course-curriculum'); |
| 130 |
|
| 131 |
if (popup && list) { |
| 132 |
const items = list.querySelector('.curriculum-sections'); |
| 133 |
const form = popup.querySelector('.search-course'); |
| 134 |
const search = popup.querySelector('.search-course input[type="text"]'); |
| 135 |
|
| 136 |
if (!search || !items || !form) { |
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
const sections = items.querySelectorAll('li.section'); |
| 141 |
const dataItems = items.querySelectorAll('li.course-item'); |
| 142 |
const dataSearch = []; |
| 143 |
dataItems.forEach(item => { |
| 144 |
const itemID = item.dataset.id; |
| 145 |
const name = item.querySelector('.item-name'); |
| 146 |
dataSearch.push({ |
| 147 |
id: itemID, |
| 148 |
name: name ? name.textContent.toLowerCase() : '' |
| 149 |
}); |
| 150 |
}); |
| 151 |
|
| 152 |
const submit = event => { |
| 153 |
event.preventDefault(); |
| 154 |
const inputVal = search.value; |
| 155 |
form.classList.add('searching'); |
| 156 |
|
| 157 |
if (!inputVal) { |
| 158 |
form.classList.remove('searching'); |
| 159 |
} |
| 160 |
|
| 161 |
const outputs = []; |
| 162 |
dataSearch.forEach(i => { |
| 163 |
if (!inputVal || i.name.match(inputVal.toLowerCase())) { |
| 164 |
outputs.push(i.id); |
| 165 |
dataItems.forEach(c => { |
| 166 |
if (outputs.indexOf(c.dataset.id) !== -1) { |
| 167 |
c.classList.remove('hide-if-js'); |
| 168 |
} else { |
| 169 |
c.classList.add('hide-if-js'); |
| 170 |
} |
| 171 |
}); |
| 172 |
} |
| 173 |
}); |
| 174 |
sections.forEach(section => { |
| 175 |
const listItem = section.querySelectorAll('.course-item'); |
| 176 |
const isTrue = []; |
| 177 |
listItem.forEach(a => { |
| 178 |
if (outputs.includes(a.dataset.id)) { |
| 179 |
isTrue.push(a.dataset.id); |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
if (isTrue.length === 0) { |
| 184 |
section.classList.add('hide-if-js'); |
| 185 |
} else { |
| 186 |
section.classList.remove('hide-if-js'); |
| 187 |
} |
| 188 |
}); |
| 189 |
}; |
| 190 |
|
| 191 |
const clear = form.querySelector('.clear'); |
| 192 |
|
| 193 |
if (clear) { |
| 194 |
clear.addEventListener('click', e => { |
| 195 |
e.preventDefault(); |
| 196 |
search.value = ''; |
| 197 |
submit(e); |
| 198 |
}); |
| 199 |
} |
| 200 |
|
| 201 |
form.addEventListener('submit', submit); |
| 202 |
search.addEventListener('keyup', submit); |
| 203 |
} |
| 204 |
}; |
| 205 |
|
| 206 |
/***/ }), |
| 207 |
|
| 208 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/components/sidebar.js": |
| 209 |
/*!*****************************************************************************!*\ |
| 210 |
!*** ./assets/src/apps/js/frontend/single-curriculum/components/sidebar.js ***! |
| 211 |
\*****************************************************************************/ |
| 212 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 213 |
|
| 214 |
"use strict"; |
| 215 |
__webpack_require__.r(__webpack_exports__); |
| 216 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 217 |
/* harmony export */ "Sidebar": function() { return /* binding */ Sidebar; } |
| 218 |
/* harmony export */ }); |
| 219 |
const $ = jQuery; |
| 220 |
const { |
| 221 |
throttle |
| 222 |
} = lodash; |
| 223 |
const Sidebar = () => { |
| 224 |
// Tungnx - Show/hide sidebar curriculumn |
| 225 |
const elSidebarToggle = document.querySelector('#sidebar-toggle'); // For style of theme |
| 226 |
|
| 227 |
const toggleSidebar = toggle => { |
| 228 |
$('body').removeClass('lp-sidebar-toggle__open'); |
| 229 |
$('body').removeClass('lp-sidebar-toggle__close'); |
| 230 |
|
| 231 |
if (toggle) { |
| 232 |
$('body').addClass('lp-sidebar-toggle__close'); |
| 233 |
} else { |
| 234 |
$('body').addClass('lp-sidebar-toggle__open'); |
| 235 |
} |
| 236 |
}; // For lp and theme |
| 237 |
|
| 238 |
|
| 239 |
if (elSidebarToggle) { |
| 240 |
if ($(window).innerWidth() <= 768) { |
| 241 |
elSidebarToggle.setAttribute('checked', 'checked'); |
| 242 |
} else if (LP.Cookies.get('sidebar-toggle')) { |
| 243 |
elSidebarToggle.setAttribute('checked', 'checked'); |
| 244 |
} else { |
| 245 |
elSidebarToggle.removeAttribute('checked'); |
| 246 |
} |
| 247 |
|
| 248 |
document.querySelector('#popup-course').addEventListener('click', e => { |
| 249 |
if (e.target.id === 'sidebar-toggle') { |
| 250 |
LP.Cookies.set('sidebar-toggle', e.target.checked ? true : false); |
| 251 |
toggleSidebar(LP.Cookies.get('sidebar-toggle')); |
| 252 |
} |
| 253 |
}); |
| 254 |
} // End editor by tungnx |
| 255 |
|
| 256 |
|
| 257 |
const $curriculum = $('#learn-press-course-curriculum'); |
| 258 |
$curriculum.find('.section-desc').each((i, el) => { |
| 259 |
const a = $('<span class="show-desc"></span>').on('click', () => { |
| 260 |
b.toggleClass('c'); |
| 261 |
}); |
| 262 |
const b = $(el).siblings('.section-title').append(a); |
| 263 |
}); |
| 264 |
$('.section').each(function () { |
| 265 |
const $section = $(this), |
| 266 |
$toggle = $section.find('.section-left'); |
| 267 |
$toggle.on('click', function () { |
| 268 |
const isClose = $section.toggleClass('closed').hasClass('closed'); |
| 269 |
const sections = LP.Cookies.get('closed-section-' + lpGlobalSettings.post_id) || []; |
| 270 |
const sectionId = parseInt($section.data('section-id')); |
| 271 |
const at = sections.findIndex(id => { |
| 272 |
return id == sectionId; |
| 273 |
}); |
| 274 |
|
| 275 |
if (isClose) { |
| 276 |
sections.push(parseInt($section.data('section-id'))); |
| 277 |
} else { |
| 278 |
sections.splice(at, 1); |
| 279 |
} |
| 280 |
|
| 281 |
LP.Cookies.remove('closed-section-(.*)'); |
| 282 |
LP.Cookies.set('closed-section-' + lpGlobalSettings.post_id, [...new Set(sections)]); |
| 283 |
}); |
| 284 |
}); |
| 285 |
}; |
| 286 |
|
| 287 |
/***/ }), |
| 288 |
|
| 289 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/scrolltoitem.js": |
| 290 |
/*!***********************************************************************!*\ |
| 291 |
!*** ./assets/src/apps/js/frontend/single-curriculum/scrolltoitem.js ***! |
| 292 |
\***********************************************************************/ |
| 293 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 294 |
|
| 295 |
"use strict"; |
| 296 |
__webpack_require__.r(__webpack_exports__); |
| 297 |
/* harmony import */ var _utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/lp-modal-overlay */ "./assets/src/apps/js/utils/lp-modal-overlay.js"); |
| 298 |
|
| 299 |
const $ = jQuery; |
| 300 |
const scrollToItemCurrent = { |
| 301 |
init() { |
| 302 |
this.scrollToItemViewing = function () { |
| 303 |
const elItemViewing = $('.viewing-course-item'); |
| 304 |
|
| 305 |
if (elItemViewing.length) { |
| 306 |
const elCourseCurriculumn = $('#learn-press-course-curriculum'); |
| 307 |
const heightCourseItemContentHeader = $('#popup-sidebar').outerHeight(); |
| 308 |
const heightSectionTitle = $('.section-title').outerHeight(); |
| 309 |
const heightSectionHeader = $('.section-header').outerHeight(); |
| 310 |
const regex = new RegExp('^viewing-course-item-([0-9].*)'); |
| 311 |
const classList = elItemViewing.attr('class'); |
| 312 |
const classArr = classList.split(/\s+/); |
| 313 |
let idItem = 0; |
| 314 |
$.each(classArr, function (i, className) { |
| 315 |
const compare = regex.exec(className); |
| 316 |
|
| 317 |
if (compare) { |
| 318 |
idItem = compare[1]; |
| 319 |
return false; |
| 320 |
} |
| 321 |
}); |
| 322 |
|
| 323 |
if (0 === idItem) { |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
const elItemCurrent = $('.course-item-' + idItem); |
| 328 |
const offSetTop = elItemCurrent.offset().top; |
| 329 |
const offset = elItemCurrent.offset().top - elCourseCurriculumn.offset().top + elCourseCurriculumn.scrollTop(); |
| 330 |
elCourseCurriculumn.animate({ |
| 331 |
scrollTop: LP.Hook.applyFilters('scroll-item-current', offset - heightSectionHeader) |
| 332 |
}, 800); |
| 333 |
} |
| 334 |
}; |
| 335 |
|
| 336 |
this.scrollToItemViewing(); |
| 337 |
} |
| 338 |
|
| 339 |
}; |
| 340 |
/* harmony default export */ __webpack_exports__["default"] = (scrollToItemCurrent); |
| 341 |
|
| 342 |
/***/ }), |
| 343 |
|
| 344 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/skeleton.js": |
| 345 |
/*!*******************************************************************!*\ |
| 346 |
!*** ./assets/src/apps/js/frontend/single-curriculum/skeleton.js ***! |
| 347 |
\*******************************************************************/ |
| 348 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 349 |
|
| 350 |
"use strict"; |
| 351 |
__webpack_require__.r(__webpack_exports__); |
| 352 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 353 |
/* harmony export */ "default": function() { return /* binding */ courseCurriculumSkeleton; } |
| 354 |
/* harmony export */ }); |
| 355 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); |
| 356 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_0__); |
| 357 |
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); |
| 358 |
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1__); |
| 359 |
/* harmony import */ var _scrolltoitem__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./scrolltoitem */ "./assets/src/apps/js/frontend/single-curriculum/scrolltoitem.js"); |
| 360 |
/* harmony import */ var _components_search__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/search */ "./assets/src/apps/js/frontend/single-curriculum/components/search.js"); |
| 361 |
// Rest API load content in Tab Curriculum - Nhamdv. |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
function courseCurriculumSkeleton() { |
| 367 |
let courseID = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; |
| 368 |
let isLoadingItems = false; |
| 369 |
let isLoadingSections = false; |
| 370 |
|
| 371 |
const Sekeleton = () => { |
| 372 |
const elementCurriculum = document.querySelector('.learnpress-course-curriculum'); |
| 373 |
|
| 374 |
if (!elementCurriculum) { |
| 375 |
return; |
| 376 |
} |
| 377 |
|
| 378 |
getResponse(elementCurriculum); |
| 379 |
}; |
| 380 |
|
| 381 |
const getResponse = async ele => { |
| 382 |
const skeleton = ele.querySelector('.lp-skeleton-animation'); |
| 383 |
const itemID = ele.dataset.id; |
| 384 |
const sectionID = ele.dataset.section; |
| 385 |
|
| 386 |
try { |
| 387 |
const page = 1; |
| 388 |
const response = await _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default()({ |
| 389 |
path: (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_0__.addQueryArgs)('lp/v1/lazy-load/course-curriculum', { |
| 390 |
courseId: courseID || lpGlobalSettings.post_id || '', |
| 391 |
page, |
| 392 |
sectionID: sectionID || '' |
| 393 |
}), |
| 394 |
method: 'GET' |
| 395 |
}); |
| 396 |
const { |
| 397 |
data, |
| 398 |
status, |
| 399 |
message |
| 400 |
} = response; |
| 401 |
let section_ids = data.section_ids; |
| 402 |
|
| 403 |
if (status === 'error') { |
| 404 |
throw new Error(message || 'Error'); |
| 405 |
} |
| 406 |
|
| 407 |
let returnData = data.content; |
| 408 |
|
| 409 |
if (undefined === returnData) { |
| 410 |
// For old Eduma <= 4.6.0 |
| 411 |
returnData = data; |
| 412 |
section_ids = response.section_ids; |
| 413 |
} |
| 414 |
|
| 415 |
if (sectionID) { |
| 416 |
if (section_ids && !section_ids.includes(sectionID)) { |
| 417 |
const response2 = await getResponsive('', page + 1, sectionID); |
| 418 |
|
| 419 |
if (response2) { |
| 420 |
const { |
| 421 |
data2, |
| 422 |
pages2, |
| 423 |
page2 |
| 424 |
} = response2; |
| 425 |
await parseContentItems({ |
| 426 |
ele, |
| 427 |
returnData, |
| 428 |
sectionID, |
| 429 |
itemID, |
| 430 |
data2, |
| 431 |
pages2, |
| 432 |
page2 |
| 433 |
}); |
| 434 |
} |
| 435 |
} else { |
| 436 |
await parseContentItems({ |
| 437 |
ele, |
| 438 |
returnData, |
| 439 |
sectionID, |
| 440 |
itemID |
| 441 |
}); |
| 442 |
} |
| 443 |
} else { |
| 444 |
returnData && ele.insertAdjacentHTML('beforeend', returnData); |
| 445 |
} |
| 446 |
} catch (error) { |
| 447 |
ele.insertAdjacentHTML('beforeend', `<div class="lp-ajax-message error" style="display:block">${error.message || 'Error: Query lp/v1/lazy-load/course-curriculum'}</div>`); |
| 448 |
} |
| 449 |
|
| 450 |
skeleton && skeleton.remove(); |
| 451 |
(0,_components_search__WEBPACK_IMPORTED_MODULE_3__.searchCourseContent)(); |
| 452 |
}; |
| 453 |
|
| 454 |
const parseContentItems = async _ref => { |
| 455 |
let { |
| 456 |
ele, |
| 457 |
returnData, |
| 458 |
sectionID, |
| 459 |
itemID, |
| 460 |
data2, |
| 461 |
pages2, |
| 462 |
page2 |
| 463 |
} = _ref; |
| 464 |
const parser = new DOMParser(); |
| 465 |
const doc = parser.parseFromString(returnData, 'text/html'); |
| 466 |
|
| 467 |
if (data2) { |
| 468 |
const sections = doc.querySelector('.curriculum-sections'); |
| 469 |
const loadMoreBtn = doc.querySelector('.curriculum-more__button'); |
| 470 |
|
| 471 |
if (loadMoreBtn) { |
| 472 |
if (pages2 <= page2) { |
| 473 |
loadMoreBtn.remove(); |
| 474 |
} else { |
| 475 |
loadMoreBtn.dataset.page = page2; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
sections.insertAdjacentHTML('beforeend', data2); |
| 480 |
} |
| 481 |
|
| 482 |
const section = doc.querySelector(`[data-section-id="${sectionID}"]`); |
| 483 |
|
| 484 |
if (section) { |
| 485 |
const items = section.querySelectorAll('.course-item'); |
| 486 |
const item_ids = [...items].map(item => item.dataset.id); |
| 487 |
const sectionContent = section.querySelector('.section-content'); |
| 488 |
const itemLoadMore = section.querySelector('.section-item__loadmore'); |
| 489 |
|
| 490 |
if (itemID && !item_ids.includes(itemID)) { |
| 491 |
const responseItem = await getResponsiveItem('', 2, sectionID, itemID); |
| 492 |
const { |
| 493 |
data3, |
| 494 |
pages3, |
| 495 |
paged3, |
| 496 |
page |
| 497 |
} = responseItem; |
| 498 |
|
| 499 |
if (pages3 <= paged3 || pages3 <= page) { |
| 500 |
itemLoadMore.remove(); |
| 501 |
} else { |
| 502 |
itemLoadMore.dataset.page = page; |
| 503 |
} |
| 504 |
|
| 505 |
if (data3 && sectionContent) { |
| 506 |
sectionContent.insertAdjacentHTML('beforeend', data3); |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
ele.insertAdjacentHTML('beforeend', doc.body.innerHTML); |
| 512 |
_scrolltoitem__WEBPACK_IMPORTED_MODULE_2__["default"].init(); |
| 513 |
}; |
| 514 |
|
| 515 |
const getResponsiveItem = async (returnData, paged, sectionID, itemID) => { |
| 516 |
const response = await _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default()({ |
| 517 |
path: (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_0__.addQueryArgs)('lp/v1/lazy-load/course-curriculum-items', { |
| 518 |
sectionId: sectionID || '', |
| 519 |
page: paged |
| 520 |
}), |
| 521 |
method: 'GET' |
| 522 |
}); |
| 523 |
const { |
| 524 |
data, |
| 525 |
status, |
| 526 |
pages, |
| 527 |
message |
| 528 |
} = response; |
| 529 |
const { |
| 530 |
page |
| 531 |
} = data; |
| 532 |
let item_ids; |
| 533 |
|
| 534 |
if (status === 'success') { |
| 535 |
let dataTmp = data.content; |
| 536 |
item_ids = data.item_ids; |
| 537 |
|
| 538 |
if (undefined === dataTmp) { |
| 539 |
// For old Eduma <= 4.6.0 |
| 540 |
dataTmp = data; |
| 541 |
item_ids = response.item_ids; |
| 542 |
} |
| 543 |
|
| 544 |
returnData += dataTmp; |
| 545 |
|
| 546 |
if (sectionID && item_ids && itemID && !item_ids.includes(itemID)) { |
| 547 |
return getResponsiveItem(returnData, paged + 1, sectionID, itemID); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
isLoadingItems = false; |
| 552 |
return { |
| 553 |
data3: returnData, |
| 554 |
pages3: pages || data.pages, |
| 555 |
status3: status, |
| 556 |
message3: message, |
| 557 |
page: page || 0 |
| 558 |
}; |
| 559 |
}; |
| 560 |
|
| 561 |
const getResponsive = async (returnData, page, sectionID) => { |
| 562 |
const response = await _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_1___default()({ |
| 563 |
path: (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_0__.addQueryArgs)('lp/v1/lazy-load/course-curriculum', { |
| 564 |
courseId: courseID || lpGlobalSettings.post_id || '', |
| 565 |
page, |
| 566 |
sectionID: sectionID || '', |
| 567 |
loadMore: true |
| 568 |
}), |
| 569 |
method: 'GET' |
| 570 |
}); |
| 571 |
const { |
| 572 |
data, |
| 573 |
status, |
| 574 |
message |
| 575 |
} = response; |
| 576 |
let returnDataTmp = data.content; |
| 577 |
let section_ids = data.section_ids; |
| 578 |
let pages = data.pages; |
| 579 |
|
| 580 |
if (undefined === returnDataTmp) { |
| 581 |
// For old Eduma <= 4.6.0 |
| 582 |
returnDataTmp = data; |
| 583 |
section_ids = response.section_ids; |
| 584 |
pages = response.pages; |
| 585 |
} |
| 586 |
|
| 587 |
if (status === 'success') { |
| 588 |
returnData += returnDataTmp; |
| 589 |
|
| 590 |
if (sectionID && section_ids && section_ids.length > 0 && !section_ids.includes(sectionID)) { |
| 591 |
return getResponsive(returnData, page + 1, sectionID); |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
isLoadingSections = false; |
| 596 |
return { |
| 597 |
data2: returnData, |
| 598 |
pages2: pages || data.pages, |
| 599 |
page2: page, |
| 600 |
status2: status, |
| 601 |
message2: message |
| 602 |
}; |
| 603 |
}; |
| 604 |
|
| 605 |
Sekeleton(); |
| 606 |
document.addEventListener('click', e => { |
| 607 |
const sectionBtns = document.querySelectorAll('.section-item__loadmore'); |
| 608 |
[...sectionBtns].map(async sectionBtn => { |
| 609 |
if (sectionBtn.contains(e.target) && !isLoadingItems) { |
| 610 |
isLoadingItems = true; |
| 611 |
const sectionItem = sectionBtn.parentNode; |
| 612 |
const sectionId = sectionItem.getAttribute('data-section-id'); |
| 613 |
const sectionContent = sectionItem.querySelector('.section-content'); |
| 614 |
const paged = parseInt(sectionBtn.dataset.page); |
| 615 |
sectionBtn.classList.add('loading'); |
| 616 |
|
| 617 |
try { |
| 618 |
const response = await getResponsiveItem('', paged + 1, sectionId, ''); |
| 619 |
const { |
| 620 |
data3, |
| 621 |
pages3, |
| 622 |
status3, |
| 623 |
message3 |
| 624 |
} = response; |
| 625 |
|
| 626 |
if (status3 === 'error') { |
| 627 |
throw new Error(message3 || 'Error'); |
| 628 |
} |
| 629 |
|
| 630 |
if (pages3 <= paged + 1) { |
| 631 |
sectionBtn.remove(); |
| 632 |
} else { |
| 633 |
sectionBtn.dataset.page = paged + 1; |
| 634 |
} |
| 635 |
|
| 636 |
sectionContent.insertAdjacentHTML('beforeend', data3); |
| 637 |
} catch (e) { |
| 638 |
sectionContent.insertAdjacentHTML('beforeend', `<div class="lp-ajax-message error" style="display:block">${e.message || 'Error: Query lp/v1/lazy-load/course-curriculum'}</div>`); |
| 639 |
} |
| 640 |
|
| 641 |
sectionBtn.classList.remove('loading'); |
| 642 |
(0,_components_search__WEBPACK_IMPORTED_MODULE_3__.searchCourseContent)(); |
| 643 |
} |
| 644 |
}); // Load more Sections |
| 645 |
|
| 646 |
const moreSections = document.querySelectorAll('.curriculum-more__button'); |
| 647 |
[...moreSections].map(async moreSection => { |
| 648 |
if (moreSection.contains(e.target) && !isLoadingSections) { |
| 649 |
isLoadingSections = true; |
| 650 |
const paged = parseInt(moreSection.dataset.page); |
| 651 |
const sections = moreSection.parentNode.parentNode.querySelector('.curriculum-sections'); |
| 652 |
|
| 653 |
if (paged && sections) { |
| 654 |
moreSection.classList.add('loading'); |
| 655 |
|
| 656 |
try { |
| 657 |
const response2 = await getResponsive('', paged + 1, ''); |
| 658 |
const { |
| 659 |
data2, |
| 660 |
pages2, |
| 661 |
status2, |
| 662 |
message2 |
| 663 |
} = response2; |
| 664 |
|
| 665 |
if (status2 === 'error') { |
| 666 |
throw new Error(message2 || 'Error'); |
| 667 |
} |
| 668 |
|
| 669 |
if (pages2 <= paged + 1) { |
| 670 |
moreSection.remove(); |
| 671 |
} else { |
| 672 |
moreSection.dataset.page = paged + 1; |
| 673 |
} |
| 674 |
|
| 675 |
sections.insertAdjacentHTML('beforeend', data2); |
| 676 |
} catch (e) { |
| 677 |
sections.insertAdjacentHTML('beforeend', `<div class="lp-ajax-message error" style="display:block">${e.message || 'Error: Query lp/v1/lazy-load/course-curriculum'}</div>`); |
| 678 |
} |
| 679 |
|
| 680 |
moreSection.classList.remove('loading'); |
| 681 |
(0,_components_search__WEBPACK_IMPORTED_MODULE_3__.searchCourseContent)(); |
| 682 |
} |
| 683 |
} |
| 684 |
}); // Show/Hide accordion |
| 685 |
|
| 686 |
if (document.querySelector('.learnpress-course-curriculum')) { |
| 687 |
const sections = document.querySelectorAll('.section'); |
| 688 |
[...sections].map(section => { |
| 689 |
if (section.contains(e.target)) { |
| 690 |
const toggle = section.querySelector('.section-left'); |
| 691 |
toggle.contains(e.target) && section.classList.toggle('closed'); |
| 692 |
} |
| 693 |
}); |
| 694 |
} |
| 695 |
}); |
| 696 |
} |
| 697 |
|
| 698 |
/***/ }), |
| 699 |
|
| 700 |
/***/ "./assets/src/apps/js/utils/lp-modal-overlay.js": |
| 701 |
/*!******************************************************!*\ |
| 702 |
!*** ./assets/src/apps/js/utils/lp-modal-overlay.js ***! |
| 703 |
\******************************************************/ |
| 704 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 705 |
|
| 706 |
"use strict"; |
| 707 |
__webpack_require__.r(__webpack_exports__); |
| 708 |
const $ = jQuery; |
| 709 |
let elLPOverlay = null; |
| 710 |
const lpModalOverlay = { |
| 711 |
elLPOverlay: null, |
| 712 |
elMainContent: null, |
| 713 |
elTitle: null, |
| 714 |
elBtnYes: null, |
| 715 |
elBtnNo: null, |
| 716 |
elFooter: null, |
| 717 |
elCalledModal: null, |
| 718 |
callBackYes: null, |
| 719 |
instance: null, |
| 720 |
|
| 721 |
init() { |
| 722 |
if (this.instance) { |
| 723 |
return true; |
| 724 |
} |
| 725 |
|
| 726 |
this.elLPOverlay = $('.lp-overlay'); |
| 727 |
|
| 728 |
if (!this.elLPOverlay.length) { |
| 729 |
return false; |
| 730 |
} |
| 731 |
|
| 732 |
elLPOverlay = this.elLPOverlay; |
| 733 |
this.elMainContent = elLPOverlay.find('.main-content'); |
| 734 |
this.elTitle = elLPOverlay.find('.modal-title'); |
| 735 |
this.elBtnYes = elLPOverlay.find('.btn-yes'); |
| 736 |
this.elBtnNo = elLPOverlay.find('.btn-no'); |
| 737 |
this.elFooter = elLPOverlay.find('.lp-modal-footer'); |
| 738 |
$(document).on('click', '.close, .btn-no', function () { |
| 739 |
elLPOverlay.hide(); |
| 740 |
}); |
| 741 |
$(document).on('click', '.btn-yes', function (e) { |
| 742 |
e.preventDefault(); |
| 743 |
e.stopPropagation(); |
| 744 |
|
| 745 |
if ('function' === typeof lpModalOverlay.callBackYes) { |
| 746 |
lpModalOverlay.callBackYes(); |
| 747 |
} |
| 748 |
}); |
| 749 |
this.instance = this; |
| 750 |
return true; |
| 751 |
}, |
| 752 |
|
| 753 |
setElCalledModal(elCalledModal) { |
| 754 |
this.elCalledModal = elCalledModal; |
| 755 |
}, |
| 756 |
|
| 757 |
setContentModal(content, event) { |
| 758 |
this.elMainContent.html(content); |
| 759 |
|
| 760 |
if ('function' === typeof event) { |
| 761 |
event(); |
| 762 |
} |
| 763 |
}, |
| 764 |
|
| 765 |
setTitleModal(content) { |
| 766 |
this.elTitle.html(content); |
| 767 |
} |
| 768 |
|
| 769 |
}; |
| 770 |
/* harmony default export */ __webpack_exports__["default"] = (lpModalOverlay); |
| 771 |
|
| 772 |
/***/ }), |
| 773 |
|
| 774 |
/***/ "@learnpress/quiz": |
| 775 |
/*!******************************!*\ |
| 776 |
!*** external ["LP","quiz"] ***! |
| 777 |
\******************************/ |
| 778 |
/***/ (function(module) { |
| 779 |
|
| 780 |
"use strict"; |
| 781 |
module.exports = window["LP"]["quiz"]; |
| 782 |
|
| 783 |
/***/ }), |
| 784 |
|
| 785 |
/***/ "@wordpress/api-fetch": |
| 786 |
/*!**********************************!*\ |
| 787 |
!*** external ["wp","apiFetch"] ***! |
| 788 |
\**********************************/ |
| 789 |
/***/ (function(module) { |
| 790 |
|
| 791 |
"use strict"; |
| 792 |
module.exports = window["wp"]["apiFetch"]; |
| 793 |
|
| 794 |
/***/ }), |
| 795 |
|
| 796 |
/***/ "@wordpress/element": |
| 797 |
/*!*********************************!*\ |
| 798 |
!*** external ["wp","element"] ***! |
| 799 |
\*********************************/ |
| 800 |
/***/ (function(module) { |
| 801 |
|
| 802 |
"use strict"; |
| 803 |
module.exports = window["wp"]["element"]; |
| 804 |
|
| 805 |
/***/ }), |
| 806 |
|
| 807 |
/***/ "@wordpress/url": |
| 808 |
/*!*****************************!*\ |
| 809 |
!*** external ["wp","url"] ***! |
| 810 |
\*****************************/ |
| 811 |
/***/ (function(module) { |
| 812 |
|
| 813 |
"use strict"; |
| 814 |
module.exports = window["wp"]["url"]; |
| 815 |
|
| 816 |
/***/ }) |
| 817 |
|
| 818 |
/******/ }); |
| 819 |
/************************************************************************/ |
| 820 |
/******/ // The module cache |
| 821 |
/******/ var __webpack_module_cache__ = {}; |
| 822 |
/******/ |
| 823 |
/******/ // The require function |
| 824 |
/******/ function __webpack_require__(moduleId) { |
| 825 |
/******/ // Check if module is in cache |
| 826 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 827 |
/******/ if (cachedModule !== undefined) { |
| 828 |
/******/ return cachedModule.exports; |
| 829 |
/******/ } |
| 830 |
/******/ // Create a new module (and put it into the cache) |
| 831 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 832 |
/******/ // no module.id needed |
| 833 |
/******/ // no module.loaded needed |
| 834 |
/******/ exports: {} |
| 835 |
/******/ }; |
| 836 |
/******/ |
| 837 |
/******/ // Execute the module function |
| 838 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 839 |
/******/ |
| 840 |
/******/ // Return the exports of the module |
| 841 |
/******/ return module.exports; |
| 842 |
/******/ } |
| 843 |
/******/ |
| 844 |
/************************************************************************/ |
| 845 |
/******/ /* webpack/runtime/compat get default export */ |
| 846 |
/******/ !function() { |
| 847 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 848 |
/******/ __webpack_require__.n = function(module) { |
| 849 |
/******/ var getter = module && module.__esModule ? |
| 850 |
/******/ function() { return module['default']; } : |
| 851 |
/******/ function() { return module; }; |
| 852 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 853 |
/******/ return getter; |
| 854 |
/******/ }; |
| 855 |
/******/ }(); |
| 856 |
/******/ |
| 857 |
/******/ /* webpack/runtime/define property getters */ |
| 858 |
/******/ !function() { |
| 859 |
/******/ // define getter functions for harmony exports |
| 860 |
/******/ __webpack_require__.d = function(exports, definition) { |
| 861 |
/******/ for(var key in definition) { |
| 862 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 863 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 864 |
/******/ } |
| 865 |
/******/ } |
| 866 |
/******/ }; |
| 867 |
/******/ }(); |
| 868 |
/******/ |
| 869 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 870 |
/******/ !function() { |
| 871 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
| 872 |
/******/ }(); |
| 873 |
/******/ |
| 874 |
/******/ /* webpack/runtime/make namespace object */ |
| 875 |
/******/ !function() { |
| 876 |
/******/ // define __esModule on exports |
| 877 |
/******/ __webpack_require__.r = function(exports) { |
| 878 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 879 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 880 |
/******/ } |
| 881 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 882 |
/******/ }; |
| 883 |
/******/ }(); |
| 884 |
/******/ |
| 885 |
/************************************************************************/ |
| 886 |
var __webpack_exports__ = {}; |
| 887 |
// This entry need to be wrapped in an IIFE because it need to be in strict mode. |
| 888 |
!function() { |
| 889 |
"use strict"; |
| 890 |
/*!******************************************************!*\ |
| 891 |
!*** ./assets/src/apps/js/frontend/single-course.js ***! |
| 892 |
\******************************************************/ |
| 893 |
__webpack_require__.r(__webpack_exports__); |
| 894 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 895 |
/* harmony export */ "enrollCourse": function() { return /* binding */ enrollCourse; }, |
| 896 |
/* harmony export */ "init": function() { return /* binding */ init; }, |
| 897 |
/* harmony export */ "initCourseSidebar": function() { return /* binding */ initCourseSidebar; }, |
| 898 |
/* harmony export */ "initCourseTabs": function() { return /* binding */ initCourseTabs; } |
| 899 |
/* harmony export */ }); |
| 900 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 901 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); |
| 902 |
/* harmony import */ var _single_course_index__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./single-course/index */ "./assets/src/apps/js/frontend/single-course/index.js"); |
| 903 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); |
| 904 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_2__); |
| 905 |
/* harmony import */ var _show_lp_overlay_complete_item__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./show-lp-overlay-complete-item */ "./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js"); |
| 906 |
/* harmony import */ var _utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../utils/lp-modal-overlay */ "./assets/src/apps/js/utils/lp-modal-overlay.js"); |
| 907 |
/* harmony import */ var _single_curriculum_skeleton__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./single-curriculum/skeleton */ "./assets/src/apps/js/frontend/single-curriculum/skeleton.js"); |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
/* harmony default export */ __webpack_exports__["default"] = (_single_course_index__WEBPACK_IMPORTED_MODULE_1__["default"]); |
| 915 |
const init = () => { |
| 916 |
wp.element.render((0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_single_course_index__WEBPACK_IMPORTED_MODULE_1__["default"], null)); |
| 917 |
}; |
| 918 |
const $ = jQuery; |
| 919 |
|
| 920 |
const initCourseTabs = function () { |
| 921 |
$('#learn-press-course-tabs').on('change', 'input[name="learn-press-course-tab-radio"]', function (e) { |
| 922 |
const selectedTab = $('input[name="learn-press-course-tab-radio"]:checked').val(); |
| 923 |
LP.Cookies.set('course-tab', selectedTab); |
| 924 |
$('label[for="' + $(e.target).attr('id') + '"]').closest('li').addClass('active').siblings().removeClass('active'); |
| 925 |
}); |
| 926 |
}; |
| 927 |
|
| 928 |
const initCourseSidebar = function initCourseSidebar() { |
| 929 |
const $sidebar = $('.course-summary-sidebar'); |
| 930 |
|
| 931 |
if (!$sidebar.length) { |
| 932 |
return; |
| 933 |
} |
| 934 |
|
| 935 |
const $window = $(window); |
| 936 |
const $scrollable = $sidebar.children(); |
| 937 |
const offset = $sidebar.offset(); |
| 938 |
let scrollTop = 0; |
| 939 |
const maxHeight = $sidebar.height(); |
| 940 |
const scrollHeight = $scrollable.height(); |
| 941 |
const options = { |
| 942 |
offsetTop: 32 |
| 943 |
}; |
| 944 |
|
| 945 |
const onScroll = function () { |
| 946 |
scrollTop = $window.scrollTop(); |
| 947 |
const top = scrollTop - offset.top + options.offsetTop; |
| 948 |
|
| 949 |
if (top < 0) { |
| 950 |
$sidebar.removeClass('slide-top slide-down'); |
| 951 |
$scrollable.css('top', ''); |
| 952 |
return; |
| 953 |
} |
| 954 |
|
| 955 |
if (top > maxHeight - scrollHeight) { |
| 956 |
$sidebar.removeClass('slide-down').addClass('slide-top'); |
| 957 |
$scrollable.css('top', maxHeight - scrollHeight); |
| 958 |
} else { |
| 959 |
$sidebar.removeClass('slide-top').addClass('slide-down'); |
| 960 |
$scrollable.css('top', options.offsetTop); |
| 961 |
} |
| 962 |
}; |
| 963 |
|
| 964 |
$window.on('scroll.fixed-course-sidebar', onScroll).trigger('scroll.fixed-course-sidebar'); |
| 965 |
}; // Rest API Enroll course - Nhamdv. |
| 966 |
|
| 967 |
|
| 968 |
const enrollCourse = () => { |
| 969 |
const formEnrolls = document.querySelectorAll('form.enroll-course'); |
| 970 |
|
| 971 |
if (formEnrolls.length > 0) { |
| 972 |
formEnrolls.forEach(formEnroll => { |
| 973 |
const submit = async (id, btnEnroll) => { |
| 974 |
try { |
| 975 |
const response = await wp.apiFetch({ |
| 976 |
path: 'lp/v1/courses/enroll-course', |
| 977 |
method: 'POST', |
| 978 |
data: { |
| 979 |
id |
| 980 |
} |
| 981 |
}); |
| 982 |
btnEnroll.classList.remove('loading'); |
| 983 |
btnEnroll.disabled = false; |
| 984 |
const { |
| 985 |
status, |
| 986 |
data: { |
| 987 |
redirect |
| 988 |
}, |
| 989 |
message |
| 990 |
} = response; |
| 991 |
|
| 992 |
if (message && status) { |
| 993 |
btnEnroll.style.display = 'none'; |
| 994 |
formEnroll.innerHTML += `<div class="lp-enroll-notice ${status}">${message}</div>`; |
| 995 |
|
| 996 |
if (redirect) { |
| 997 |
window.location.href = redirect; |
| 998 |
} |
| 999 |
} |
| 1000 |
} catch (error) { |
| 1001 |
form.innerHTML += `<div class="lp-enroll-notice error">${error.message && error.message}</div>`; |
| 1002 |
} |
| 1003 |
}; |
| 1004 |
|
| 1005 |
formEnroll.addEventListener('submit', event => { |
| 1006 |
event.preventDefault(); |
| 1007 |
const id = formEnroll.querySelector('input[name=enroll-course]').value; |
| 1008 |
const btnEnroll = formEnroll.querySelector('button.button-enroll-course'); |
| 1009 |
btnEnroll.classList.add('loading'); |
| 1010 |
btnEnroll.disabled = true; |
| 1011 |
submit(id, btnEnroll); |
| 1012 |
}); |
| 1013 |
}); |
| 1014 |
} // Reload when press back button in chrome. |
| 1015 |
|
| 1016 |
|
| 1017 |
if (document.querySelector('.course-detail-info') !== null) { |
| 1018 |
window.addEventListener('pageshow', event => { |
| 1019 |
const hasCache = event.persisted || typeof window.performance != 'undefined' && String(window.performance.getEntriesByType('navigation')[0].type) == 'back_forward'; |
| 1020 |
|
| 1021 |
if (hasCache) { |
| 1022 |
location.reload(); |
| 1023 |
} |
| 1024 |
}); |
| 1025 |
} |
| 1026 |
}; // Rest API purchase course - Nhamdv. |
| 1027 |
|
| 1028 |
|
| 1029 |
const purchaseCourse = () => { |
| 1030 |
const forms = document.querySelectorAll('form.purchase-course'); |
| 1031 |
|
| 1032 |
if (forms.length > 0) { |
| 1033 |
forms.forEach(form => { |
| 1034 |
// Allow Repurchase. |
| 1035 |
const allowRepurchase = () => { |
| 1036 |
const continueRepurchases = document.querySelectorAll('.lp_allow_repuchase_select'); |
| 1037 |
continueRepurchases.forEach(repurchase => { |
| 1038 |
const radios = repurchase.querySelectorAll('[name=_lp_allow_repurchase_type]'); |
| 1039 |
|
| 1040 |
for (let i = 0, length = radios.length; i < length; i++) { |
| 1041 |
if (radios[i].checked) { |
| 1042 |
const repurchaseType = radios[i].value; |
| 1043 |
const id = form.querySelector('input[name=purchase-course]').value; |
| 1044 |
const btnBuynow = form.querySelector('button.button-purchase-course'); |
| 1045 |
btnBuynow.classList.add('loading'); |
| 1046 |
btnBuynow.disabled = true; |
| 1047 |
submit(id, btnBuynow, repurchaseType); |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
}); |
| 1052 |
}; |
| 1053 |
|
| 1054 |
const submit = async function (id, btn) { |
| 1055 |
let repurchaseType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; |
| 1056 |
|
| 1057 |
try { |
| 1058 |
const response = await wp.apiFetch({ |
| 1059 |
path: 'lp/v1/courses/purchase-course', |
| 1060 |
method: 'POST', |
| 1061 |
data: { |
| 1062 |
id, |
| 1063 |
repurchaseType |
| 1064 |
} |
| 1065 |
}); |
| 1066 |
|
| 1067 |
if (btn) { |
| 1068 |
btn.classList.remove('loading'); |
| 1069 |
btn.disabled = false; |
| 1070 |
} |
| 1071 |
|
| 1072 |
const { |
| 1073 |
status, |
| 1074 |
data: { |
| 1075 |
redirect, |
| 1076 |
type, |
| 1077 |
html, |
| 1078 |
titlePopup |
| 1079 |
}, |
| 1080 |
message |
| 1081 |
} = response; |
| 1082 |
|
| 1083 |
if (type === 'allow_repurchase' && status === 'success') { |
| 1084 |
if (!form.querySelector('.lp_allow_repuchase_select')) { |
| 1085 |
if (!_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].init()) { |
| 1086 |
return; |
| 1087 |
} |
| 1088 |
|
| 1089 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].elLPOverlay.show(); |
| 1090 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].setTitleModal(titlePopup || ''); |
| 1091 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].setContentModal(html); |
| 1092 |
|
| 1093 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].callBackYes = () => { |
| 1094 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_4__["default"].elLPOverlay.hide(); |
| 1095 |
allowRepurchase(); |
| 1096 |
}; |
| 1097 |
} |
| 1098 |
} else if (message && status) { |
| 1099 |
form.innerHTML += `<div class="lp-enroll-notice ${status}">${message}</div>`; |
| 1100 |
|
| 1101 |
if ('success' === status && redirect) { |
| 1102 |
window.location.href = redirect; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
} catch (error) { |
| 1106 |
form.innerHTML += `<div class="lp-enroll-notice error">${error.message && error.message}</div>`; |
| 1107 |
} |
| 1108 |
}; |
| 1109 |
|
| 1110 |
form.addEventListener('submit', event => { |
| 1111 |
event.preventDefault(); |
| 1112 |
const id = form.querySelector('input[name=purchase-course]').value; |
| 1113 |
const btn = form.querySelector('button.button-purchase-course'); |
| 1114 |
btn.classList.add('loading'); |
| 1115 |
btn.disabled = true; |
| 1116 |
submit(id, btn); |
| 1117 |
}); |
| 1118 |
}); |
| 1119 |
} |
| 1120 |
}; |
| 1121 |
|
| 1122 |
const retakeCourse = () => { |
| 1123 |
const elFormRetakeCourses = document.querySelectorAll('.lp-form-retake-course'); |
| 1124 |
|
| 1125 |
if (!elFormRetakeCourses.length) { |
| 1126 |
return; |
| 1127 |
} |
| 1128 |
|
| 1129 |
elFormRetakeCourses.forEach(elFormRetakeCourse => { |
| 1130 |
const elButtonRetakeCourses = elFormRetakeCourse.querySelector('.button-retake-course'); |
| 1131 |
const elCourseId = elFormRetakeCourse.querySelector('[name=retake-course]').value; |
| 1132 |
const elAjaxMessage = elFormRetakeCourse.querySelector('.lp-ajax-message'); |
| 1133 |
|
| 1134 |
const submit = elButtonRetakeCourse => { |
| 1135 |
wp.apiFetch({ |
| 1136 |
path: '/lp/v1/courses/retake-course', |
| 1137 |
method: 'POST', |
| 1138 |
data: { |
| 1139 |
id: elCourseId |
| 1140 |
} |
| 1141 |
}).then(res => { |
| 1142 |
const { |
| 1143 |
status, |
| 1144 |
message, |
| 1145 |
data |
| 1146 |
} = res; |
| 1147 |
elAjaxMessage.innerHTML = message; |
| 1148 |
|
| 1149 |
if (undefined != status && status === 'success') { |
| 1150 |
elButtonRetakeCourse.style.display = 'none'; |
| 1151 |
setTimeout(() => { |
| 1152 |
window.location.replace(data.url_redirect); |
| 1153 |
}, 1000); |
| 1154 |
} else { |
| 1155 |
elAjaxMessage.classList.add('error'); |
| 1156 |
} |
| 1157 |
}).catch(err => { |
| 1158 |
elAjaxMessage.classList.add('error'); |
| 1159 |
elAjaxMessage.innerHTML = 'error: ' + err.message; |
| 1160 |
}).then(() => { |
| 1161 |
elButtonRetakeCourse.classList.remove('loading'); |
| 1162 |
elButtonRetakeCourse.disabled = false; |
| 1163 |
elAjaxMessage.style.display = 'block'; |
| 1164 |
}); |
| 1165 |
}; |
| 1166 |
|
| 1167 |
elFormRetakeCourse.addEventListener('submit', e => { |
| 1168 |
e.preventDefault(); |
| 1169 |
}); |
| 1170 |
elButtonRetakeCourses.addEventListener('click', e => { |
| 1171 |
e.preventDefault(); |
| 1172 |
elButtonRetakeCourses.classList.add('loading'); |
| 1173 |
elButtonRetakeCourses.disabled = true; |
| 1174 |
submit(elButtonRetakeCourses); |
| 1175 |
}); |
| 1176 |
}); |
| 1177 |
}; // Rest API load content course progress - Nhamdv. |
| 1178 |
|
| 1179 |
|
| 1180 |
const courseProgress = () => { |
| 1181 |
const elements = document.querySelectorAll('.lp-course-progress-wrapper'); |
| 1182 |
|
| 1183 |
if (!elements.length) { |
| 1184 |
return; |
| 1185 |
} |
| 1186 |
|
| 1187 |
if ('IntersectionObserver' in window) { |
| 1188 |
const eleObserver = new IntersectionObserver((entries, observer) => { |
| 1189 |
entries.forEach(entry => { |
| 1190 |
if (entry.isIntersecting) { |
| 1191 |
const ele = entry.target; |
| 1192 |
setTimeout(function () { |
| 1193 |
getResponse(ele); |
| 1194 |
}, 600); |
| 1195 |
eleObserver.unobserve(ele); |
| 1196 |
} |
| 1197 |
}); |
| 1198 |
}); |
| 1199 |
[...elements].map(ele => eleObserver.observe(ele)); |
| 1200 |
} |
| 1201 |
|
| 1202 |
const getResponse = async ele => { |
| 1203 |
const response = await wp.apiFetch({ |
| 1204 |
path: 'lp/v1/lazy-load/course-progress', |
| 1205 |
method: 'POST', |
| 1206 |
data: { |
| 1207 |
courseId: lpGlobalSettings.post_id || '', |
| 1208 |
userId: lpGlobalSettings.user_id || '' |
| 1209 |
} |
| 1210 |
}); |
| 1211 |
const { |
| 1212 |
data |
| 1213 |
} = response; |
| 1214 |
ele.innerHTML = data; |
| 1215 |
}; |
| 1216 |
}; |
| 1217 |
|
| 1218 |
const accordionExtraTab = () => { |
| 1219 |
const elements = document.querySelectorAll('.course-extra-box'); |
| 1220 |
[...elements].map(ele => { |
| 1221 |
const title = ele.querySelector('.course-extra-box__title'); |
| 1222 |
title.addEventListener('click', () => { |
| 1223 |
const panel = title.nextElementSibling; |
| 1224 |
const eleActive = document.querySelector('.course-extra-box.active'); |
| 1225 |
|
| 1226 |
if (eleActive && !ele.classList.contains('active')) { |
| 1227 |
eleActive.classList.remove('active'); |
| 1228 |
eleActive.querySelector('.course-extra-box__content').style.display = 'none'; |
| 1229 |
} |
| 1230 |
|
| 1231 |
if (!ele.classList.contains('active')) { |
| 1232 |
ele.classList.add('active'); |
| 1233 |
panel.style.display = 'block'; |
| 1234 |
} else { |
| 1235 |
ele.classList.remove('active'); |
| 1236 |
panel.style.display = 'none'; |
| 1237 |
} |
| 1238 |
}); |
| 1239 |
}); |
| 1240 |
}; |
| 1241 |
|
| 1242 |
const courseContinue = () => { |
| 1243 |
const formContinue = document.querySelectorAll('form.continue-course'); |
| 1244 |
|
| 1245 |
if (formContinue != null && lpGlobalSettings.user_id > 0) { |
| 1246 |
const getResponse = async ele => { |
| 1247 |
const response = await wp.apiFetch({ |
| 1248 |
path: 'lp/v1/courses/continue-course', |
| 1249 |
method: 'POST', |
| 1250 |
data: { |
| 1251 |
courseId: lpGlobalSettings.post_id || '', |
| 1252 |
userId: lpGlobalSettings.user_id || '' |
| 1253 |
} |
| 1254 |
}); |
| 1255 |
return response; |
| 1256 |
}; |
| 1257 |
|
| 1258 |
getResponse(formContinue).then(function (result) { |
| 1259 |
if (result.status === 'success') { |
| 1260 |
formContinue.forEach(form => { |
| 1261 |
form.style.display = 'block'; |
| 1262 |
form.action = result.data; |
| 1263 |
}); |
| 1264 |
} |
| 1265 |
}); |
| 1266 |
} |
| 1267 |
}; |
| 1268 |
|
| 1269 |
|
| 1270 |
$(window).on('load', () => { |
| 1271 |
const $popup = $('#popup-course'); |
| 1272 |
let timerClearScroll; |
| 1273 |
const $curriculum = $('#learn-press-course-curriculum'); |
| 1274 |
accordionExtraTab(); |
| 1275 |
initCourseTabs(); |
| 1276 |
initCourseSidebar(); |
| 1277 |
enrollCourse(); |
| 1278 |
purchaseCourse(); |
| 1279 |
retakeCourse(); |
| 1280 |
courseProgress(); |
| 1281 |
courseContinue(); |
| 1282 |
_show_lp_overlay_complete_item__WEBPACK_IMPORTED_MODULE_3__["default"].init(); //courseCurriculumSkeleton(); |
| 1283 |
}); |
| 1284 |
const detectedElCurriculum = setInterval(function () { |
| 1285 |
const elementCurriculum = document.querySelector('.learnpress-course-curriculum'); |
| 1286 |
|
| 1287 |
if (elementCurriculum) { |
| 1288 |
(0,_single_curriculum_skeleton__WEBPACK_IMPORTED_MODULE_5__["default"])(); |
| 1289 |
clearInterval(detectedElCurriculum); |
| 1290 |
} |
| 1291 |
}, 1); // Add callback for Thimkits |
| 1292 |
|
| 1293 |
LP.Hook.addAction('lp_course_curriculum_skeleton', function (id) { |
| 1294 |
(0,_single_curriculum_skeleton__WEBPACK_IMPORTED_MODULE_5__["default"])(id); |
| 1295 |
}); |
| 1296 |
}(); |
| 1297 |
/******/ })() |
| 1298 |
; |
| 1299 |
//# sourceMappingURL=single-course.js.map |