PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
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 4.1.7.3.2 All 140 releases
← All changes | assets/js/dist/loadAJAX.js +198 -51 4.4.1 → 4.4.9 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 -/******/ const __webpack_module_cache__ = {};
507 +/******/ var __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 -/******/ const cachedModule = __webpack_module_cache__[moduleId];
512 +/******/ var 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 -/******/ const module = __webpack_module_cache__[moduleId] = {
517 +/******/ var 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 -/******/ const e = new Error("Cannot find module '" + moduleId + "'");
526 +/******/ var 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,29 +535,14 @@
397 535 /******/
398 536 /************************************************************************/
399 537 /******/ /* webpack/runtime/define property getters */
400 538 /******/ (() => {
401 -/******/ // define getter/value functions for harmony exports
539 +/******/ // define getter functions for harmony exports
402 540 /******/ __webpack_require__.d = (exports, definition) => {
403 -/******/ if(Array.isArray(definition)) {
404 -/******/ var i = 0;
405 -/******/ while(i < definition.length) {
406 -/******/ var key = definition[i++];
407 -/******/ var binding = definition[i++];
408 -/******/ if(!__webpack_require__.o(exports, key)) {
409 -/******/ if(binding === 0) {
410 -/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
411 -/******/ } else {
412 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
413 -/******/ }
414 -/******/ } else if(binding === 0) { i++; }
541 +/******/ for(var key in definition) {
542 +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
543 +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
415 544 /******/ }
416 -/******/ } else {
417 -/******/ for(var key in definition) {
418 -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
419 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
420 -/******/ }
421 -/******/ }
422 545 /******/ }
423 546 /******/ };
424 547 /******/ })();
425 548 /******/
@@ -424,9 +547,9 @@
424 547 /******/ })();
425 548 /******/
426 549 /******/ /* webpack/runtime/hasOwnProperty shorthand */
427 550 /******/ (() => {
428 -/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
551 +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
429 552 /******/ })();
430 553 /******/
431 554 /******/ /* webpack/runtime/make namespace object */
432 555 /******/ (() => {
@@ -431,9 +554,9 @@
431 554 /******/ /* webpack/runtime/make namespace object */
432 555 /******/ (() => {
433 556 /******/ // define __esModule on exports
434 557 /******/ __webpack_require__.r = (exports) => {
435 -/******/ if(Symbol.toStringTag) {
558 +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
436 559 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
437 560 /******/ }
438 561 /******/ Object.defineProperty(exports, '__esModule', { value: true });
439 562 /******/ };
@@ -439,9 +562,9 @@
439 562 /******/ };
440 563 /******/ })();
441 564 /******/
442 565 /************************************************************************/
443 -let __webpack_exports__ = {};
566 +var __webpack_exports__ = {};
444 567 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
445 568 (() => {
446 569 /*!***********************************!*\
447 570 !*** ./assets/src/js/loadAJAX.js ***!
@@ -449,14 +572,14 @@
449 572 __webpack_require__.r(__webpack_exports__);
450 573 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
451 574 /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
452 575 /* harmony export */ });
453 -/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./assets/src/js/utils.js");
576 +/* harmony import */ var lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lpAssetsJsPath/utils.js */ "./assets/src/js/utils.js");
454 577 /**
455 578 * Load all you need via AJAX
456 579 *
457 580 * @since 4.2.5.7
458 - * @version 1.1.0
581 + * @version 1.1.1
459 582 */
460 583
461 584
462 585
@@ -470,9 +593,9 @@
470 593 // End Handle general parameter in the Frontend and Backend
471 594
472 595 const lpAJAX = () => {
473 596 const classLPTarget = '.lp-target';
474 - const urlCurrent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam)();
597 + const urlCurrent = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam();
475 598 return {
476 599 autoLoadAPIs: () => {
477 600 console.log('autoLoadAPIs');
478 601 },
@@ -496,11 +619,11 @@
496 619 option.headers['Content-Type'] = 'application/json';
497 620 } else {
498 621 params.args = JSON.stringify(params.args);
499 622 params.callback = JSON.stringify(params.callback);
500 - url = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(url, params);
623 + url = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(url, params);
501 624 }
502 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(url, option, callBack);
625 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(url, option, callBack);
503 626 },
504 627 fetchAJAX: (params, callBack) => {
505 628 let urlAjax = lpSettings.lpAjaxUrl;
506 629
@@ -505,36 +628,55 @@
505 628 let urlAjax = lpSettings.lpAjaxUrl;
506 629
507 630 // Set param id_url for identify.
508 631 if (params.hasOwnProperty('args') && params.args.hasOwnProperty('id_url')) {
509 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
632 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
510 633 id_url: params.args.id_url
511 634 });
512 635 } else if (params.hasOwnProperty('id_url')) {
513 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
636 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
514 637 id_url: params.id_url
515 638 });
516 639 }
517 640 // Set param lang here if exits, for detect translate
518 641 if (lpSettings.urlParams.hasOwnProperty('lang')) {
519 - urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
642 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
520 643 lang: lpSettings.urlParams.lang
521 644 });
522 645 }
523 - const formData = new FormData();
524 646 const action = params.hasOwnProperty('action') ? params.action : 'load_content_via_ajax';
525 - formData.append('nonce', lpSettings.nonce);
526 - formData.append('lp-load-ajax', action);
527 - formData.append('data', JSON.stringify(params));
528 - const dataSend = {
529 - method: 'POST',
530 - headers: {},
531 - body: formData
532 - };
647 + const isGet = params.hasOwnProperty('method_request') && 'GET' === String(params.method_request).toUpperCase();
648 + let dataSend;
649 + if (isGet) {
650 + // Don't send method_request back to server; keep URL shorter.
651 + const paramsForSend = {
652 + ...params
653 + };
654 + delete paramsForSend.method_request;
655 + urlAjax = lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlAjax, {
656 + nonce: lpSettings.nonce,
657 + 'lp-load-ajax': action,
658 + data: JSON.stringify(paramsForSend)
659 + });
660 + dataSend = {
661 + method: 'GET',
662 + headers: {}
663 + };
664 + } else {
665 + const formData = new FormData();
666 + formData.append('nonce', lpSettings.nonce);
667 + formData.append('lp-load-ajax', action);
668 + formData.append('data', JSON.stringify(params));
669 + dataSend = {
670 + method: 'POST',
671 + headers: {},
672 + body: formData
673 + };
674 + }
533 675 if (0 !== parseInt(lpSettings.user_id)) {
534 676 dataSend.headers['X-WP-Nonce'] = lpSettings.nonce;
535 677 }
536 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(urlAjax, dataSend, callBack);
678 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI(urlAjax, dataSend, callBack);
537 679 },
538 680 getElements: () => {
539 681 // Finds all elements with the class '.lp-load-ajax-element'
540 682 const elements = document.querySelectorAll('.lp-load-ajax-element:not(.loaded)');
@@ -589,8 +731,13 @@
589 731 const btnNumber = target.closest('.page-numbers:not(.disabled)');
590 732 if (!btnNumber) {
591 733 return;
592 734 }
735 +
736 + // Check btnNumber is tag a
737 + if (btnNumber.tagName.toLowerCase() !== 'a') {
738 + return;
739 + }
593 740 const elLPTarget = btnNumber.closest(`${classLPTarget}`);
594 741 if (!elLPTarget) {
595 742 return;
596 743 }
@@ -617,9 +764,9 @@
617 764
618 765 // Set url params to reload page.
619 766 if (!dataSend.args.hasOwnProperty('enableUpdateParamsUrl') || dataSend.args.enableUpdateParamsUrl) {
620 767 lpSettings.urlParams.paged = dataSend.args.paged;
621 - window.history.pushState({}, '', (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlCurrent, lpSettings.urlParams));
768 + window.history.pushState({}, '', lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs(urlCurrent, lpSettings.urlParams));
622 769 }
623 770 // End.
624 771
625 772 // Show loading
@@ -661,9 +808,9 @@
661 808 },
662 809 showHideLoading: (elLPTarget, status) => {
663 810 const elLoading = elLPTarget.nextElementSibling?.querySelector('.lp-loading-change');
664 811 if (elLoading) {
665 - (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elLoading, status);
812 + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl(elLoading, status);
666 813 }
667 814 }
668 815 };
669 816 };
@@ -676,9 +823,9 @@
676 823 window.lpAJAXG.clickNumberPage(e, target);
677 824 });
678 825
679 826 // Listen element created
680 -(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated)(node => {
827 +lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated(node => {
681 828 if (node.classList.contains('lp-load-ajax-element')) {
682 829 //console.log( 'Element created', node );
683 830 window.lpAJAXG.getElements();
684 831 }
@@ -684,9 +831,9 @@
684 831 }
685 832 });
686 833
687 834 // Listen element ready
688 -(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady)('.lp-load-ajax-element', element => {
835 +lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady('.lp-load-ajax-element', element => {
689 836 //console.log( 'Element ready', element );
690 837 window.lpAJAXG.getElements();
691 838 });
692 839