/******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./assets/src/js/utils.js" /*!********************************!*\ !*** ./assets/src/js/utils.js ***! \********************************/ (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ debounce: () => (/* binding */ debounce), /* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), /* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), /* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), /* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs), /* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld), /* harmony export */ lpClassName: () => (/* binding */ lpClassName), /* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI), /* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam), /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), /* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), /* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) /* harmony export */ }); /** * Utils functions * * @param url * @param data * @param functions * @since 4.2.5.1 * @version 1.0.6 */ const lpClassName = { hidden: 'lp-hidden', loading: 'loading', elCollapse: 'lp-collapse', elSectionToggle: '.lp-section-toggle', elTriggerToggle: '.lp-trigger-toggle' }; const lpFetchAPI = (url, data = {}, functions = {}) => { if ('function' === typeof functions.before) { functions.before(); } fetch(url, { method: 'GET', ...data }).then(response => response.json()).then(response => { if ('function' === typeof functions.success) { functions.success(response); } }).catch(err => { if ('function' === typeof functions.error) { functions.error(err); } }).finally(() => { if ('function' === typeof functions.completed) { functions.completed(); } }); }; /** * Get current URL without params. * * @since 4.2.5.1 */ const lpGetCurrentURLNoParam = () => { let currentUrl = window.location.href; const hasParams = currentUrl.includes('?'); if (hasParams) { currentUrl = currentUrl.split('?')[0]; } return currentUrl; }; const lpAddQueryArgs = (endpoint, args) => { const url = new URL(endpoint); Object.keys(args).forEach(arg => { url.searchParams.set(arg, args[arg]); }); return url; }; /** * Listen element viewed. * * @param el * @param callback * @since 4.2.5.8 */ const listenElementViewed = (el, callback) => { const observerSeeItem = new IntersectionObserver(function (entries) { for (const entry of entries) { if (entry.isIntersecting) { callback(entry); } } }); observerSeeItem.observe(el); }; /** * Listen element created. * * @param callback * @since 4.2.5.8 */ const listenElementCreated = callback => { const observerCreateItem = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.addedNodes) { mutation.addedNodes.forEach(function (node) { if (node.nodeType === 1) { callback(node); } }); } }); }); observerCreateItem.observe(document, { childList: true, subtree: true }); // End. }; /** * Listen element created. * * @param selector * @param callback * @since 4.2.7.1 */ const lpOnElementReady = (selector, callback) => { const element = document.querySelector(selector); if (element) { callback(element); return; } const observer = new MutationObserver((mutations, obs) => { const element = document.querySelector(selector); if (element) { obs.disconnect(); callback(element); } }); observer.observe(document.documentElement, { childList: true, subtree: true }); }; // Parse JSON from string with content include LP_AJAX_START. const lpAjaxParseJsonOld = data => { if (typeof data !== 'string') { return data; } const m = String.raw({ raw: data }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s); try { if (m) { data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, '')); } else { data = JSON.parse(data); } } catch (e) { data = {}; } return data; }; // status 0: hide, 1: show const lpShowHideEl = (el, status = 0) => { if (!el) { return; } if (!status) { el.classList.add(lpClassName.hidden); } else { el.classList.remove(lpClassName.hidden); } }; // status 0: hide, 1: show const lpSetLoadingEl = (el, status) => { if (!el) { return; } if (!status) { el.classList.remove(lpClassName.loading); } else { el.classList.add(lpClassName.loading); } }; // Toggle collapse section const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => { if (!elTriggerClassName) { elTriggerClassName = lpClassName.elTriggerToggle; } // Exclude elements, which should not trigger the collapse toggle if (elsExclude && elsExclude.length > 0) { for (const elExclude of elsExclude) { if (target.closest(elExclude)) { return; } } } const elTrigger = target.closest(elTriggerClassName); if (!elTrigger) { return; } //console.log( 'elTrigger', elTrigger ); const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`); if (!elSectionToggle) { return; } elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`); if ('function' === typeof callback) { callback(elSectionToggle); } }; // Get data of form const getDataOfForm = form => { const dataSend = {}; const formData = new FormData(form); for (const pair of formData.entries()) { const key = pair[0]; const value = formData.getAll(key); if (!dataSend.hasOwnProperty(key)) { // Convert value array to string. dataSend[key] = value.join(','); } } return dataSend; }; // Get field keys of form const getFieldKeysOfForm = form => { const keys = []; const elements = form.elements; for (let i = 0; i < elements.length; i++) { const name = elements[i].name; if (name && !keys.includes(name)) { keys.push(name); } } return keys; }; // Merge data handle with data form. const mergeDataWithDatForm = (elForm, dataHandle) => { const dataForm = getDataOfForm(elForm); const keys = getFieldKeysOfForm(elForm); keys.forEach(key => { if (!dataForm.hasOwnProperty(key)) { delete dataHandle[key]; } else if (dataForm[key][0] === '') { delete dataForm[key]; delete dataHandle[key]; } }); dataHandle = { ...dataHandle, ...dataForm }; return dataHandle; }; /** * Event trigger * For each list of event handlers, listen event on document. * * eventName: 'click', 'change', ... * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] * * @param eventName * @param eventHandlers */ const eventHandlers = (eventName, eventHandlers) => { document.addEventListener(eventName, e => { const target = e.target; let args = { e, target }; eventHandlers.forEach(eventHandler => { args = { ...args, ...eventHandler }; //console.log( args ); // Check condition before call back if (eventHandler.conditionBeforeCallBack) { if (eventHandler.conditionBeforeCallBack(args) !== true) { return; } } // Special check for keydown event with checkIsEventEnter = true if (eventName === 'keydown' && eventHandler.checkIsEventEnter) { if (e.key !== 'Enter') { return; } } if (target.closest(eventHandler.selector)) { if (eventHandler.class) { // Call method of class, function callBack will understand exactly {this} is class object. eventHandler.class[eventHandler.callBack](args); } else { // For send args is objected, {this} is eventHandler object, not class object. eventHandler.callBack(args); } } }); }); }; /** * Debounce - delays function execution until after `wait` ms of inactivity. * * Each call resets the timer. Only the last call in a burst executes. * * USE CASES: * - Search inputs, form validation, window resize * - Multiple elements need independent timers * - When you need to call with different arguments * * EXAMPLES: * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); * * const debouncedResize = debounce( recalculateLayout, 250 ); * window.addEventListener('resize', debouncedResize); * * ⚠️ Create ONCE outside event handlers, not inside. * * @param {Function} func - Function to debounce (can be anonymous) * @param {number} wait - Milliseconds to wait (default: 500) * @return {Function} Debounced wrapper function * @since 4.3.7 * @version 1.0.0 */ const debounce = (func, wait = 500) => { let timer; return args => { clearTimeout(timer); timer = setTimeout(() => func(args), wait); }; }; /***/ } /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ if (!(moduleId in __webpack_modules__)) { /******/ delete __webpack_module_cache__[moduleId]; /******/ var e = new Error("Cannot find module '" + moduleId + "'"); /******/ e.code = 'MODULE_NOT_FOUND'; /******/ throw e; /******/ } /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. (() => { /*!*******************************************!*\ !*** ./assets/src/js/admin/learnpress.js ***! \*******************************************/ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./assets/src/js/utils.js"); const $ = jQuery; const $doc = $(document); const makePaymentsSortable = function makePaymentsSortable() { // Make payments sortable $('.learn-press-payments.sortable tbody').sortable({ handle: '.dashicons-menu', helper(e, ui) { ui.children().each(function () { $(this).width($(this).width()); }); return ui; }, axis: 'y', start(event, ui) {}, stop(event, ui) {}, update(event, ui) { const order = $(this).children().map(function () { return $(this).find('input[name="payment-order"]').val(); }).get(); $.post({ url: '', data: { 'lp-ajax': 'update-payment-order', order, nonce: $('input[name=lp-settings-nonce]').val() }, success(response) {} }); } }); }; /** Start Nhamdv code */ const lpMetaboxCustomFields = () => { $('.lp-metabox__custom-fields').on('click', '.lp-metabox-custom-field-button', function () { const row = $(this).data('row').replace(/lp_metabox_custom_fields_key/gi, Math.floor(Math.random() * 1000) + 1); $(this).closest('table').find('tbody').append(row); updateSort($(this).closest('.lp-metabox__custom-fields')); return false; }); $('.lp-metabox__custom-fields').on('click', 'a.delete', function () { $(this).closest('tr').remove(); updateSort($(this).closest('.lp-metabox__custom-fields')); return false; }); $('.lp-metabox__custom-fields tbody').sortable({ items: 'tr', cursor: 'move', axis: 'y', handle: 'td.sort', scrollSensitivity: 40, forcePlaceholderSize: true, helper: 'clone', opacity: 0.65, update(event, ui) { updateSort($(this).closest('.lp-metabox__custom-fields')); } }); const updateSort = element => { const items = element.find('tbody tr'); items.each(function (i, item) { $(this).find('.sort .count').val(i); }); }; }; const lpMetaboxRepeaterField = () => { const updateSort = element => { const items = element.find('.lp_repeater_meta_box__field'); items.each(function (i, item) { $(this).find('.lp_repeater_meta_box__field__count').val(i); $(this).find('.lp_repeater_meta_box__title__title > span').text(i + 1); }); }; $('.lp_repeater_meta_box__add').on('click', function () { const row = $(this).data('add').replace(/lp_metabox_repeater_key/gi, Math.floor(Math.random() * 1000) + 1); $(this).closest('.lp_repeater_meta_box__wrapper').find('.lp_repeater_meta_box__fields').append(row); updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); $(this).closest('.lp_repeater_meta_box__wrapper').find('.lp_repeater_meta_box__fields').last().find('input').trigger('focus'); return false; }); $('.lp_repeater_meta_box__wrapper').on('click', 'a.lp_repeater_meta_box__title__delete', function () { $(this).closest('.lp_repeater_meta_box__field').remove(); updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); return false; }); $('.lp_repeater_meta_box__fields').on('click', '.lp_repeater_meta_box__title__toggle, .lp_repeater_meta_box__title__title', function () { const field = $(this).closest('.lp_repeater_meta_box__field'); if (field.hasClass('lp_repeater_meta_box__field_active')) { field.removeClass('lp_repeater_meta_box__field_active'); } else { field.addClass('lp_repeater_meta_box__field_active'); } return false; }); $('.lp_repeater_meta_box__fields').sortable({ items: '.lp_repeater_meta_box__field', cursor: 'grab', axis: 'y', handle: '.lp_repeater_meta_box__title__sort', scrollSensitivity: 40, forcePlaceholderSize: true, helper: 'clone', opacity: 0.65, update(event, ui) { updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); } }); }; const lpMetaboxExtraInfo = () => { $('.lp_course_extra_meta_box__add').on('click', function () { $(this).closest('.lp_course_extra_meta_box__content').find('.lp_course_extra_meta_box__fields').append($(this).data('add')); $(this).closest('.lp_course_extra_meta_box__content').find('.lp_course_extra_meta_box__field').last().find('input').trigger('focus'); return false; }); /*document.querySelectorAll( '.lp_course_extra_meta_box__fields' ).forEach( ( ele ) => { ele.addEventListener( 'keydown', ( e ) => { const inputs = ele.querySelectorAll( '.lp_course_extra_meta_box__input' ); if ( e.keyCode === 13 ) { e.preventDefault(); inputs.forEach( ( input ) => { input.blur(); } ); return false; } } ); } );*/ $('.lp_course_extra_meta_box__fields').on('click', 'a.delete', function () { $(this).closest('.lp_course_extra_meta_box__field').remove(); return false; }); $('.lp_course_extra_meta_box__fields').sortable({ items: '.lp_course_extra_meta_box__field', cursor: 'grab', axis: 'y', handle: '.sort', scrollSensitivity: 40, forcePlaceholderSize: true, helper: 'clone', opacity: 0.65 }); // FAQs metabox. $('.lp_course_faq_meta_box__add').on('click', function () { $(this).closest('.lp_course_faq_meta_box__content').find('.lp_course_faq_meta_box__fields').append($(this).data('add')); return false; }); /*document.querySelectorAll( '.lp_course_faq_meta_box__fields' ).forEach( ( ele ) => { ele.addEventListener( 'keydown', ( e ) => { const inputs = ele.querySelectorAll( '.lp_course_faq_meta_box__field input' ); const textareas = ele.querySelectorAll( '.lp_course_faq_meta_box__field textarea' ); if ( e.keyCode === 13 ) { e.preventDefault(); [ ...inputs, ...textareas ].forEach( ( input ) => { input.blur(); } ); return false; } } ); } );*/ $('.lp_course_faq_meta_box__fields').on('click', 'a.delete', function () { $(this).closest('.lp_course_faq_meta_box__field').remove(); return false; }); $('.lp_course_faq_meta_box__fields').sortable({ items: '.lp_course_faq_meta_box__field', cursor: 'grab', axis: 'y', handle: '.sort', scrollSensitivity: 40, forcePlaceholderSize: true, helper: 'clone', opacity: 0.65 }); }; // Nhamdv. const lpGetFinalQuiz = () => { const btns = document.querySelectorAll('.lp-metabox-get-final-quiz'); [...btns].map(btn => { btn.addEventListener('click', e => { e.preventDefault(); const text = btn.textContent, loading = btn.dataset.loading, message = document.querySelector('.lp-metabox-evaluate-final_quiz'); if (message) { message.remove(); } btn.textContent = loading; getResponse(btn).then(data => { const { message, data: responseData } = data; btn.textContent = text; const newNode = document.createElement('div'); newNode.className = 'lp-metabox-evaluate-final_quiz'; newNode.innerHTML = responseData || message; btn.parentNode.insertBefore(newNode, btn.nextSibling); }); }); }); const getResponse = async btn => { const response = await wp.apiFetch({ path: 'lp/v1/admin/course/get_final_quiz', method: 'POST', data: { courseId: btn.dataset.postid || '' } }); return response; }; }; const lpMetaboxColorPicker = () => { $('.lp-metabox__colorpick').iris({ change(event, ui) { $(this).parent().find('.colorpickpreview').css({ backgroundColor: ui.color.toString() }); }, hide: true, border: true }).on('click focus', function (event) { event.stopPropagation(); $('.iris-picker').hide(); $(this).closest('td').find('.iris-picker').show(); $(this).data('original-value', $(this).val()); }).on('change', function () { if ($(this).is('.iris-error')) { const originalValue = $(this).data('original-value'); if (originalValue.match(/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/)) { $(this).val($(this).data('original-value')).trigger('change'); } else { $(this).val('').trigger('change'); } } }); $('body').on('click', function () { $('.iris-picker').hide(); }); }; const lpMetaboxImage = () => { $('.lp-metabox-field__image').each((i, ele) => { let lpImageFrame; const addImage = $(ele).find('.lp-metabox-field__image--add'); const delImage = $(ele).find('.lp-metabox-field__image--delete'); const image = $(ele).find('.lp-metabox-field__image--image'); const inputVal = $(ele).find('.lp-metabox-field__image--id'); if (!inputVal.val()) { addImage.show(); delImage.hide(); } else { addImage.hide(); delImage.show(); } addImage.on('click', event => { event.preventDefault(); if (lpImageFrame) { lpImageFrame.open(); return; } lpImageFrame = wp.media({ title: addImage.data('choose'), button: { text: addImage.data('update') }, multiple: false }); lpImageFrame.on('select', function () { const attachment = lpImageFrame.state().get('selection').first().toJSON(); const attachmentImage = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; image.append('
'); inputVal.val(attachment.id); addImage.hide(); delImage.show(); }); lpImageFrame.open(); }); delImage.on('click', event => { event.preventDefault(); image.html(''); addImage.show(); delImage.hide(); inputVal.val(''); }); }); }; const lpMetaboxImageAdvanced = () => { $('.lp-metabox-field__image-advanced').each((i, element) => { let lpImageFrame; const imageGalleryIds = $(element).find('#lp-gallery-images-ids'); const listImages = $(element).find('.lp-metabox-field__image-advanced-images'); const btnUpload = $(element).find('.lp-metabox-field__image-advanced-upload > a'); $(btnUpload).on('click', event => { event.preventDefault(); if (lpImageFrame) { lpImageFrame.open(); return; } lpImageFrame = wp.media({ title: btnUpload.data('choose'), button: { text: btnUpload.data('update') }, states: [new wp.media.controller.Library({ title: btnUpload.data('choose'), filterable: 'all', multiple: true })] }); lpImageFrame.on('select', function () { const selection = lpImageFrame.state().get('selection'); let attachmentIds = imageGalleryIds.val(); selection.forEach(function (attachment) { attachment = attachment.toJSON(); if (attachment.id) { attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id; const attachmentImage = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; listImages.append('