PageSourceSearch

https://studentsrisingabove.org/wp-content/plugins/learnpress/assets/js/dist/loadAJAX.js?ver=1790251507

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