PageSourceSearch

https://www.africansnakebiteinstitute.com/wp-content/plugins/learn…/assets/js/dist/loadAJAX.js?ver=1790938262

js africansnakebiteinstitute.com collected 2026-10-02 10:52:11 UTC 15,667 bytes, 505 lines download raw bytes

vendor: 111 bytes, lines 1-5
1/******/ (() => { // webpackBootstrap
2/******/ 	"use strict";
3/******/ 	var __webpack_modules__ = ({
4
5/***/ "./
5assets/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 */   listenElementCreated: () => (/* binding */ listenElementCreated),
14/* harmony export */   listenElementViewed: () => (/* binding */ listenElementViewed),
15/* harmony export */   lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs),
16/* harmony export */   lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld),
17/* harmony export */   lpClassName: () => (/* binding */ lpClassName),
18/* harmony export */   lpFetchAPI: () => (/* binding */ lpFetchAPI),
19/* harmony export */   lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam),
20/* harmony export */   lpOnElementReady: () => (/* binding */ lpOnElementReady),
21/* harmony export */   lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl),
22/* harmony export */   lpShowHideEl: () => (/* binding */ lpShowHideEl)
23/* harmony export */ });
24/**
25 * Utils functions
26 *
27 * @param url
28 * @param data
29 * @param functions
30 * @since 4.2.5.1
31 * @version 1.0.3
32 */
33const lpClassName = {
34  hidden: 'lp-hidden',
35  loading: 'loading'
36};
37const lpFetchAPI = (url, data = {}, functions = {}) => {
38  if ('function' === typeof functions.before) {
39    functions.before();
40  }
41  fetch(url, {
42    method: 'GET',
43    ...data
44  }).then(response => response.json()).then(response => {
45    if ('function' === typeof functions.success) {
46      functions.success(response);
47    }
48  }).catch(err => {
49    if ('function' === typeof functions.error) {
50      functions.error(err);
51    }
52  }).finally(() => {
53    if ('function' === typeof functions.completed) {
54      functions.completed();
55    }
56  });
57};
58
59/**
60 * Get current URL without params.
61 *
62 * @since 4.2.5.1
63 */
64const lpGetCurrentURLNoParam = () => {
65  let currentUrl = window.location.href;
66  const hasParams = currentUrl.includes('?');
67  if (hasParams) {
68    currentUrl = currentUrl.split('?')[0];
69  }
70  return currentUrl;
71};
72const lpAddQueryArgs = (endpoint, args) => {
73  const url = new URL(endpoint);
74  Object.keys(args).forEach(arg => {
75    url.searchParams.set(arg, args[arg]);
76  });
77  return url;
78};
79
80/**
81 * Listen element viewed.
82 *
83 * @param el
84 * @param callback
85 * @since 4.2.5.8
86 */
87const listenElementViewed = (el, callback) => {
88  const observerSeeItem = new IntersectionObserver(function (entries) {
89    for (const entry of entries) {
90      if (entry.isIntersecting) {
91        callback(entry);
92      }
93    }
94  });
95  observerSeeItem.observe(el);
96};
97
98/**
99 * Listen element created.
100 *
101 * @param callback
102 * @since 4.2.5.8
103 */
104const listenElementCreated = callback => {
105  const observerCreateItem = new MutationObserver(function (mutations) {
106    mutations.forEach(function (mutation) {
107      if (mutation.addedNodes) {
108        mutation.addedNodes.forEach(function (node) {
109          if (node.nodeType === 1) {
110            callback(node);
111          }
112        });
113      }
114    });
115  });
116  observerCreateItem.observe(document, {
117    childList: true,
118    subtree: true
119  });
120  // End.
121};
122
123/**
124 * Listen element created.
125 *
126 * @param selector
127 * @param callback
128 * @since 4.2.7.1
129 */
130const lpOnElementReady = (selector, callback) => {
131  const element = document.querySelector(selector);
132  if (element) {
133    callback(element);
134    return;
135  }
136  const observer = new MutationObserver((mutations, obs) => {
137    const element = document.querySelector(selector);
138    if (element) {
139      obs.disconnect();
140      callback(element);
141    }
142  });
143  observer.observe(document.documentElement, {
144    childList: true,
145    subtree: true
146  });
147};
148
149// Parse JSON from string with content include LP_AJAX_START.
150const lpAjaxParseJsonOld = data => {
151  if (typeof data !== 'string') {
152    return data;
153  }
154  const m = String.raw({
155    raw: data
156  }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s);
157  try {
158    if (m) {
159      data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, ''));
160    } else {
161      data = JSON.parse(data);
162    }
163  } catch (e) {
164    data = {};
165  }
166  return data;
167};
168
169// status 0: hide, 1: show
170const lpShowHideEl = (el, status = 0) => {
171  if (!el) {
172    return;
173  }
174  if (!status) {
175    el.classList.add(lpClassName.hidden);
176  } else {
177    el.classList.remove(lpClassName.hidden);
178  }
179};
180
181// status 0: hide, 1: show
182const lpSetLoadingEl = (el, status) => {
183  if (!el) {
184    return;
185  }
186  if (!status) {
187    el.classList.remove(lpClassName.loading);
188  } else {
189    el.classList.add(lpClassName.loading);
190  }
191};
192
193
194/***/ })
194
195
196/******/ 	});
197/************************************************************************/
198/******/ 	// The module cache
199/******/ 	var __webpack_module_cache__ = {};
200/******/ 	
201/******/ 	// The require function
202/******/ 	function __webpack_require__(moduleId) {
203/******/ 		// Check if module is in cache
204/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
205/******/ 		if (cachedModule !== undefined) {
206/******/ 			return cachedModule.exports;
207/******/ 		}
208/******/ 		// Create a new module (and put it into the cache)
209/******/ 		var module = __webpack_module_cache__[moduleId] = {
210/******/ 			// no module.id needed
211/******/ 			// no module.loaded needed
212/******/ 			exports: {}
213/******/ 		};
214/******/ 	
215/******/ 		// Execute the module function
216/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
217/******/ 	
218/******/ 		// Return the exports of the module
219/******/ 		return module.exports;
220/******/ 	}
221/******/ 	
222/************************************************************************/
223/******/ 	/* webpack/runtime/define property getters */
224/******/ 	(() => {
225/******/ 		// define getter functions for harmony exports
226/******/ 		__webpack_require__.d = (exports, definition) => {
227/******/ 			for(var key in definition) {
228/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
229/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
230/******/ 				}
231/******/ 			}
232/******/ 		};
233/******/ 	})();
234/******/ 	
235/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
236/******/ 	(() => {
237/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
238/******/ 	})();
239/******/ 	
240/******/ 	/* webpack/runtime/make namespace object */
241/******/ 	(() => {
242/******/ 		// define __esModule on exports
243/******/ 		__webpack_require__.r = (exports) => {
244/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
245/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
246/******/ 			}
247/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
248/******/ 		};
249/******/ 	})();
250/******/ 	
251/************************************************************************/
252var __webpack_exports__ = {};
253/*!***********************************!*\
254  !*** ./assets/src/js/loadAJAX.js ***!
255  \***********************************/
256__webpack_require__.r(__webpack_exports__);
257/* harmony export */ __webpack_require__.d(__webpack_exports__, {
258/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
259/* harmony export */ });
260/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./assets/src/js/utils.js");
261/**
262 * Load all you need via AJAX
263 *
264 * @since 4.2.5.7
265 * @version 1.0.9
266 */
267
268
269
270// Handle general parameter in the Frontend and Backend
271let lpSettings = {};
272if ('undefined' !== typeof lpDataAdmin) {
273  lpSettings = lpDataAdmin;
274} else if ('undefined' !== typeof lpData) {
275  lpSettings = lpData;
276}
277// End Handle general parameter in the Frontend and Backend
278
279const lpAJAX = () => {
280  const classLPTarget = '.lp-target';
281  const urlCurrent = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpGetCurrentURLNoParam)();
282  return {
283    autoLoadAPIs: () => {
284      console.log('autoLoadAPIs');
285    },
286    fetchAPI: (url, params, callBack) => {
287      const option = {
288        headers: {}
289      };
290      if (0 !== parseInt(lpSettings.user_id)) {
291        option.headers['X-WP-Nonce'] = lpSettings.nonce;
292      }
293      if ('undefined' !== typeof params.args.method_request) {
294        option.method = params.args.method_request;
295      } else {
296        option.method = 'POST';
297      }
298
299      //params.args = { ...params.args, ...lpData.urlParams };
300
301      if ('POST' === option.method) {
302        option.body = JSON.stringify(params);
303        option.headers['Content-Type'] = 'application/json';
304      } else {
305        params.args = JSON.stringify(params.args);
306        params.callback = JSON.stringify(params.callback);
307        url = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(url, params);
308      }
309      (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(url, option, callBack);
310    },
311    fetchAJAX: (params, callBack) => {
312      let urlAjax = lpSettings.lpAjaxUrl;
313
314      // Set param id_url for identify.
315      if (params.hasOwnProperty('args') && params.args.hasOwnProperty('id_url')) {
316        urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
317          id_url: params.args.id_url
318        });
319      }
320      // Set param lang here if exits, for detect translate
321      if (lpSettings.urlParams.hasOwnProperty('lang')) {
322        urlAjax = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlAjax, {
323          lang: lpSettings.urlParams.lang
324        });
325      }
326      const formData = new FormData();
327      const action = params.hasOwnProperty('action') ? params.action : 'load_content_via_ajax';
328      formData.append('nonce', lpSettings.nonce);
329      formData.append('lp-load-ajax', action);
330      formData.append('data', JSON.stringify(params));
331      const dataSend = {
332        method: 'POST',
333        headers: {},
334        body: formData
335      };
336      if (0 !== parseInt(lpSettings.user_id)) {
337        dataSend.headers['X-WP-Nonce'] = lpSettings.nonce;
338      }
339      (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(urlAjax, dataSend, callBack);
340    },
341    getElements: () => {
342      // Finds all elements with the class '.lp-load-ajax-element'
343      const elements = document.querySelectorAll('.lp-load-ajax-element:not(.loaded)');
344      //console.log( 'getElements', elements );
345      if (elements.length) {
346        elements.forEach(element => {
347          //console.log( 'Element handing', element );
348          const elTarget = element.querySelector(`${classLPTarget}`);
349          if (!elTarget) {
350            return;
351          }
352          const dataObj = JSON.parse(elTarget.dataset.send);
353          const dataSend = {
354            ...dataObj
355          };
356          const elLoadingFirst = element.querySelector('.loading-first');
357          const callBack = {
358            success: response => {
359              const {
360                status,
361                message,
362                data
363              } = response;
364              if ('success' === status) {
365                elTarget.innerHTML = data.content;
366              } else if ('error' === status) {
367                elTarget.innerHTML = message;
368              }
369            },
370            error: error => {
371              console.log(error);
372            },
373            completed: () => {
374              wp.hooks.doAction('lp-ajax-completed', element, dataSend);
375              window.lpAJAXG.getElements();
376              //console.log( 'completed' );
377              if (elLoadingFirst) {
378                elLoadingFirst.remove();
379              }
380            }
381          };
382
383          // Call via AJAX
384          window.lpAJAXG.fetchAJAX(dataSend, callBack);
385          element.classList.add('loaded');
386        });
387      }
388    },
389    clickNumberPage: (e, target) => {
390      const btnNumber = target.closest('.page-numbers:not(.disabled)');
391      if (!btnNumber) {
392        return;
393      }
394      const elLPTarget = btnNumber.closest(`${classLPTarget}`);
395      if (!elLPTarget) {
396        return;
397      }
398      e.preventDefault();
399      const dataObj = JSON.parse(elLPTarget.dataset.send);
400      const dataSend = {
401        ...dataObj
402      };
403      if (!dataSend.args.hasOwnProperty('paged')) {
404        dataSend.args.paged = 1;
405      }
406      if (btnNumber.classList.contains('prev')) {
407        dataSend.args.paged--;
408      } else if (btnNumber.classList.contains('next')) {
409        dataSend.args.paged++;
410      } else {
411        const pagedNumber = parseInt(btnNumber.textContent);
412        if (isNaN(pagedNumber) || pagedNumber < 1) {
413          return;
414        }
415        dataSend.args.paged = pagedNumber;
416      }
417      elLPTarget.dataset.send = JSON.stringify(dataSend);
418
419      // Set url params to reload page.
420      // Todo: need check allow set url params.
421      lpSettings.urlParams.paged = dataSend.args.paged;
422      window.history.pushState({}, '', (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlCurrent, lpSettings.urlParams));
423      // End.
424
425      // Show loading
426      window.lpAJAXG.showHideLoading(elLPTarget, 1);
427      // End
428
429      // Scroll to archive element
430      const elLPTargetY = elLPTarget.getBoundingClientRect().top + window.scrollY - 100;
431      window.scrollTo({
432        top: elLPTargetY
433      });
434      const callBack = {
435        success: response => {
436          //console.log( 'response', response );
437          const {
438            status,
439            message,
440            data
441          } = response;
442          elLPTarget.innerHTML = data.content || '';
443        },
444        error: error => {
445          console.log(error);
446        },
447        completed: () => {
448          //console.log( 'completed' );
449          window.lpAJAXG.showHideLoading(elLPTarget, 0);
450        }
451      };
452      window.lpAJAXG.fetchAJAX(dataSend, callBack);
453    },
454    getDataSetCurrent: elLPTarget => {
455      return JSON.parse(elLPTarget.dataset.send);
456    },
457    setDataSetCurrent: (elLPTarget, dataSend) => {
458      return elLPTarget.dataset.send = JSON.stringify(dataSend);
459    },
460    showHideLoading: (elLPTarget, status) => {
461      const elLoading = elLPTarget.closest(`div:not(${classLPTarget})`).querySelector('.lp-loading-change');
462      if (elLoading) {
463        (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elLoading, status);
464      }
465    }
466  };
467};
468window.lpAJAXG = lpAJAX();
469window.lpAJAXG.getElements();
470
471// Events
472document.addEventListener('click', function (e) {
473  const target = e.target;
474  window.lpAJAXG.clickNumberPage(e, target);
475});
476
477// Listen element created
478(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.listenElementCreated)(node => {
479  if (node.classList.contains('lp-load-ajax-element')) {
480    //console.log( 'Element created', node );
481    window.lpAJAXG.getElements();
482  }
483});
484
485// Listen element ready
486(0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady)('.lp-load-ajax-element', element => {
487  //console.log( 'Element ready', element );
488  window.lpAJAXG.getElements();
489});
490
491// Case 2: readystatechange, find all elements with the class '.lp-load-ajax-element' not have class 'loaded'
492document.addEventListener('readystatechange', event => {
493  //console.log( 'readystatechange' );
494  window.lpAJAXG.getElements();
495});
496
497// Case 3: DOMContentLoaded, find all elements with the class '.lp-load-ajax-element' not have class 'loaded'
498document.addEventListener('DOMContentLoaded', () => {
499  //console.log( 'DOMContentLoaded' );
500  window.lpAJAXG.getElements();
501});
502/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lpAJAX);
503/******/ })()
504;
505//# 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.