PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 4.2.0 All 139 releases
learnpress / assets / js / dist / frontend / instructors.js

instructors.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at assets/js/dist/frontend/instructors.js

453 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ var __webpack_modules__ = ({
4
5 /***/ "./assets/src/apps/js/frontend/instructors/instructor-list.js"
6 /*!********************************************************************!*\
7 !*** ./assets/src/apps/js/frontend/instructors/instructor-list.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 */ "default": () => (/* binding */ InstructorList)
14 /* harmony export */ });
15 /* harmony import */ var _utils_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../utils/utils */ "./assets/src/apps/js/utils/utils.js");
16
17 let query = {};
18 let lpUrlParam = [];
19 if ('undefined' !== typeof lpSkeletonParam) {
20 lpUrlParam = lpSkeletonParam;
21 }
22 function InstructorList() {
23 // Call API get instructors without wait element ready
24 let htmlListItemInstructor = '';
25 let htmlPagination = '';
26 getInstructors({
27 ...lpUrlParam,
28 paged: 1
29 }, true, function (res) {
30 htmlListItemInstructor = res.data.content;
31 if (res.data.pagination !== undefined) {
32 htmlPagination = res.data.pagination;
33 }
34 });
35 let totalTimeDetect = 0;
36 const detectedElArchive = setInterval(function () {
37 totalTimeDetect++;
38
39 // Stop if detected more than 10 seconds
40 if (totalTimeDetect > 10000) {
41 clearInterval(detectedElArchive);
42 }
43 const elListInstructors = document.querySelector('.lp-list-instructors');
44 if (elListInstructors && htmlListItemInstructor !== '') {
45 clearInterval(detectedElArchive);
46 const elUlListInstructors = document.querySelector('.ul-list-instructors');
47 elListInstructors.classList.add('detected');
48 elUlListInstructors.innerHTML = htmlListItemInstructor;
49 elListInstructors.insertAdjacentHTML('beforeend', htmlPagination);
50 }
51 }, 1);
52
53 // For case multiple ul list instructors on a page.
54 /*document.addEventListener( 'DOMContentLoaded', function( event ) {
55 const elListInstructors = document.querySelectorAll( '.lp-list-instructors:not(.detected)' );
56 if ( elListInstructors.length > 0 ) {
57 elListInstructors.forEach( function( el ) {
58 const elUlListInstructors = el.querySelector( '.ul-list-instructors' );
59 query = { paged: 1 };
60 getInstructors( query, true, function( res ) {
61 elUlListInstructors.innerHTML = res.data.content;
62 if ( res.data.pagination !== undefined ) {
63 el.insertAdjacentHTML( 'beforeend', res.data.pagination );
64 }
65 } );
66 } );
67 }
68 } );*/
69
70 pagination();
71 }
72 const getInstructors = (queryParam, firstLoad = false, callBack) => {
73 const url = (0,_utils_utils__WEBPACK_IMPORTED_MODULE_0__.lpAddQueryArgs)(urlListInstructorsAPI, queryParam);
74 const paramsFetch = {
75 method: 'GET'
76 };
77 fetch(url, paramsFetch).then(response => response.json()).then(res => {
78 if (res.data.content !== undefined) {
79 if (callBack) {
80 callBack(res);
81 }
82 }
83 }).catch(error => {
84 console.log(error);
85 }).finally(() => {
86 if (firstLoad === false) {
87 const urlPush = lpInstructorsUrl + '?paged=' + queryParam.paged;
88 window.history.pushState('', '', urlPush);
89 }
90 });
91 };
92 const pagination = () => {
93 document.addEventListener('click', function (event) {
94 const target = event.target;
95 const elListInstructors = target.closest('.lp-list-instructors');
96 if (!elListInstructors) {
97 return;
98 }
99 const elUlListInstructors = elListInstructors.querySelector('.ul-list-instructors');
100 const pagination = target.closest('.learn-press-pagination');
101 if (!pagination || !elListInstructors || !elUlListInstructors) {
102 return;
103 }
104 let pageLinkNode;
105 if (target.tagName.toLowerCase() === 'a') {
106 pageLinkNode = target;
107 } else if (target.closest('a.page-numbers')) {
108 pageLinkNode = target.closest('a.page-numbers');
109 } else {
110 return;
111 }
112 event.preventDefault();
113 const currentPage = parseInt(pagination.querySelector('.current').innerHTML);
114 let paged;
115 if (pageLinkNode.classList.contains('next')) {
116 paged = currentPage + 1;
117 } else if (pageLinkNode.classList.contains('prev')) {
118 paged = currentPage - 1;
119 } else {
120 paged = pageLinkNode.innerHTML;
121 }
122 query = {
123 ...query,
124 paged,
125 ...lpUrlParam
126 };
127 getInstructors(query, false, function (res) {
128 elUlListInstructors.innerHTML = res.data.content;
129 pagination.remove();
130 if (res.data.pagination !== undefined) {
131 elListInstructors.insertAdjacentHTML('beforeend', res.data.pagination);
132 }
133 });
134 });
135 };
136
137 /***/ },
138
139 /***/ "./assets/src/apps/js/utils/utils.js"
140 /*!*******************************************!*\
141 !*** ./assets/src/apps/js/utils/utils.js ***!
142 \*******************************************/
143 (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
144
145 __webpack_require__.r(__webpack_exports__);
146 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
147 /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated),
148 /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed),
149 /* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs),
150 /* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld),
151 /* harmony export */ lpClassName: () => (/* binding */ lpClassName),
152 /* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI),
153 /* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam),
154 /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady),
155 /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl),
156 /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl),
157 /* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse)
158 /* harmony export */ });
159 /**
160 * Utils functions
161 *
162 * @param url
163 * @param data
164 * @param functions
165 * @since 4.2.5.1
166 * @version 1.0.3
167 */
168 const lpClassName = {
169 hidden: 'lp-hidden',
170 loading: 'loading',
171 elCollapse: 'lp-collapse',
172 elSectionToggle: '.lp-section-toggle',
173 elTriggerToggle: '.lp-trigger-toggle'
174 };
175 const lpFetchAPI = (url, data = {}, functions = {}) => {
176 if ('function' === typeof functions.before) {
177 functions.before();
178 }
179 fetch(url, {
180 method: 'GET',
181 ...data
182 }).then(response => response.json()).then(response => {
183 if ('function' === typeof functions.success) {
184 functions.success(response);
185 }
186 }).catch(err => {
187 if ('function' === typeof functions.error) {
188 functions.error(err);
189 }
190 }).finally(() => {
191 if ('function' === typeof functions.completed) {
192 functions.completed();
193 }
194 });
195 };
196
197 /**
198 * Get current URL without params.
199 *
200 * @since 4.2.5.1
201 */
202 const lpGetCurrentURLNoParam = () => {
203 let currentUrl = window.location.href;
204 const hasParams = currentUrl.includes('?');
205 if (hasParams) {
206 currentUrl = currentUrl.split('?')[0];
207 }
208 return currentUrl;
209 };
210 const lpAddQueryArgs = (endpoint, args) => {
211 const url = new URL(endpoint);
212 Object.keys(args).forEach(arg => {
213 url.searchParams.set(arg, args[arg]);
214 });
215 return url;
216 };
217
218 /**
219 * Listen element viewed.
220 *
221 * @param el
222 * @param callback
223 * @since 4.2.5.8
224 */
225 const listenElementViewed = (el, callback) => {
226 const observerSeeItem = new IntersectionObserver(function (entries) {
227 for (const entry of entries) {
228 if (entry.isIntersecting) {
229 callback(entry);
230 }
231 }
232 });
233 observerSeeItem.observe(el);
234 };
235
236 /**
237 * Listen element created.
238 *
239 * @param callback
240 * @since 4.2.5.8
241 */
242 const listenElementCreated = callback => {
243 const observerCreateItem = new MutationObserver(function (mutations) {
244 mutations.forEach(function (mutation) {
245 if (mutation.addedNodes) {
246 mutation.addedNodes.forEach(function (node) {
247 if (node.nodeType === 1) {
248 callback(node);
249 }
250 });
251 }
252 });
253 });
254 observerCreateItem.observe(document, {
255 childList: true,
256 subtree: true
257 });
258 // End.
259 };
260
261 /**
262 * Listen element created.
263 *
264 * @param selector
265 * @param callback
266 * @since 4.2.7.1
267 */
268 const lpOnElementReady = (selector, callback) => {
269 const element = document.querySelector(selector);
270 if (element) {
271 callback(element);
272 return;
273 }
274 const observer = new MutationObserver((mutations, obs) => {
275 const element = document.querySelector(selector);
276 if (element) {
277 obs.disconnect();
278 callback(element);
279 }
280 });
281 observer.observe(document.documentElement, {
282 childList: true,
283 subtree: true
284 });
285 };
286
287 // Parse JSON from string with content include LP_AJAX_START.
288 const lpAjaxParseJsonOld = data => {
289 if (typeof data !== 'string') {
290 return data;
291 }
292 const m = String.raw({
293 raw: data
294 }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s);
295 try {
296 if (m) {
297 data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, ''));
298 } else {
299 data = JSON.parse(data);
300 }
301 } catch (e) {
302 data = {};
303 }
304 return data;
305 };
306
307 // status 0: hide, 1: show
308 const lpShowHideEl = (el, status = 0) => {
309 if (!el) {
310 return;
311 }
312 if (!status) {
313 el.classList.add(lpClassName.hidden);
314 } else {
315 el.classList.remove(lpClassName.hidden);
316 }
317 };
318
319 // status 0: hide, 1: show
320 const lpSetLoadingEl = (el, status) => {
321 if (!el) {
322 return;
323 }
324 if (!status) {
325 el.classList.remove(lpClassName.loading);
326 } else {
327 el.classList.add(lpClassName.loading);
328 }
329 };
330
331 // Toggle collapse section
332 const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => {
333 if (!elTriggerClassName) {
334 elTriggerClassName = lpClassName.elTriggerToggle;
335 }
336
337 // Exclude elements, which should not trigger the collapse toggle
338 if (elsExclude && elsExclude.length > 0) {
339 for (const elExclude of elsExclude) {
340 if (target.closest(elExclude)) {
341 return;
342 }
343 }
344 }
345 const elTrigger = target.closest(elTriggerClassName);
346 if (!elTrigger) {
347 return;
348 }
349 const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`);
350 if (!elSectionToggle) {
351 return;
352 }
353 elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`);
354 if ('function' === typeof callback) {
355 callback(elSectionToggle);
356 }
357 };
358
359
360 /***/ }
361
362 /******/ });
363 /************************************************************************/
364 /******/ // The module cache
365 /******/ const __webpack_module_cache__ = {};
366 /******/
367 /******/ // The require function
368 /******/ function __webpack_require__(moduleId) {
369 /******/ // Check if module is in cache
370 /******/ const cachedModule = __webpack_module_cache__[moduleId];
371 /******/ if (cachedModule !== undefined) {
372 /******/ return cachedModule.exports;
373 /******/ }
374 /******/ // Create a new module (and put it into the cache)
375 /******/ const module = __webpack_module_cache__[moduleId] = {
376 /******/ // no module.id needed
377 /******/ // no module.loaded needed
378 /******/ exports: {}
379 /******/ };
380 /******/
381 /******/ // Execute the module function
382 /******/ if (!(moduleId in __webpack_modules__)) {
383 /******/ delete __webpack_module_cache__[moduleId];
384 /******/ const e = new Error("Cannot find module '" + moduleId + "'");
385 /******/ e.code = 'MODULE_NOT_FOUND';
386 /******/ throw e;
387 /******/ }
388 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
389 /******/
390 /******/ // Return the exports of the module
391 /******/ return module.exports;
392 /******/ }
393 /******/
394 /************************************************************************/
395 /******/ /* webpack/runtime/define property getters */
396 /******/ (() => {
397 /******/ // define getter/value functions for harmony exports
398 /******/ __webpack_require__.d = (exports, definition) => {
399 /******/ if(Array.isArray(definition)) {
400 /******/ var i = 0;
401 /******/ while(i < definition.length) {
402 /******/ var key = definition[i++];
403 /******/ var binding = definition[i++];
404 /******/ if(!__webpack_require__.o(exports, key)) {
405 /******/ if(binding === 0) {
406 /******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
407 /******/ } else {
408 /******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
409 /******/ }
410 /******/ } else if(binding === 0) { i++; }
411 /******/ }
412 /******/ } else {
413 /******/ for(var key in definition) {
414 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
415 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
416 /******/ }
417 /******/ }
418 /******/ }
419 /******/ };
420 /******/ })();
421 /******/
422 /******/ /* webpack/runtime/hasOwnProperty shorthand */
423 /******/ (() => {
424 /******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
425 /******/ })();
426 /******/
427 /******/ /* webpack/runtime/make namespace object */
428 /******/ (() => {
429 /******/ // define __esModule on exports
430 /******/ __webpack_require__.r = (exports) => {
431 /******/ if(Symbol.toStringTag) {
432 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
433 /******/ }
434 /******/ Object.defineProperty(exports, '__esModule', { value: true });
435 /******/ };
436 /******/ })();
437 /******/
438 /************************************************************************/
439 let __webpack_exports__ = {};
440 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
441 (() => {
442 /*!****************************************************!*\
443 !*** ./assets/src/apps/js/frontend/instructors.js ***!
444 \****************************************************/
445 __webpack_require__.r(__webpack_exports__);
446 /* harmony import */ var _instructors_instructor_list__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./instructors/instructor-list */ "./assets/src/apps/js/frontend/instructors/instructor-list.js");
447
448 (0,_instructors_instructor_list__WEBPACK_IMPORTED_MODULE_0__["default"])();
449 })();
450
451 /******/ })()
452 ;
453 //# sourceMappingURL=instructors.js.map