PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9.1
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.3.9.1, at assets/js/dist/frontend/instructors.js

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