1/******/ (() => { // webpackBootstrap 2/******/ "use strict"; 3/******/ var __webpack_modules__ = ({ 4 5/***/ "./assets/src/js/utils.js" 6/*!********************************!*\ 7 !*** ./assets/src/js/utils.js ***! 8 \********************************/ 9(__unused_webpack_module, __webpack_exports__, __webpack_require__) { 10 11__webpack_require__.r(__webpack_exports__); 12/* harmony export */ __webpack_require__.d(__webpack_exports__, { 13/* harmony export */ debounce: () => (/* binding */ debounce), 14/* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), 15/* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), 16/* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), 17/* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), 18/* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), 19/* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs), 20/* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld), 21/* harmony export */ lpClassName: () => (/* binding */ lpClassName), 22/* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI), 23/* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam), 24/* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), 25/* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), 26/* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), 27/* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), 28/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) 29/* harmony export */ }); 30/** 31 * Utils functions 32 * 33 * @param url 34 * @param data 35 * @param functions 36 * @since 4.2.5.1 37 * @version 1.0.6 38 */ 39const lpClassName = { 40 hidden: 'lp-hidden', 41 loading: 'loading', 42 elCollapse: 'lp-collapse', 43 elSectionToggle: '.lp-section-toggle', 44 elTriggerToggle: '.lp-trigger-toggle' 45}; 46const lpFetchAPI = (url, data = {}, functions = {}) => { 47 if ('function' === typeof functions.before) { 48 functions.before(); 49 } 50 fetch(url, { 51 method: 'GET', 52 ...data 53 }).then(response => response.json()).then(response => { 54 if ('function' === typeof functions.success) { 55 functions.success(response); 56 } 57 }).catch(err => { 58 if ('function' === typeof functions.error) { 59 functions.error(err); 60 } 61 }).finally(() => { 62 if ('function' === typeof functions.completed) { 63 functions.completed(); 64 } 65 }); 66}; 67 68/** 69 * Get current URL without params. 70 * 71 * @since 4.2.5.1 72 */ 73const lpGetCurrentURLNoParam = () => { 74 let currentUrl = window.location.href; 75 const hasParams = currentUrl.includes('?'); 76 if (hasParams) { 77 currentUrl = currentUrl.split('?')[0]; 78 } 79 return currentUrl; 80}; 81const lpAddQueryArgs = (endpoint, args) => { 82 const url = new URL(endpoint); 83 Object.keys(args).forEach(arg => { 84 url.searchParams.set(arg, args[arg]); 85 }); 86 return url; 87}; 88 89/** 90 * Listen element viewed. 91 * 92 * @param el 93 * @param callback 94 * @since 4.2.5.8 95 */ 96const listenElementViewed = (el, callback) => { 97 const observerSeeItem = new IntersectionObserver(function (entries) { 98 for (const entry of entries) { 99 if (entry.isIntersecting) { 100 callback(entry); 101 } 102 } 103 }); 104 observerSeeItem.observe(el); 105}; 106 107/** 108 * Listen element created. 109 * 110 * @param callback 111 * @since 4.2.5.8 112 */ 113const listenElementCreated = callback => { 114 const observerCreateItem = new MutationObserver(function (mutations) { 115 mutations.forEach(function (mutation) { 116 if (mutation.addedNodes) { 117 mutation.addedNodes.forEach(function (node) { 118 if (node.nodeType === 1) { 119 callback(node); 120 } 121 }); 122 } 123 }); 124 }); 125 observerCreateItem.observe(document, { 126 childList: true, 127 subtree: true 128 }); 129 // End. 130}; 131 132/** 133 * Listen element created. 134 * 135 * @param selector 136 * @param callback 137 * @since 4.2.7.1 138 */ 139const lpOnElementReady = (selector, callback) => { 140 const element = document.querySelector(selector); 141 if (element) { 142 callback(element); 143 return; 144 } 145 const observer = new MutationObserver((mutations, obs) => { 146 const element = document.querySelector(selector); 147 if (element) { 148 obs.disconnect(); 149 callback(element); 150 } 151 }); 152 observer.observe(document.documentElement, { 153 childList: true, 154 subtree: true 155 }); 156}; 157 158// Parse JSON from string with content include LP_AJAX_START. 159const lpAjaxParseJsonOld = data => { 160 if (typeof data !== 'string') { 161 return data; 162 }
163 const m = String.raw({ 164 raw: data 165 }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s); 166 try { 167 if (m) { 168 data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, '')); 169 } else { 170 data = JSON.parse(data); 171 } 172 } catch (e) { 173 data = {}; 174 } 175 return data; 176}; 177 178// status 0: hide, 1: show 179const lpShowHideEl = (el, status = 0) => { 180 if (!el) { 181 return; 182 } 183 if (!status) { 184 el.classList.add(lpClassName.hidden); 185 } else { 186 el.classList.remove(lpClassName.hidden); 187 } 188}; 189 190// status 0: hide, 1: show 191const lpSetLoadingEl = (el, status) => { 192 if (!el) { 193 return; 194 } 195 if (!status) { 196 el.classList.remove(lpClassName.loading); 197 } else { 198 el.classList.add(lpClassName.loading); 199 } 200}; 201 202// Toggle collapse section 203const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => { 204 if (!elTriggerClassName) { 205 elTriggerClassName = lpClassName.elTriggerToggle; 206 } 207 208 // Exclude elements, which should not trigger the collapse toggle 209 if (elsExclude && elsExclude.length > 0) { 210 for (const elExclude of elsExclude) { 211 if (target.closest(elExclude)) { 212 return; 213 } 214 } 215 } 216 const elTrigger = target.closest(elTriggerClassName); 217 if (!elTrigger) { 218 return; 219 } 220 221 //console.log( 'elTrigger', elTrigger ); 222 223 const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`); 224 if (!elSectionToggle) { 225 return; 226 } 227 elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`); 228 if ('function' === typeof callback) { 229 callback(elSectionToggle); 230 } 231}; 232 233// Get data of form 234const getDataOfForm = form => { 235 const dataSend = {}; 236 const formData = new FormData(form); 237 for (const pair of formData.entries()) { 238 const key = pair[0];
239 const value = formData.getAll(key); 240 if (!dataSend.hasOwnProperty(key)) { 241 // Convert value array to string. 242 dataSend[key] = value.join(','); 243 } 244 } 245 return dataSend; 246}; 247 248// Get field keys of form 249const getFieldKeysOfForm = form => { 250 const keys = []; 251 const elements = form.elements; 252 for (let i = 0; i < elements.length; i++) { 253 const name = elements[i].name; 254 if (name && !keys.includes(name)) { 255 keys.push(name); 256 } 257 } 258 return keys; 259}; 260 261// Merge data handle with data form. 262const mergeDataWithDatForm = (elForm, dataHandle) => { 263 const dataForm = getDataOfForm(elForm); 264 const keys = getFieldKeysOfForm(elForm); 265 keys.forEach(key => { 266 if (!dataForm.hasOwnProperty(key)) { 267 delete dataHandle[key]; 268 } else if (dataForm[key][0] === '') { 269 delete dataForm[key]; 270 delete dataHandle[key]; 271 } 272 }); 273 dataHandle = { 274 ...dataHandle, 275 ...dataForm 276 }; 277 return dataHandle; 278}; 279 280/** 281 * Event trigger 282 * For each list of event handlers, listen event on document. 283 * 284 * eventName: 'click', 'change', ... 285 * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] 286 * 287 * @param eventName 288 * @param eventHandlers 289 */ 290const eventHandlers = (eventName, eventHandlers) => { 291 document.addEventListener(eventName, e => { 292 const target = e.target; 293 let args = { 294 e, 295 target 296 }; 297 eventHandlers.forEach(eventHandler => { 298 args = { 299 ...args, 300 ...eventHandler 301 }; 302 303 //console.log( args ); 304 305 // Check condition before call back 306 if (eventHandler.conditionBeforeCallBack) { 307 if (eventHandler.conditionBeforeCallBack(args) !== true) { 308 return; 309 } 310 } 311 312 // Special check for keydown event with checkIsEventEnter = true 313 if (eventName === 'keydown' && eventHandler.checkIsEventEnter) { 314 if (e.key !== 'Enter') { 315 return; 316 } 317 } 318 if (target.closest(eventHandler.selector)) { 319 if (eventHandler.class) { 320 // Call method of class, function callBack will understand exactly {this} is class object. 321 eventHandler.class[eventHandler.callBack](args); 322 } else { 323 // For send args is objected, {this} is eventHandler object, not class object. 324 eventHandler.callBack(args); 325 } 326 } 327 }); 328 }); 329}; 330 331/** 332 * Debounce - delays function execution until after `wait` ms of inactivity. 333 * 334 * Each call resets the timer. Only the last call in a burst executes. 335 * 336 * USE CASES: 337 * - Search inputs, form validation, window resize 338 * - Multiple elements need independent timers 339 * - When you need to call with different arguments 340 * 341 * EXAMPLES: 342 * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); 343 * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); 344 * 345 * const debouncedResize = debounce( recalculateLayout, 250 ); 346 * window.addEventListener('resize', debouncedResize); 347 * 348 * â ï¸ Create ONCE outside event handlers, not inside. 349 * 350 * @param {Function} func - Function to debounce (can be anonymous) 351 * @param {number} wait - Milliseconds to wait (default: 500) 352 * @return {Function} Debounced wrapper function 353 * @since 4.3.7 354 * @version 1.0.0 355 */ 356const debounce = (func, wait = 500) => { 357 let timer; 358 return args => { 359 clearTimeout(timer); 360 timer = setTimeout(() => func(args), wait); 361 }; 362}; 363 364/***/ } 365 366/******/ }); 367/************************************************************************/ 368/******/ // The module cache 369/******/ const __webpack_module_cache__ = {}; 370/******/ 371/******/ // The require function 372/******/ function __webpack_require__(moduleId) { 373/******/ // Check if module is in cache 374/******/ const cachedModule = __webpack_module_cache__[moduleId]; 375/******/ if (cachedModule !== undefined) { 376/******/ return cachedModule.exports; 377/******/ } 378/******/ // Create a new module (and put it into the cache) 379/******/ const module = __webpack_module_cache__[moduleId] = { 380/******/ // no module.id needed 381/******/ // no module.loaded needed 382/******/ exports: {} 383/******/ }; 384/******/ 385/******/ // Execute the module function 386/******/ if (!(moduleId in __webpack_modules__)) { 387/******/ delete __webpack_module_cache__[moduleId]; 388/******/ const e = new Error("Cannot find module '" + moduleId + "'"); 389/******/ e.code = 'MODULE_NOT_FOUND'; 390/******/ throw e; 391/******/ } 392/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 393/******/ 394/******/ // Return the exports of the module 395/******/ return module.exports; 396/******/ } 397/******/ 398/************************************************************************/ 399/******/ /* webpack/runtime/define property getters */ 400/******/ (() => { 401/******/ // define getter/value functions for harmony exports 402/******/ __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++; } 415/******/ } 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/******/ } 423/******/ }; 424/******/ })(); 425/******/ 426/******/ /* webpack/runtime/hasOwnProperty shorthand */ 427/******/ (() => { 428/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop)) 429/******/ })(); 430/******/ 431/******/ /* webpack/runtime/make namespace object */ 432/******/ (() => { 433/******/ // define __esModule on exports 434/******/ __webpack_require__.r = (exports) => { 435/******/ if(Symbol.toStringTag) { 436/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 437/******/ } 438/******/ Object.defineProperty(exports, '__esModule', { value: true }); 439/******/ }; 440/******/ })(); 441/******/ 442/************************************************************************/ 443let __webpack_exports__ = {}; 444// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. 445(() => { 446/*!***********************************!*\ 447 !*** ./assets/src/js/loadAJAX.js ***! 448 \***********************************/ 449__webpack_require__.r(__webpack_exports__); 450/* harmony export */ __webpack_require__.d(__webpack_exports__, { 451/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) 452/* harmony export */ }); 453/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./assets/src/js/utils.js"); 454/** 455 * Load all you need via AJAX 456 * 457 * @since 4.2.5.7 458 * @version 1.1.0 459 */ 460 461 462 463// Handle general parameter in the Frontend and Backend 464let lpSettings = {}; 465if ('undefined' !== typeof lpDataAdmin) { 466 lpSettings = lpDataAdmin; 467} else if ('undefined' !== typeof lpData) { 468 lpSettings = lpData; 469} 470// End Handle general parameter in the Frontend and Backend 471 472const lpAJAX = () => { 473 const classLPTarget = '.lp-target';
474 const urlCurrent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam)(); 475 return { 476 autoLoadAPIs: () => { 477 console.log('autoLoadAPIs'); 478 }, 479 fetchAPI: (url, params, callBack) => { 480 const option = { 481 headers: {} 482 }; 483 if (0 !== parseInt(lpSettings.user_id)) { 484 option.headers['X-WP-Nonce'] = lpSettings.nonce; 485 } 486 if ('undefined' !== typeof params.args.method_request) { 487 option.method = params.args.method_request; 488 } else { 489 option.method = 'POST'; 490 } 491 492 //params.args = { ...params.args, ...lpData.urlParams }; 493 494 if ('POST' === option.method) { 495 option.body = JSON.stringify(params); 496 option.headers['Content-Type'] = 'application/json'; 497 } else { 498 params.args = JSON.stringify(params.args); 499 params.callback = JSON.stringify(params.callback); 500 url = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(url, params); 501 } 502 ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(url, option, callBack); 503 }, 504 fetchAJAX: (params, callBack) => { 505 let urlAjax = lpSettings.lpAjaxUrl; 506 507 // Set param id_url for identify. 508 if (params.hasOwnProperty('args') && params.args.hasOwnProperty('id_url')) { 509 urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, { 510 id_url: params.args.id_url 511 }); 512 } else if (params.hasOwnProperty('id_url')) { 513 urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, { 514 id_url: params.id_url 515 }); 516 } 517 // Set param lang here if exits, for detect translate 518 if (lpSettings.urlParams.hasOwnProperty('lang')) { 519 urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, { 520 lang: lpSettings.urlParams.lang 521 }); 522 } 523 const formData = new FormData(); 524 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 }; 533 if (0 !== parseInt(lpSettings.user_id)) { 534 dataSend.headers['X-WP-Nonce'] = lpSettings.nonce; 535 } 536 ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(urlAjax, dataSend, callBack); 537 }, 538 getElements: () => { 539 // Finds all elements with the class '.lp-load-ajax-element' 540 const elements = document.querySelectorAll('.lp-load-ajax-element:not(.loaded)'); 541 //console.log( 'getElements', elements ); 542 if (elements.length) { 543 elements.forEach(element => { 544 //console.log( 'Element handing', element ); 545 const elTarget = element.querySelector(`${classLPTarget}`); 546 if (!elTarget) { 547 return; 548 } 549 const dataObj = JSON.parse(elTarget.dataset.send); 550 const dataSend = { 551 ...dataObj 552 }; 553 const elLoadingFirst = element.querySelector('.loading-first'); 554 const callBack = { 555 success: response => { 556 const { 557 status, 558 message, 559 data 560 } = response; 561 if ('success' === status) { 562 elTarget.innerHTML = data.content; 563 } else if ('error' === status) { 564 elTarget.innerHTML = message; 565 } 566 }, 567 error: error => { 568 console.log(error); 569 }, 570 completed: () => { 571 if (typeof wp !== 'undefined' && wp.hooks) { 572 wp.hooks.doAction('lp-ajax-completed', element, dataSend); 573 } 574 window.lpAJAXG.getElements(); 575 //console.log( 'completed' ); 576 if (elLoadingFirst) { 577 elLoadingFirst.remove(); 578 } 579 } 580 }; 581 582 // Call via AJAX 583 window.lpAJAXG.fetchAJAX(dataSend, callBack); 584 element.classList.add('loaded'); 585 }); 586 } 587 }, 588 clickNumberPage: (e, target) => {
589 const btnNumber = target.closest('.page-numbers:not(.disabled)'); 590 if (!btnNumber) { 591 return; 592 } 593 const elLPTarget = btnNumber.closest(`${classLPTarget}`); 594 if (!elLPTarget) { 595 return; 596 } 597 e.preventDefault(); 598 const dataObj = JSON.parse(elLPTarget.dataset.send); 599 const dataSend = { 600 ...dataObj 601 }; 602 if (!dataSend.args.hasOwnProperty('paged')) { 603 dataSend.args.paged = 1; 604 } 605 if (btnNumber.classList.contains('prev')) { 606 dataSend.args.paged--; 607 } else if (btnNumber.classList.contains('next')) { 608 dataSend.args.paged++; 609 } else { 610 const pagedNumber = parseInt(btnNumber.textContent); 611 if (isNaN(pagedNumber) || pagedNumber < 1) { 612 return; 613 } 614 dataSend.args.paged = pagedNumber; 615 } 616 elLPTarget.dataset.send = JSON.stringify(dataSend); 617 618 // Set url params to reload page. 619 if (!dataSend.args.hasOwnProperty('enableUpdateParamsUrl') || dataSend.args.enableUpdateParamsUrl) { 620 lpSettings.urlParams.paged = dataSend.args.paged; 621 window.history.pushState({}, '', (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlCurrent, lpSettings.urlParams)); 622 } 623 // End. 624 625 // Show loading 626 window.lpAJAXG.showHideLoading(elLPTarget, 1); 627 // End 628 629 // Scroll to archive element 630 if (!dataSend.args.hasOwnProperty('enableScrollToView') || dataSend.args.enableScrollToView) { 631 const elLPTargetY = elLPTarget.getBoundingClientRect().top + window.scrollY - 100; 632 window.scrollTo({ 633 top: elLPTargetY 634 }); 635 } 636 const callBack = { 637 success: response => { 638 //console.log( 'response', response ); 639 const { 640 status, 641 message, 642 data 643 } = response; 644 elLPTarget.innerHTML = data.content || ''; 645 }, 646 error: error => { 647 console.log(error); 648 }, 649 completed: () => { 650 //console.log( 'completed' ); 651 window.lpAJAXG.showHideLoading(elLPTarget, 0); 652 } 653 }; 654 window.lpAJAXG.fetchAJAX(dataSend, callBack); 655 }, 656 getDataSetCurrent: elLPTarget => { 657 return JSON.parse(elLPTarget.dataset.send); 658 }, 659 setDataSetCurrent: (elLPTarget, dataSend) => { 660 return elLPTarget.dataset.send = JSON.stringify(dataSend); 661 }, 662 showHideLoading: (elLPTarget, status) => { 663 const elLoading = elLPTarget.nextElementSibling?.querySelector('.lp-loading-change'); 664 if (elLoading) { 665 (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elLoading, status); 666 } 667 } 668 }; 669}; 670window.lpAJAXG = lpAJAX(); 671window.lpAJAXG.getElements(); 672 673// Events 674document.addEventListener('click', function (e) { 675 const target = e.target; 676 window.lpAJAXG.clickNumberPage(e, target); 677}); 678 679// Listen element created 680(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated)(node => { 681 if (node.classList.contains('lp-load-ajax-element')) { 682 //console.log( 'Element created', node ); 683 window.lpAJAXG.getElements(); 684 } 685}); 686 687// Listen element ready 688(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady)('.lp-load-ajax-element', element => { 689 //console.log( 'Element ready', element ); 690 window.lpAJAXG.getElements(); 691}); 692 693// Case 2: readystatechange, find all elements with the class '.lp-load-ajax-element' not have class 'loaded' 694document.addEventListener('readystatechange', event => { 695 //console.log( 'readystatechange' ); 696 window.lpAJAXG.getElements(); 697}); 698 699// Case 3: DOMContentLoaded, find all elements with the class '.lp-load-ajax-element' not have class 'loaded' 700document.addEventListener('DOMContentLoaded', () => { 701 //console.log( 'DOMContentLoaded' ); 702 window.lpAJAXG.getElements(); 703}); 704/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lpAJAX); 705})(); 706 707/******/ })() 708; 709//# sourceMappingURL=loadAJAX.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.