| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /******/ (() => { // webpackBootstrap |
| 2 | 2 | /******/ "use strict"; |
| 3 | 3 | /******/ var __webpack_modules__ = ({ |
| 4 | 4 | |
| @@ -11,13 +11,13 @@ | ||
| 11 | 11 | __webpack_require__.r(__webpack_exports__); |
| 12 | 12 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 13 | 13 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 14 | 14 | /* harmony export */ }); |
| 15 | -/** | |
| 16 | - * List API on backend | |
| 17 | - * | |
| 18 | - * @since 4.2.6 | |
| 19 | - * @version 1.0.2 | |
| 15 | +/** | |
| 16 | + * List API on backend | |
| 17 | + * | |
| 18 | + * @since 4.2.6 | |
| 19 | + * @version 1.0.2 | |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | const lplistAPI = {}; |
| 23 | 23 | let lp_rest_url; |
| @@ -23,12 +23,9 @@ | ||
| 23 | 23 | let lp_rest_url; |
| 24 | 24 | if ('undefined' !== typeof lpDataAdmin) { |
| 25 | 25 | lp_rest_url = lpDataAdmin.lp_rest_url; |
| 26 | 26 | lplistAPI.admin = { |
| 27 | - apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', | |
| 28 | - apiAddons: lp_rest_url + 'lp/v1/addon/all', | |
| 29 | - apiAddonAction: lp_rest_url + 'lp/v1/addon/action-n', | |
| 30 | - apiAddonsPurchase: lp_rest_url + 'lp/v1/addon/info-addons-purchase', | |
| 27 | + // apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', | |
| 31 | 28 | apiSearchCourses: lp_rest_url + 'lp/v1/admin/tools/search-course', |
| 32 | 29 | apiSearchUsers: lp_rest_url + 'lp/v1/admin/tools/search-user', |
| 33 | 30 | apiAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/assign-user-course', |
| 34 | 31 | apiUnAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/unassign-user-course' |
| @@ -63,8 +60,9 @@ | ||
| 63 | 60 | __webpack_require__.r(__webpack_exports__); |
| 64 | 61 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 65 | 62 | /* harmony export */ debounce: () => (/* binding */ debounce), |
| 66 | 63 | /* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), |
| 64 | +/* harmony export */ fullScreenView: () => (/* binding */ fullScreenView), | |
| 67 | 65 | /* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), |
| 68 | 66 | /* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), |
| 69 | 67 | /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), |
| 70 | 68 | /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), |
| @@ -76,18 +74,19 @@ | ||
| 76 | 74 | /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), |
| 77 | 75 | /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), |
| 78 | 76 | /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), |
| 79 | 77 | /* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), |
| 80 | -/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) | |
| 78 | +/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse), | |
| 79 | +/* harmony export */ toggleEnable: () => (/* binding */ toggleEnable) | |
| 81 | 80 | /* harmony export */ }); |
| 82 | -/** | |
| 83 | - * Utils functions | |
| 84 | - * | |
| 85 | - * @param url | |
| 86 | - * @param data | |
| 87 | - * @param functions | |
| 88 | - * @since 4.2.5.1 | |
| 89 | - * @version 1.0.6 | |
| 81 | +/** | |
| 82 | + * Utils functions | |
| 83 | + * | |
| 84 | + * @param url | |
| 85 | + * @param data | |
| 86 | + * @param functions | |
| 87 | + * @since 4.2.5.1 | |
| 88 | + * @version 1.0.7 | |
| 90 | 89 | */ |
| 91 | 90 | const lpClassName = { |
| 92 | 91 | hidden: 'lp-hidden', |
| 93 | 92 | loading: 'loading', |
| @@ -92,9 +91,12 @@ | ||
| 92 | 91 | hidden: 'lp-hidden', |
| 93 | 92 | loading: 'loading', |
| 94 | 93 | elCollapse: 'lp-collapse', |
| 95 | 94 | elSectionToggle: '.lp-section-toggle', |
| 96 | - elTriggerToggle: '.lp-trigger-toggle' | |
| 95 | + elTriggerToggle: '.lp-trigger-toggle', | |
| 96 | + elBtnFullScreen: '.lp-btn-full-screen-view', | |
| 97 | + elFullScreen: 'lp-full-screen-view', | |
| 98 | + elBtnFullScreenClose: 'lp-full-screen-view__close' | |
| 97 | 99 | }; |
| 98 | 100 | const lpFetchAPI = (url, data = {}, functions = {}) => { |
| 99 | 101 | if ('function' === typeof functions.before) { |
| 100 | 102 | functions.before(); |
| @@ -116,12 +118,12 @@ | ||
| 116 | 118 | } |
| 117 | 119 | }); |
| 118 | 120 | }; |
| 119 | 121 | |
| 120 | -/** | |
| 121 | - * Get current URL without params. | |
| 122 | - * | |
| 123 | - * @since 4.2.5.1 | |
| 122 | +/** | |
| 123 | + * Get current URL without params. | |
| 124 | + * | |
| 125 | + * @since 4.2.5.1 | |
| 124 | 126 | */ |
| 125 | 127 | const lpGetCurrentURLNoParam = () => { |
| 126 | 128 | let currentUrl = window.location.href; |
| 127 | 129 | const hasParams = currentUrl.includes('?'); |
| @@ -137,14 +139,14 @@ | ||
| 137 | 139 | }); |
| 138 | 140 | return url; |
| 139 | 141 | }; |
| 140 | 142 | |
| 141 | -/** | |
| 142 | - * Listen element viewed. | |
| 143 | - * | |
| 144 | - * @param el | |
| 145 | - * @param callback | |
| 146 | - * @since 4.2.5.8 | |
| 143 | +/** | |
| 144 | + * Listen element viewed. | |
| 145 | + * | |
| 146 | + * @param el | |
| 147 | + * @param callback | |
| 148 | + * @since 4.2.5.8 | |
| 147 | 149 | */ |
| 148 | 150 | const listenElementViewed = (el, callback) => { |
| 149 | 151 | const observerSeeItem = new IntersectionObserver(function (entries) { |
| 150 | 152 | for (const entry of entries) { |
| @@ -155,13 +157,13 @@ | ||
| 155 | 157 | }); |
| 156 | 158 | observerSeeItem.observe(el); |
| 157 | 159 | }; |
| 158 | 160 | |
| 159 | -/** | |
| 160 | - * Listen element created. | |
| 161 | - * | |
| 162 | - * @param callback | |
| 163 | - * @since 4.2.5.8 | |
| 161 | +/** | |
| 162 | + * Listen element created. | |
| 163 | + * | |
| 164 | + * @param callback | |
| 165 | + * @since 4.2.5.8 | |
| 164 | 166 | */ |
| 165 | 167 | const listenElementCreated = callback => { |
| 166 | 168 | const observerCreateItem = new MutationObserver(function (mutations) { |
| 167 | 169 | mutations.forEach(function (mutation) { |
| @@ -180,14 +182,14 @@ | ||
| 180 | 182 | }); |
| 181 | 183 | // End. |
| 182 | 184 | }; |
| 183 | 185 | |
| 184 | -/** | |
| 185 | - * Listen element created. | |
| 186 | - * | |
| 187 | - * @param selector | |
| 188 | - * @param callback | |
| 189 | - * @since 4.2.7.1 | |
| 186 | +/** | |
| 187 | + * Listen element created. | |
| 188 | + * | |
| 189 | + * @param selector | |
| 190 | + * @param callback | |
| 191 | + * @since 4.2.7.1 | |
| 190 | 192 | */ |
| 191 | 193 | const lpOnElementReady = (selector, callback) => { |
| 192 | 194 | const element = document.querySelector(selector); |
| 193 | 195 | if (element) { |
| @@ -328,17 +330,17 @@ | ||
| 328 | 330 | }; |
| 329 | 331 | return dataHandle; |
| 330 | 332 | }; |
| 331 | 333 | |
| 332 | -/** | |
| 333 | - * Event trigger | |
| 334 | - * For each list of event handlers, listen event on document. | |
| 335 | - * | |
| 336 | - * eventName: 'click', 'change', ... | |
| 337 | - * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] | |
| 338 | - * | |
| 339 | - * @param eventName | |
| 340 | - * @param eventHandlers | |
| 334 | +/** | |
| 335 | + * Event trigger | |
| 336 | + * For each list of event handlers, listen event on document. | |
| 337 | + * | |
| 338 | + * eventName: 'click', 'change', ... | |
| 339 | + * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] | |
| 340 | + * | |
| 341 | + * @param eventName | |
| 342 | + * @param eventHandlers | |
| 341 | 343 | */ |
| 342 | 344 | const eventHandlers = (eventName, eventHandlers) => { |
| 343 | 345 | document.addEventListener(eventName, e => { |
| 344 | 346 | const target = e.target; |
| @@ -379,32 +381,32 @@ | ||
| 379 | 381 | }); |
| 380 | 382 | }); |
| 381 | 383 | }; |
| 382 | 384 | |
| 383 | -/** | |
| 384 | - * Debounce - delays function execution until after `wait` ms of inactivity. | |
| 385 | - * | |
| 386 | - * Each call resets the timer. Only the last call in a burst executes. | |
| 387 | - * | |
| 388 | - * USE CASES: | |
| 389 | - * - Search inputs, form validation, window resize | |
| 390 | - * - Multiple elements need independent timers | |
| 391 | - * - When you need to call with different arguments | |
| 392 | - * | |
| 393 | - * EXAMPLES: | |
| 394 | - * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); | |
| 395 | - * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); | |
| 396 | - * | |
| 397 | - * const debouncedResize = debounce( recalculateLayout, 250 ); | |
| 398 | - * window.addEventListener('resize', debouncedResize); | |
| 399 | - * | |
| 400 | - * ⚠️ Create ONCE outside event handlers, not inside. | |
| 401 | - * | |
| 402 | - * @param {Function} func - Function to debounce (can be anonymous) | |
| 403 | - * @param {number} wait - Milliseconds to wait (default: 500) | |
| 404 | - * @return {Function} Debounced wrapper function | |
| 405 | - * @since 4.3.7 | |
| 406 | - * @version 1.0.0 | |
| 385 | +/** | |
| 386 | + * Debounce - delays function execution until after `wait` ms of inactivity. | |
| 387 | + * | |
| 388 | + * Each call resets the timer. Only the last call in a burst executes. | |
| 389 | + * | |
| 390 | + * USE CASES: | |
| 391 | + * - Search inputs, form validation, window resize | |
| 392 | + * - Multiple elements need independent timers | |
| 393 | + * - When you need to call with different arguments | |
| 394 | + * | |
| 395 | + * EXAMPLES: | |
| 396 | + * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); | |
| 397 | + * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); | |
| 398 | + * | |
| 399 | + * const debouncedResize = debounce( recalculateLayout, 250 ); | |
| 400 | + * window.addEventListener('resize', debouncedResize); | |
| 401 | + * | |
| 402 | + * ⚠️ Create ONCE outside event handlers, not inside. | |
| 403 | + * | |
| 404 | + * @param {Function} func - Function to debounce (can be anonymous) | |
| 405 | + * @param {number} wait - Milliseconds to wait (default: 500) | |
| 406 | + * @return {Function} Debounced wrapper function | |
| 407 | + * @since 4.3.7 | |
| 408 | + * @version 1.0.0 | |
| 407 | 409 | */ |
| 408 | 410 | const debounce = (func, wait = 500) => { |
| 409 | 411 | let timer; |
| 410 | 412 | return args => { |
| @@ -412,8 +414,141 @@ | ||
| 412 | 414 | timer = setTimeout(() => func(args), wait); |
| 413 | 415 | }; |
| 414 | 416 | }; |
| 415 | 417 | |
| 418 | +/** | |
| 419 | + * Initialize lp-toggle-enable components. | |
| 420 | + * | |
| 421 | + * Finds all `.lp-toggle-enable` elements and wires up toggle behavior. | |
| 422 | + * Reads initial state from `data-enabled` attribute ("true"/"false"). | |
| 423 | + * Calls `data-on-toggle` callback (if provided via options) on state change. | |
| 424 | + * | |
| 425 | + * HTML structure: | |
| 426 | + * <label class="lp-toggle-enable" data-enabled="true"> | |
| 427 | + * <input type="checkbox" class="lp-toggle-enable__input" /> | |
| 428 | + * <span class="lp-toggle-enable__track"></span> | |
| 429 | + * </label> | |
| 430 | + * | |
| 431 | + * @param {string} selector CSS selector for toggle elements (default: '.lp-toggle-enable') | |
| 432 | + * @param {Function} onToggle Optional callback( el, isEnabled ) called on state change | |
| 433 | + * @since 4.4.5 | |
| 434 | + * @version 1.0.0 | |
| 435 | + */ | |
| 436 | +window.lpToggleEnableInit = 0; | |
| 437 | +const toggleEnable = (onToggle = null) => { | |
| 438 | + if (window.lpToggleEnableInit) { | |
| 439 | + return; | |
| 440 | + } | |
| 441 | + window.lpToggleEnableInit = 1; | |
| 442 | + const selector = '.lp-toggle-enable'; | |
| 443 | + const updateUI = (toggle, isEnabled) => { | |
| 444 | + toggle.classList.toggle('is-enabled', isEnabled); | |
| 445 | + const input = toggle.querySelector('.lp-toggle-enable__input'); | |
| 446 | + if (input) { | |
| 447 | + input.checked = isEnabled; | |
| 448 | + input.value = isEnabled ? '1' : '0'; | |
| 449 | + } | |
| 450 | + }; | |
| 451 | + | |
| 452 | + // Delegate click handling via eventHandlers. | |
| 453 | + eventHandlers('click', [{ | |
| 454 | + selector, | |
| 455 | + callBack: args => { | |
| 456 | + const { | |
| 457 | + e, | |
| 458 | + target | |
| 459 | + } = args; | |
| 460 | + const toggle = target.closest(selector); | |
| 461 | + if (!toggle || toggle.classList.contains('is-disabled')) { | |
| 462 | + return; | |
| 463 | + } | |
| 464 | + e.preventDefault(); | |
| 465 | + const isEnabled = !toggle.classList.contains('is-enabled'); | |
| 466 | + updateUI(toggle, isEnabled); | |
| 467 | + if ('function' === typeof onToggle) { | |
| 468 | + onToggle(toggle, isEnabled); | |
| 469 | + } | |
| 470 | + } | |
| 471 | + }]); | |
| 472 | +}; | |
| 473 | + | |
| 474 | +/** | |
| 475 | + * Initialize custom fullscreen view buttons. | |
| 476 | + * | |
| 477 | + * Delegates clicks on `.lp-btn-full-screen-view` buttons to | |
| 478 | + * `lpToggleFullscreenView`. Reads the `data-target` attribute to find the | |
| 479 | + * target element. Falls back to the button's parent element when | |
| 480 | + * `data-target` is not provided. | |
| 481 | + * | |
| 482 | + * @since 4.4.5 | |
| 483 | + * @version 1.0.0 | |
| 484 | + */ | |
| 485 | +window.lpFullScreenViewInit = 0; | |
| 486 | +const fullScreenView = () => { | |
| 487 | + if (window.lpFullScreenViewInit) { | |
| 488 | + return; | |
| 489 | + } | |
| 490 | + window.lpFullScreenViewInit = 1; | |
| 491 | + let lastScrollY = 0; | |
| 492 | + const lpToggleFullscreenView = (elTarget, elBtnFullScreen = null) => { | |
| 493 | + const isFullscreen = elTarget.classList.contains(lpClassName.elFullScreen); | |
| 494 | + if (isFullscreen) { | |
| 495 | + elTarget.classList.remove(lpClassName.elFullScreen); | |
| 496 | + document.documentElement.classList.remove('lp-full-screen-active'); | |
| 497 | + window.scrollTo(0, lastScrollY); | |
| 498 | + } else { | |
| 499 | + lastScrollY = window.scrollY; | |
| 500 | + elTarget.classList.add(lpClassName.elFullScreen); | |
| 501 | + document.documentElement.classList.add('lp-full-screen-active'); | |
| 502 | + } | |
| 503 | + if (!isFullscreen) { | |
| 504 | + if (!elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`)) { | |
| 505 | + const closeButton = document.createElement('button'); | |
| 506 | + closeButton.type = 'button'; | |
| 507 | + closeButton.className = lpClassName.elBtnFullScreenClose; | |
| 508 | + closeButton.setAttribute('aria-label', 'Close'); | |
| 509 | + closeButton.innerHTML = lpData.i18n.closeButtonFullScreen || 'Close ×'; | |
| 510 | + closeButton.addEventListener('click', e => { | |
| 511 | + e.preventDefault(); | |
| 512 | + lpToggleFullscreenView(elTarget); | |
| 513 | + }); | |
| 514 | + elTarget.appendChild(closeButton); | |
| 515 | + } | |
| 516 | + } else { | |
| 517 | + const closeButton = elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`); | |
| 518 | + if (closeButton) { | |
| 519 | + closeButton.remove(); | |
| 520 | + } | |
| 521 | + } | |
| 522 | + }; | |
| 523 | + eventHandlers('click', [{ | |
| 524 | + selector: lpClassName.elBtnFullScreen, | |
| 525 | + callBack: args => { | |
| 526 | + const { | |
| 527 | + e, | |
| 528 | + target | |
| 529 | + } = args; | |
| 530 | + const elBtnFullScreen = target.closest(lpClassName.elBtnFullScreen); | |
| 531 | + if (!elBtnFullScreen) { | |
| 532 | + console.log('No full screen button found'); | |
| 533 | + return; | |
| 534 | + } | |
| 535 | + e.preventDefault(); | |
| 536 | + let elTarget = null; | |
| 537 | + const targetSelector = elBtnFullScreen.dataset.targetFullscreen; | |
| 538 | + console.log(targetSelector); | |
| 539 | + if (targetSelector) { | |
| 540 | + elTarget = document.querySelector(targetSelector); | |
| 541 | + } | |
| 542 | + if (!elTarget) { | |
| 543 | + console.log('No target element found'); | |
| 544 | + return; | |
| 545 | + } | |
| 546 | + lpToggleFullscreenView(elTarget, elBtnFullScreen); | |
| 547 | + } | |
| 548 | + }]); | |
| 549 | +}; | |
| 550 | + | |
| 416 | 551 | /***/ }, |
| 417 | 552 | |
| 418 | 553 | /***/ "./assets/src/js/utils/cookies.js" |
| 419 | 554 | /*!****************************************!*\ |
| @@ -550,12 +685,12 @@ | ||
| 550 | 685 | __webpack_require__.r(__webpack_exports__); |
| 551 | 686 | /* harmony import */ var _api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../api */ "./assets/src/js/api.js"); |
| 552 | 687 | /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils */ "./assets/src/js/utils.js"); |
| 553 | 688 | /* harmony import */ var _utils_cookies__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/cookies */ "./assets/src/js/utils/cookies.js"); |
| 554 | -/** | |
| 555 | - * @deprecated 4.2.5.8 | |
| 556 | - * But still support for theme has html old, override. | |
| 557 | - * Todo: if want remove file, need to check theme override file archive, can via remove hook override file. | |
| 689 | +/** | |
| 690 | + * @deprecated 4.2.5.8 | |
| 691 | + * But still support for theme has html old, override. | |
| 692 | + * Todo: if want remove file, need to check theme override file archive, can via remove hook override file. | |
| 558 | 693 | */ |
| 559 | 694 | |
| 560 | 695 | |
| 561 | 696 | |
| @@ -863,56 +998,56 @@ | ||
| 863 | 998 | elListCourse.closest(`.${classArchiveCourse}`).scrollIntoView(optionScroll); |
| 864 | 999 | } |
| 865 | 1000 | }; |
| 866 | 1001 | }, |
| 867 | - /*callBackPaginationTypeNumber: ( elListCourse ) => { | |
| 868 | - if ( ! elListCourse ) { | |
| 869 | - return; | |
| 870 | - } | |
| 871 | - const skeleton = elListCourse.querySelector( `.${ classSkeletonArchiveCourse }` ); | |
| 872 | - return { | |
| 873 | - before: () => { | |
| 874 | - const urlPush = lpAddQueryArgs( currentUrl, args ); | |
| 875 | - window.history.pushState( '', '', urlPush ); | |
| 876 | - // Save filter courses to Storage | |
| 877 | - window.localStorage.setItem( 'lp_filter_courses', JSON.stringify( args ) ); | |
| 878 | - if ( skeleton ) { | |
| 879 | - skeleton.style.display = 'block'; | |
| 880 | - } | |
| 881 | - }, | |
| 882 | - success: ( res ) => { | |
| 883 | - // Remove all items before insert new items. | |
| 884 | - const elLis = elListCourse.querySelectorAll( `:not(.${ classSkeletonArchiveCourse })` ); | |
| 885 | - elLis.forEach( ( elLi ) => { | |
| 886 | - const parent = elLi.closest( `.${ classSkeletonArchiveCourse }` ); | |
| 887 | - if ( parent ) { | |
| 888 | - return; | |
| 889 | - } | |
| 890 | - elLi.remove(); | |
| 891 | - } ); | |
| 892 | - // Insert new items. | |
| 893 | - elListCourse.insertAdjacentHTML( 'afterbegin', res.data.content || '' ); | |
| 894 | - // Check if Pagination exists will remove. | |
| 895 | - const elPagination = document.querySelector( `.${ classPaginationCourse }` ); | |
| 896 | - if ( elPagination ) { | |
| 897 | - elPagination.remove(); | |
| 898 | - } | |
| 899 | - // Insert Pagination. | |
| 900 | - const pagination = res.data.pagination || ''; | |
| 901 | - elListCourse.insertAdjacentHTML( 'afterend', pagination ); | |
| 902 | - }, | |
| 903 | - error: ( error ) => { | |
| 904 | - elListCourse.innerHTML += `<div class="lp-ajax-message error" style="display:block">${ error.message || 'Error' }</div>`; | |
| 905 | - }, | |
| 906 | - completed: () => { | |
| 907 | - if ( skeleton ) { | |
| 908 | - skeleton.style.display = 'none'; | |
| 909 | - } | |
| 910 | - // Scroll to archive element | |
| 911 | - const optionScroll = { behavior: 'smooth' }; | |
| 912 | - elListCourse.closest( '.lp-archive-courses' ).scrollIntoView( optionScroll ); | |
| 913 | - }, | |
| 914 | - }; | |
| 1002 | + /*callBackPaginationTypeNumber: ( elListCourse ) => { | |
| 1003 | + if ( ! elListCourse ) { | |
| 1004 | + return; | |
| 1005 | + } | |
| 1006 | + const skeleton = elListCourse.querySelector( `.${ classSkeletonArchiveCourse }` ); | |
| 1007 | + return { | |
| 1008 | + before: () => { | |
| 1009 | + const urlPush = lpAddQueryArgs( currentUrl, args ); | |
| 1010 | + window.history.pushState( '', '', urlPush ); | |
| 1011 | + // Save filter courses to Storage | |
| 1012 | + window.localStorage.setItem( 'lp_filter_courses', JSON.stringify( args ) ); | |
| 1013 | + if ( skeleton ) { | |
| 1014 | + skeleton.style.display = 'block'; | |
| 1015 | + } | |
| 1016 | + }, | |
| 1017 | + success: ( res ) => { | |
| 1018 | + // Remove all items before insert new items. | |
| 1019 | + const elLis = elListCourse.querySelectorAll( `:not(.${ classSkeletonArchiveCourse })` ); | |
| 1020 | + elLis.forEach( ( elLi ) => { | |
| 1021 | + const parent = elLi.closest( `.${ classSkeletonArchiveCourse }` ); | |
| 1022 | + if ( parent ) { | |
| 1023 | + return; | |
| 1024 | + } | |
| 1025 | + elLi.remove(); | |
| 1026 | + } ); | |
| 1027 | + // Insert new items. | |
| 1028 | + elListCourse.insertAdjacentHTML( 'afterbegin', res.data.content || '' ); | |
| 1029 | + // Check if Pagination exists will remove. | |
| 1030 | + const elPagination = document.querySelector( `.${ classPaginationCourse }` ); | |
| 1031 | + if ( elPagination ) { | |
| 1032 | + elPagination.remove(); | |
| 1033 | + } | |
| 1034 | + // Insert Pagination. | |
| 1035 | + const pagination = res.data.pagination || ''; | |
| 1036 | + elListCourse.insertAdjacentHTML( 'afterend', pagination ); | |
| 1037 | + }, | |
| 1038 | + error: ( error ) => { | |
| 1039 | + elListCourse.innerHTML += `<div class="lp-ajax-message error" style="display:block">${ error.message || 'Error' }</div>`; | |
| 1040 | + }, | |
| 1041 | + completed: () => { | |
| 1042 | + if ( skeleton ) { | |
| 1043 | + skeleton.style.display = 'none'; | |
| 1044 | + } | |
| 1045 | + // Scroll to archive element | |
| 1046 | + const optionScroll = { behavior: 'smooth' }; | |
| 1047 | + elListCourse.closest( '.lp-archive-courses' ).scrollIntoView( optionScroll ); | |
| 1048 | + }, | |
| 1049 | + }; | |
| 915 | 1050 | },*/ |
| 916 | 1051 | callBackPaginationTypeLoadMore: (elArchive, elListCourse) => { |
| 917 | 1052 | //console.log( 'callBackPaginationTypeLoadMore' ); |
| 918 | 1053 | if (!elListCourse || !elArchive) { |
| @@ -931,10 +1066,10 @@ | ||
| 931 | 1066 | elLoading.classList.remove('hide'); |
| 932 | 1067 | btnLoadMore.setAttribute('disabled', 'disabled'); |
| 933 | 1068 | } |
| 934 | 1069 | |
| 935 | - /*if ( skeleton ) { | |
| 936 | - skeleton.style.display = 'block'; | |
| 1070 | + /*if ( skeleton ) { | |
| 1071 | + skeleton.style.display = 'block'; | |
| 937 | 1072 | }*/ |
| 938 | 1073 | }, |
| 939 | 1074 | success: res => { |
| 940 | 1075 | elListCourse.insertAdjacentHTML('beforeend', res.data.content || ''); |
| @@ -954,10 +1089,10 @@ | ||
| 954 | 1089 | elLoading.classList.add('hide'); |
| 955 | 1090 | btnLoadMore.remove(); |
| 956 | 1091 | } |
| 957 | 1092 | |
| 958 | - /*if ( skeleton ) { | |
| 959 | - skeleton.style.display = 'none'; | |
| 1093 | + /*if ( skeleton ) { | |
| 1094 | + skeleton.style.display = 'none'; | |
| 960 | 1095 | }*/ |
| 961 | 1096 | } |
| 962 | 1097 | }; |
| 963 | 1098 | }, |