PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9.1
4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 All 141 releases
← All changes | assets/js/dist/loadAJAX.js +213 -36 4.4.2 → 4.4.9.1 View file →
@@ -11,8 +11,9 @@
11 11 __webpack_require__.r(__webpack_exports__);
12 12 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
13 13 /* harmony export */ debounce: () => (/* binding */ debounce),
14 14 /* harmony export */ eventHandlers: () => (/* binding */ eventHandlers),
15 +/* harmony export */ fullScreenView: () => (/* binding */ fullScreenView),
15 16 /* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm),
16 17 /* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm),
17 18 /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated),
18 19 /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed),
@@ -24,9 +25,10 @@
24 25 /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady),
25 26 /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl),
26 27 /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl),
27 28 /* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm),
28 -/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse)
29 +/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse),
30 +/* harmony export */ toggleEnable: () => (/* binding */ toggleEnable)
29 31 /* harmony export */ });
30 32 /**
31 33 * Utils functions
32 34 *
@@ -33,9 +35,9 @@
33 35 * @param url
34 36 * @param data
35 37 * @param functions
36 38 * @since 4.2.5.1
37 - * @version 1.0.6
39 + * @version 1.0.7
38 40 */
39 41 const lpClassName = {
40 42 hidden: 'lp-hidden',
41 43 loading: 'loading',
@@ -40,9 +42,12 @@
40 42 hidden: 'lp-hidden',
41 43 loading: 'loading',
42 44 elCollapse: 'lp-collapse',
43 45 elSectionToggle: '.lp-section-toggle',
44 - elTriggerToggle: '.lp-trigger-toggle'
46 + elTriggerToggle: '.lp-trigger-toggle',
47 + elBtnFullScreen: '.lp-btn-full-screen-view',
48 + elFullScreen: 'lp-full-screen-view',
49 + elBtnFullScreenClose: 'lp-full-screen-view__close'
45 50 };
46 51 const lpFetchAPI = (url, data = {}, functions = {}) => {
47 52 if ('function' === typeof functions.before) {
48 53 functions.before();
@@ -360,24 +365,157 @@
360 365 timer = setTimeout(() => func(args), wait);
361 366 };
362 367 };
363 368
369 +/**
370 + * Initialize lp-toggle-enable components.
371 + *
372 + * Finds all `.lp-toggle-enable` elements and wires up toggle behavior.
373 + * Reads initial state from `data-enabled` attribute ("true"/"false").
374 + * Calls `data-on-toggle` callback (if provided via options) on state change.
375 + *
376 + * HTML structure:
377 + * <label class="lp-toggle-enable" data-enabled="true">
378 + * <input type="checkbox" class="lp-toggle-enable__input" />
379 + * <span class="lp-toggle-enable__track"></span>
380 + * </label>
381 + *
382 + * @param {string} selector CSS selector for toggle elements (default: '.lp-toggle-enable')
383 + * @param {Function} onToggle Optional callback( el, isEnabled ) called on state change
384 + * @since 4.4.5
385 + * @version 1.0.0
386 + */
387 +window.lpToggleEnableInit = 0;
388 +const toggleEnable = (onToggle = null) => {
389 + if (window.lpToggleEnableInit) {
390 + return;
391 + }
392 + window.lpToggleEnableInit = 1;
393 + const selector = '.lp-toggle-enable';
394 + const updateUI = (toggle, isEnabled) => {
395 + toggle.classList.toggle('is-enabled', isEnabled);
396 + const input = toggle.querySelector('.lp-toggle-enable__input');
397 + if (input) {
398 + input.checked = isEnabled;
399 + input.value = isEnabled ? '1' : '0';
400 + }
401 + };
402 +
403 + // Delegate click handling via eventHandlers.
404 + eventHandlers('click', [{
405 + selector,
406 + callBack: args => {
407 + const {
408 + e,
409 + target
410 + } = args;
411 + const toggle = target.closest(selector);
412 + if (!toggle || toggle.classList.contains('is-disabled')) {
413 + return;
414 + }
415 + e.preventDefault();
416 + const isEnabled = !toggle.classList.contains('is-enabled');
417 + updateUI(toggle, isEnabled);
418 + if ('function' === typeof onToggle) {
419 + onToggle(toggle, isEnabled);
420 + }
421 + }
422 + }]);
423 +};
424 +
425 +/**
426 + * Initialize custom fullscreen view buttons.
427 + *
428 + * Delegates clicks on `.lp-btn-full-screen-view` buttons to
429 + * `lpToggleFullscreenView`. Reads the `data-target` attribute to find the
430 + * target element. Falls back to the button's parent element when
431 + * `data-target` is not provided.
432 + *
433 + * @since 4.4.5
434 + * @version 1.0.0
435 + */
436 +window.lpFullScreenViewInit = 0;
437 +const fullScreenView = () => {
438 + if (window.lpFullScreenViewInit) {
439 + return;
440 + }
441 + window.lpFullScreenViewInit = 1;
442 + let lastScrollY = 0;
443 + const lpToggleFullscreenView = (elTarget, elBtnFullScreen = null) => {
444 + const isFullscreen = elTarget.classList.contains(lpClassName.elFullScreen);
445 + if (isFullscreen) {
446 + elTarget.classList.remove(lpClassName.elFullScreen);
447 + document.documentElement.classList.remove('lp-full-screen-active');
448 + window.scrollTo(0, lastScrollY);
449 + } else {
450 + lastScrollY = window.scrollY;
451 + elTarget.classList.add(lpClassName.elFullScreen);
452 + document.documentElement.classList.add('lp-full-screen-active');
453 + }
454 + if (!isFullscreen) {
455 + if (!elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`)) {
456 + const closeButton = document.createElement('button');
457 + closeButton.type = 'button';
458 + closeButton.className = lpClassName.elBtnFullScreenClose;
459 + closeButton.setAttribute('aria-label', 'Close');
460 + closeButton.innerHTML = lpData.i18n.closeButtonFullScreen || 'Close &times;';
461 + closeButton.addEventListener('click', e => {
462 + e.preventDefault();
463 + lpToggleFullscreenView(elTarget);
464 + });
465 + elTarget.appendChild(closeButton);
466 + }
467 + } else {
468 + const closeButton = elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`);
469 + if (closeButton) {
470 + closeButton.remove();
471 + }
472 + }
473 + };
474 + eventHandlers('click', [{
475 + selector: lpClassName.elBtnFullScreen,
476 + callBack: args => {
477 + const {
478 + e,
479 + target
480 + } = args;
481 + const elBtnFullScreen = target.closest(lpClassName.elBtnFullScreen);
482 + if (!elBtnFullScreen) {
483 + console.log('No full screen button found');
484 + return;
485 + }
486 + e.preventDefault();
487 + let elTarget = null;
488 + const targetSelector = elBtnFullScreen.dataset.targetFullscreen;
489 + console.log(targetSelector);
490 + if (targetSelector) {
491 + elTarget = document.querySelector(targetSelector);
492 + }
493 + if (!elTarget) {
494 + console.log('No target element found');
495 + return;
496 + }
497 + lpToggleFullscreenView(elTarget, elBtnFullScreen);
498 + }
499 + }]);
500 +};
501 +
364 502 /***/ }
365 503
366 504 /******/ });
367 505 /************************************************************************/
368 506 /******/ // The module cache
369 -/******/ var __webpack_module_cache__ = {};
507 +/******/ const __webpack_module_cache__ = {};
370 508 /******/
371 509 /******/ // The require function
372 510 /******/ function __webpack_require__(moduleId) {
373 511 /******/ // Check if module is in cache
374 -/******/ var cachedModule = __webpack_module_cache__[moduleId];
512 +/******/ const cachedModule = __webpack_module_cache__[moduleId];
375 513 /******/ if (cachedModule !== undefined) {
376 514 /******/ return cachedModule.exports;
377 515 /******/ }
378 516 /******/ // Create a new module (and put it into the cache)
379 -/******/ var module = __webpack_module_cache__[moduleId] = {
517 +/******/ const module = __webpack_module_cache__[moduleId] = {
380 518 /******/ // no module.id needed
381 519 /******/ // no module.loaded needed
382 520 /******/ exports: {}
383 521 /******/ };
@@ -384,9 +522,9 @@
384 522 /******/
385 523 /******/ // Execute the module function
386 524 /******/ if (!(moduleId in __webpack_modules__)) {
387 525 /******/ delete __webpack_module_cache__[moduleId];
388 -/******/ var e = new Error("Cannot find module '" + moduleId + "'");
526 +/******/ const e = new Error("Cannot find module '" + moduleId + "'");
389 527 /******/ e.code = 'MODULE_NOT_FOUND';
390 528 /******/ throw e;
391 529 /******/ }
392 530 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
@@ -397,14 +535,29 @@
397 535 /******/
398 536 /************************************************************************/
399 537 /******/ /* webpack/runtime/define property getters */
400 538 /******/ (() => {
401 -/******/ // define getter functions for harmony exports
539 +/******/ // define getter/value functions for harmony exports
402 540 /******/ __webpack_require__.d = (exports, definition) => {
403 -/******/ for(var key in definition) {
404 -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
405 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
541 +/******/ if(Array.isArray(definition)) {
542 +/******/ var i = 0;
543 +/******/ while(i < definition.length) {
544 +/******/ var key = definition[i++];
545 +/******/ var binding = definition[i++];
546 +/******/ if(!__webpack_require__.o(exports, key)) {
547 +/******/ if(binding === 0) {
548 +/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
549 +/******/ } else {
550 +/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
551 +/******/ }
552 +/******/ } else if(binding === 0) { i++; }
406 553 /******/ }
554 +/******/ } else {
555 +/******/ for(var key in definition) {
556 +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
557 +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
558 +/******/ }
559 +/******/ }
407 560 /******/ }
408 561 /******/ };
409 562 /******/ })();
410 563 /******/
@@ -409,9 +562,9 @@
409 562 /******/ })();
410 563 /******/
411 564 /******/ /* webpack/runtime/hasOwnProperty shorthand */
412 565 /******/ (() => {
413 -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
566 +/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
414 567 /******/ })();
415 568 /******/
416 569 /******/ /* webpack/runtime/make namespace object */
417 570 /******/ (() => {
@@ -416,9 +569,9 @@
416 569 /******/ /* webpack/runtime/make namespace object */
417 570 /******/ (() => {
418 571 /******/ // define __esModule on exports
419 572 /******/ __webpack_require__.r = (exports) => {
420 -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
573 +/******/ if(Symbol.toStringTag) {
421 574 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
422 575 /******/ }
423 576 /******/ Object.defineProperty(exports, '__esModule', { value: true });
424 577 /******/ };
@@ -424,9 +577,9 @@
424 577 /******/ };
425 578 /******/ })();
426 579 /******/
427 580 /************************************************************************/
428 -var __webpack_exports__ = {};
581 +let __webpack_exports__ = {};
429 582 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
430 583 (() => {
431 584 /*!***********************************!*\
432 585 !*** ./assets/src/js/loadAJAX.js ***!
@@ -434,14 +587,14 @@
434 587 __webpack_require__.r(__webpack_exports__);
435 588 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
436 589 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
437 590 /* harmony export */ });
438 -/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./assets/src/js/utils.js");
591 +/* harmony import */ var lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lpAssetsJsPath/utils.js */ "./assets/src/js/utils.js");
439 592 /**
440 593 * Load all you need via AJAX
441 594 *
442 595 * @since 4.2.5.7
443 - * @version 1.1.0
596 + * @version 1.1.1
444 597 */
445 598
446 599
447 600
@@ -455,9 +608,9 @@
455 608 // End Handle general parameter in the Frontend and Backend
456 609
457 610 const lpAJAX = () => {
458 611 const classLPTarget = '.lp-target';
459 - const urlCurrent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam)();
612 + const urlCurrent = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam();
460 613 return {
461 614 autoLoadAPIs: () => {
462 615 console.log('autoLoadAPIs');
463 616 },
@@ -481,11 +634,11 @@
481 634 option.headers['Content-Type'] = 'application/json';
482 635 } else {
483 636 params.args = JSON.stringify(params.args);
484 637 params.callback = JSON.stringify(params.callback);
485 - url = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(url, params);
638 + url = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(url, params);
486 639 }
487 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(url, option, callBack);
640 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(url, option, callBack);
488 641 },
489 642 fetchAJAX: (params, callBack) => {
490 643 let urlAjax = lpSettings.lpAjaxUrl;
491 644
@@ -490,36 +643,55 @@
490 643 let urlAjax = lpSettings.lpAjaxUrl;
491 644
492 645 // Set param id_url for identify.
493 646 if (params.hasOwnProperty('args') && params.args.hasOwnProperty('id_url')) {
494 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
647 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
495 648 id_url: params.args.id_url
496 649 });
497 650 } else if (params.hasOwnProperty('id_url')) {
498 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
651 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
499 652 id_url: params.id_url
500 653 });
501 654 }
502 655 // Set param lang here if exits, for detect translate
503 656 if (lpSettings.urlParams.hasOwnProperty('lang')) {
504 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
657 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
505 658 lang: lpSettings.urlParams.lang
506 659 });
507 660 }
508 - const formData = new FormData();
509 661 const action = params.hasOwnProperty('action') ? params.action : 'load_content_via_ajax';
510 - formData.append('nonce', lpSettings.nonce);
511 - formData.append('lp-load-ajax', action);
512 - formData.append('data', JSON.stringify(params));
513 - const dataSend = {
514 - method: 'POST',
515 - headers: {},
516 - body: formData
517 - };
662 + const isGet = params.hasOwnProperty('method_request') && 'GET' === String(params.method_request).toUpperCase();
663 + let dataSend;
664 + if (isGet) {
665 + // Don't send method_request back to server; keep URL shorter.
666 + const paramsForSend = {
667 + ...params
668 + };
669 + delete paramsForSend.method_request;
670 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
671 + nonce: lpSettings.nonce,
672 + 'lp-load-ajax': action,
673 + data: JSON.stringify(paramsForSend)
674 + });
675 + dataSend = {
676 + method: 'GET',
677 + headers: {}
678 + };
679 + } else {
680 + const formData = new FormData();
681 + formData.append('nonce', lpSettings.nonce);
682 + formData.append('lp-load-ajax', action);
683 + formData.append('data', JSON.stringify(params));
684 + dataSend = {
685 + method: 'POST',
686 + headers: {},
687 + body: formData
688 + };
689 + }
518 690 if (0 !== parseInt(lpSettings.user_id)) {
519 691 dataSend.headers['X-WP-Nonce'] = lpSettings.nonce;
520 692 }
521 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(urlAjax, dataSend, callBack);
693 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(urlAjax, dataSend, callBack);
522 694 },
523 695 getElements: () => {
524 696 // Finds all elements with the class '.lp-load-ajax-element'
525 697 const elements = document.querySelectorAll('.lp-load-ajax-element:not(.loaded)');
@@ -574,8 +746,13 @@
574 746 const btnNumber = target.closest('.page-numbers:not(.disabled)');
575 747 if (!btnNumber) {
576 748 return;
577 749 }
750 +
751 + // Check btnNumber is tag a
752 + if (btnNumber.tagName.toLowerCase() !== 'a') {
753 + return;
754 + }
578 755 const elLPTarget = btnNumber.closest(`${classLPTarget}`);
579 756 if (!elLPTarget) {
580 757 return;
581 758 }
@@ -602,9 +779,9 @@
602 779
603 780 // Set url params to reload page.
604 781 if (!dataSend.args.hasOwnProperty('enableUpdateParamsUrl') || dataSend.args.enableUpdateParamsUrl) {
605 782 lpSettings.urlParams.paged = dataSend.args.paged;
606 - window.history.pushState({}, '', (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlCurrent, lpSettings.urlParams));
783 + window.history.pushState({}, '', lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlCurrent, lpSettings.urlParams));
607 784 }
608 785 // End.
609 786
610 787 // Show loading
@@ -646,9 +823,9 @@
646 823 },
647 824 showHideLoading: (elLPTarget, status) => {
648 825 const elLoading = elLPTarget.nextElementSibling?.querySelector('.lp-loading-change');
649 826 if (elLoading) {
650 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elLoading, status);
827 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl(elLoading, status);
651 828 }
652 829 }
653 830 };
654 831 };
@@ -661,9 +838,9 @@
661 838 window.lpAJAXG.clickNumberPage(e, target);
662 839 });
663 840
664 841 // Listen element created
665 -(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated)(node => {
842 +lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated(node => {
666 843 if (node.classList.contains('lp-load-ajax-element')) {
667 844 //console.log( 'Element created', node );
668 845 window.lpAJAXG.getElements();
669 846 }
@@ -669,9 +846,9 @@
669 846 }
670 847 });
671 848
672 849 // Listen element ready
673 -(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady)('.lp-load-ajax-element', element => {
850 +lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady('.lp-load-ajax-element', element => {
674 851 //console.log( 'Element ready', element );
675 852 window.lpAJAXG.getElements();
676 853 });
677 854