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 / admin / admin-notices.js

admin-notices.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9.1, at assets/js/dist/admin/admin-notices.js

600 lines 17.7 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/js/api.js"
6 /*!******************************!*\
7 !*** ./assets/src/js/api.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": () => (__WEBPACK_DEFAULT_EXPORT__)
14 /* harmony export */ });
15 /**
16 * List API on backend
17 *
18 * @since 4.2.6
19 * @version 1.0.2
20 */
21
22 const lplistAPI = {};
23 let lp_rest_url;
24 if ('undefined' !== typeof lpDataAdmin) {
25 lp_rest_url = lpDataAdmin.lp_rest_url;
26 lplistAPI.admin = {
27 apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices',
28 apiAddons: lp_rest_url + 'lp/v1/addon/all',
29 apiAddonAction: lp_rest_url + 'lp/v1/addon/action-n',
30 apiAddonsPurchase: lp_rest_url + 'lp/v1/addon/info-addons-purchase',
31 apiSearchCourses: lp_rest_url + 'lp/v1/admin/tools/search-course',
32 apiSearchUsers: lp_rest_url + 'lp/v1/admin/tools/search-user',
33 apiAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/assign-user-course',
34 apiUnAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/unassign-user-course'
35 };
36 }
37 if ('undefined' !== typeof lpData) {
38 lp_rest_url = lpData.lp_rest_url;
39 lplistAPI.frontend = {
40 apiWidgets: lp_rest_url + 'lp/v1/widgets/api',
41 apiCourses: lp_rest_url + 'lp/v1/courses/archive-course',
42 // Deprecated API, don't load from v4.3.7
43 apiAJAX: lp_rest_url + 'lp/v1/load_content_via_ajax/',
44 // Deprecated since 4.3.0
45 apiProfileCoverImage: lp_rest_url + 'lp/v1/profile/cover-image'
46 };
47 }
48 if (lp_rest_url) {
49 lplistAPI.apiCourses = lp_rest_url + 'lp/v1/courses/';
50 lplistAPI.apiEditCoursesArchiveBlock = lp_rest_url + 'lp/v1/courses/edit-archive-block';
51 lplistAPI.apiCoursesSuggest = lp_rest_url + 'lp/v1/courses/courses-suggest';
52 }
53 /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lplistAPI);
54
55 /***/ },
56
57 /***/ "./assets/src/js/utils.js"
58 /*!********************************!*\
59 !*** ./assets/src/js/utils.js ***!
60 \********************************/
61 (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
62
63 __webpack_require__.r(__webpack_exports__);
64 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
65 /* harmony export */ debounce: () => (/* binding */ debounce),
66 /* harmony export */ eventHandlers: () => (/* binding */ eventHandlers),
67 /* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm),
68 /* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm),
69 /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated),
70 /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed),
71 /* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs),
72 /* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld),
73 /* harmony export */ lpClassName: () => (/* binding */ lpClassName),
74 /* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI),
75 /* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam),
76 /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady),
77 /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl),
78 /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl),
79 /* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm),
80 /* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse)
81 /* harmony export */ });
82 /**
83 * Utils functions
84 *
85 * @param url
86 * @param data
87 * @param functions
88 * @since 4.2.5.1
89 * @version 1.0.6
90 */
91 const lpClassName = {
92 hidden: 'lp-hidden',
93 loading: 'loading',
94 elCollapse: 'lp-collapse',
95 elSectionToggle: '.lp-section-toggle',
96 elTriggerToggle: '.lp-trigger-toggle'
97 };
98 const lpFetchAPI = (url, data = {}, functions = {}) => {
99 if ('function' === typeof functions.before) {
100 functions.before();
101 }
102 fetch(url, {
103 method: 'GET',
104 ...data
105 }).then(response => response.json()).then(response => {
106 if ('function' === typeof functions.success) {
107 functions.success(response);
108 }
109 }).catch(err => {
110 if ('function' === typeof functions.error) {
111 functions.error(err);
112 }
113 }).finally(() => {
114 if ('function' === typeof functions.completed) {
115 functions.completed();
116 }
117 });
118 };
119
120 /**
121 * Get current URL without params.
122 *
123 * @since 4.2.5.1
124 */
125 const lpGetCurrentURLNoParam = () => {
126 let currentUrl = window.location.href;
127 const hasParams = currentUrl.includes('?');
128 if (hasParams) {
129 currentUrl = currentUrl.split('?')[0];
130 }
131 return currentUrl;
132 };
133 const lpAddQueryArgs = (endpoint, args) => {
134 const url = new URL(endpoint);
135 Object.keys(args).forEach(arg => {
136 url.searchParams.set(arg, args[arg]);
137 });
138 return url;
139 };
140
141 /**
142 * Listen element viewed.
143 *
144 * @param el
145 * @param callback
146 * @since 4.2.5.8
147 */
148 const listenElementViewed = (el, callback) => {
149 const observerSeeItem = new IntersectionObserver(function (entries) {
150 for (const entry of entries) {
151 if (entry.isIntersecting) {
152 callback(entry);
153 }
154 }
155 });
156 observerSeeItem.observe(el);
157 };
158
159 /**
160 * Listen element created.
161 *
162 * @param callback
163 * @since 4.2.5.8
164 */
165 const listenElementCreated = callback => {
166 const observerCreateItem = new MutationObserver(function (mutations) {
167 mutations.forEach(function (mutation) {
168 if (mutation.addedNodes) {
169 mutation.addedNodes.forEach(function (node) {
170 if (node.nodeType === 1) {
171 callback(node);
172 }
173 });
174 }
175 });
176 });
177 observerCreateItem.observe(document, {
178 childList: true,
179 subtree: true
180 });
181 // End.
182 };
183
184 /**
185 * Listen element created.
186 *
187 * @param selector
188 * @param callback
189 * @since 4.2.7.1
190 */
191 const lpOnElementReady = (selector, callback) => {
192 const element = document.querySelector(selector);
193 if (element) {
194 callback(element);
195 return;
196 }
197 const observer = new MutationObserver((mutations, obs) => {
198 const element = document.querySelector(selector);
199 if (element) {
200 obs.disconnect();
201 callback(element);
202 }
203 });
204 observer.observe(document.documentElement, {
205 childList: true,
206 subtree: true
207 });
208 };
209
210 // Parse JSON from string with content include LP_AJAX_START.
211 const lpAjaxParseJsonOld = data => {
212 if (typeof data !== 'string') {
213 return data;
214 }
215 const m = String.raw({
216 raw: data
217 }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s);
218 try {
219 if (m) {
220 data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, ''));
221 } else {
222 data = JSON.parse(data);
223 }
224 } catch (e) {
225 data = {};
226 }
227 return data;
228 };
229
230 // status 0: hide, 1: show
231 const lpShowHideEl = (el, status = 0) => {
232 if (!el) {
233 return;
234 }
235 if (!status) {
236 el.classList.add(lpClassName.hidden);
237 } else {
238 el.classList.remove(lpClassName.hidden);
239 }
240 };
241
242 // status 0: hide, 1: show
243 const lpSetLoadingEl = (el, status) => {
244 if (!el) {
245 return;
246 }
247 if (!status) {
248 el.classList.remove(lpClassName.loading);
249 } else {
250 el.classList.add(lpClassName.loading);
251 }
252 };
253
254 // Toggle collapse section
255 const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => {
256 if (!elTriggerClassName) {
257 elTriggerClassName = lpClassName.elTriggerToggle;
258 }
259
260 // Exclude elements, which should not trigger the collapse toggle
261 if (elsExclude && elsExclude.length > 0) {
262 for (const elExclude of elsExclude) {
263 if (target.closest(elExclude)) {
264 return;
265 }
266 }
267 }
268 const elTrigger = target.closest(elTriggerClassName);
269 if (!elTrigger) {
270 return;
271 }
272
273 //console.log( 'elTrigger', elTrigger );
274
275 const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`);
276 if (!elSectionToggle) {
277 return;
278 }
279 elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`);
280 if ('function' === typeof callback) {
281 callback(elSectionToggle);
282 }
283 };
284
285 // Get data of form
286 const getDataOfForm = form => {
287 const dataSend = {};
288 const formData = new FormData(form);
289 for (const pair of formData.entries()) {
290 const key = pair[0];
291 const value = formData.getAll(key);
292 if (!dataSend.hasOwnProperty(key)) {
293 // Convert value array to string.
294 dataSend[key] = value.join(',');
295 }
296 }
297 return dataSend;
298 };
299
300 // Get field keys of form
301 const getFieldKeysOfForm = form => {
302 const keys = [];
303 const elements = form.elements;
304 for (let i = 0; i < elements.length; i++) {
305 const name = elements[i].name;
306 if (name && !keys.includes(name)) {
307 keys.push(name);
308 }
309 }
310 return keys;
311 };
312
313 // Merge data handle with data form.
314 const mergeDataWithDatForm = (elForm, dataHandle) => {
315 const dataForm = getDataOfForm(elForm);
316 const keys = getFieldKeysOfForm(elForm);
317 keys.forEach(key => {
318 if (!dataForm.hasOwnProperty(key)) {
319 delete dataHandle[key];
320 } else if (dataForm[key][0] === '') {
321 delete dataForm[key];
322 delete dataHandle[key];
323 }
324 });
325 dataHandle = {
326 ...dataHandle,
327 ...dataForm
328 };
329 return dataHandle;
330 };
331
332 /**
333 * Event trigger
334 * For each list of event handlers, listen event on document.
335 *
336 * eventName: 'click', 'change', ...
337 * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ]
338 *
339 * @param eventName
340 * @param eventHandlers
341 */
342 const eventHandlers = (eventName, eventHandlers) => {
343 document.addEventListener(eventName, e => {
344 const target = e.target;
345 let args = {
346 e,
347 target
348 };
349 eventHandlers.forEach(eventHandler => {
350 args = {
351 ...args,
352 ...eventHandler
353 };
354
355 //console.log( args );
356
357 // Check condition before call back
358 if (eventHandler.conditionBeforeCallBack) {
359 if (eventHandler.conditionBeforeCallBack(args) !== true) {
360 return;
361 }
362 }
363
364 // Special check for keydown event with checkIsEventEnter = true
365 if (eventName === 'keydown' && eventHandler.checkIsEventEnter) {
366 if (e.key !== 'Enter') {
367 return;
368 }
369 }
370 if (target.closest(eventHandler.selector)) {
371 if (eventHandler.class) {
372 // Call method of class, function callBack will understand exactly {this} is class object.
373 eventHandler.class[eventHandler.callBack](args);
374 } else {
375 // For send args is objected, {this} is eventHandler object, not class object.
376 eventHandler.callBack(args);
377 }
378 }
379 });
380 });
381 };
382
383 /**
384 * Debounce - delays function execution until after `wait` ms of inactivity.
385 *
386 * Each call resets the timer. Only the last call in a burst executes.
387 *
388 * USE CASES:
389 * - Search inputs, form validation, window resize
390 * - Multiple elements need independent timers
391 * - When you need to call with different arguments
392 *
393 * EXAMPLES:
394 * const debouncedSearch = debounce( (query) => fetchResults(query), 300 );
395 * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value));
396 *
397 * const debouncedResize = debounce( recalculateLayout, 250 );
398 * window.addEventListener('resize', debouncedResize);
399 *
400 * ⚠️ Create ONCE outside event handlers, not inside.
401 *
402 * @param {Function} func - Function to debounce (can be anonymous)
403 * @param {number} wait - Milliseconds to wait (default: 500)
404 * @return {Function} Debounced wrapper function
405 * @since 4.3.7
406 * @version 1.0.0
407 */
408 const debounce = (func, wait = 500) => {
409 let timer;
410 return args => {
411 clearTimeout(timer);
412 timer = setTimeout(() => func(args), wait);
413 };
414 };
415
416 /***/ }
417
418 /******/ });
419 /************************************************************************/
420 /******/ // The module cache
421 /******/ var __webpack_module_cache__ = {};
422 /******/
423 /******/ // The require function
424 /******/ function __webpack_require__(moduleId) {
425 /******/ // Check if module is in cache
426 /******/ var cachedModule = __webpack_module_cache__[moduleId];
427 /******/ if (cachedModule !== undefined) {
428 /******/ return cachedModule.exports;
429 /******/ }
430 /******/ // Create a new module (and put it into the cache)
431 /******/ var module = __webpack_module_cache__[moduleId] = {
432 /******/ // no module.id needed
433 /******/ // no module.loaded needed
434 /******/ exports: {}
435 /******/ };
436 /******/
437 /******/ // Execute the module function
438 /******/ if (!(moduleId in __webpack_modules__)) {
439 /******/ delete __webpack_module_cache__[moduleId];
440 /******/ var e = new Error("Cannot find module '" + moduleId + "'");
441 /******/ e.code = 'MODULE_NOT_FOUND';
442 /******/ throw e;
443 /******/ }
444 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
445 /******/
446 /******/ // Return the exports of the module
447 /******/ return module.exports;
448 /******/ }
449 /******/
450 /************************************************************************/
451 /******/ /* webpack/runtime/define property getters */
452 /******/ (() => {
453 /******/ // define getter functions for harmony exports
454 /******/ __webpack_require__.d = (exports, definition) => {
455 /******/ for(var key in definition) {
456 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
457 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
458 /******/ }
459 /******/ }
460 /******/ };
461 /******/ })();
462 /******/
463 /******/ /* webpack/runtime/hasOwnProperty shorthand */
464 /******/ (() => {
465 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
466 /******/ })();
467 /******/
468 /******/ /* webpack/runtime/make namespace object */
469 /******/ (() => {
470 /******/ // define __esModule on exports
471 /******/ __webpack_require__.r = (exports) => {
472 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
473 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
474 /******/ }
475 /******/ Object.defineProperty(exports, '__esModule', { value: true });
476 /******/ };
477 /******/ })();
478 /******/
479 /************************************************************************/
480 var __webpack_exports__ = {};
481 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
482 (() => {
483 /*!**********************************************!*\
484 !*** ./assets/src/js/admin/admin-notices.js ***!
485 \**********************************************/
486 __webpack_require__.r(__webpack_exports__);
487 /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./assets/src/js/utils.js");
488 /* harmony import */ var _api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../api.js */ "./assets/src/js/api.js");
489 /**
490 * Script handle admin notices.
491 *
492 * @since 4.1.7.3.2
493 * @version 1.0.2
494 */
495
496
497 let elLPAdminNotices = null;
498 let dataHtml = null;
499 const queryString = window.location.search;
500 const urlParams = new URLSearchParams(queryString);
501 const tab = urlParams.get('tab');
502 const notifyAddonsNewVersion = () => {
503 try {
504 const elAdminMenu = document.querySelector('#adminmenu');
505 if (!elAdminMenu) {
506 return;
507 }
508 const elTabLP = elAdminMenu.querySelector('#toplevel_page_learn_press');
509 if (!elTabLP) {
510 return;
511 }
512 const elTabLPName = elTabLP.querySelector('.wp-menu-name');
513 if (!elTabLPName) {
514 return;
515 }
516 const elAddonsNewVerTotal = document.querySelector('input[name=lp-addons-new-version-totals]');
517 if (!elAddonsNewVerTotal) {
518 return;
519 }
520 const htmlNotifyLP = `<span class="tab-lp-admin-notice"></span>`;
521 elTabLPName.insertAdjacentHTML('beforeend', htmlNotifyLP);
522 const elTabLPAddons = elTabLP.querySelector('a[href="admin.php?page=learn-press-addons"]');
523 if (!elTabLPAddons) {
524 return;
525 }
526 const total = elAddonsNewVerTotal.value;
527 const html = `<span style="margin-left: 5px" class="update-plugins">${total}</span>`;
528 elTabLPAddons.setAttribute('href', 'admin.php?page=learn-press-addons&tab=update');
529 elTabLPAddons.insertAdjacentHTML('beforeend', html);
530 } catch (e) {
531 console.log(e);
532 }
533 };
534 const callAdminNotices = (set = '') => {
535 if (!lpGlobalSettings.is_admin) {
536 return;
537 }
538 let params = tab ? `?tab=${tab}` : '';
539 params += set ? (tab ? '&' : '?') + `${set}` : '';
540 fetch(_api_js__WEBPACK_IMPORTED_MODULE_1__["default"].admin.apiAdminNotice + params, {
541 method: 'POST',
542 headers: {
543 'X-WP-Nonce': lpGlobalSettings.nonce
544 }
545 }).then(res => res.json()).then(res => {
546 // console.log(data);
547
548 const {
549 status,
550 message,
551 data
552 } = res;
553 if (status === 'success') {
554 if ('Dismissed!' !== message) {
555 dataHtml = data.content;
556 if (dataHtml.length === 0) {
557 elLPAdminNotices.style.display = 'none';
558 } else {
559 elLPAdminNotices.innerHTML = dataHtml;
560 elLPAdminNotices.style.display = 'block';
561 // Handle notify addons new version.
562 notifyAddonsNewVersion();
563 }
564 }
565 } else {
566 dataHtml = message;
567 }
568 }).catch(err => {
569 console.log(err);
570 });
571 };
572
573 // Listen element ready
574 (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpOnElementReady)('.lp-admin-notices', () => {
575 elLPAdminNotices = document.querySelector('.lp-admin-notices');
576 callAdminNotices();
577 });
578
579 /*** Events ***/
580 document.addEventListener('click', e => {
581 const el = e.target;
582 if (el.classList.contains('btn-lp-notice-dismiss')) {
583 e.preventDefault();
584
585 // eslint-disable-next-line no-alert
586 if (confirm('Are you sure you want to dismiss this notice?')) {
587 const parent = el.closest('.lp-notice');
588 callAdminNotices(`dismiss=${el.getAttribute('data-dismiss')}`);
589 parent.remove();
590 if (elLPAdminNotices.querySelectorAll('.lp-notice').length === 0) {
591 elLPAdminNotices.style.display = 'none';
592 }
593 }
594 }
595 });
596 })();
597
598 /******/ })()
599 ;
600 //# sourceMappingURL=admin-notices.js.map