PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.2
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 / src / apps / js / admin / admin-notices.js

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

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 let elLPAdminNotices = null;
2 let elBtnDismiss;
3 let dataHtml = null;
4 const queryString = window.location.search;
5 const urlParams = new URLSearchParams( queryString );
6 const tab = urlParams.get( 'tab' );
7 const urlApiAdminNotices = lpGlobalSettings.rest + 'lp/v1/admin/tools/admin-notices';
8
9 const callAdminNotices = ( set = '' ) => {
10 const params = tab ? `?tab=${ tab }` : `?${ set }`;
11 fetch( urlApiAdminNotices + params, {
12 method: 'GET',
13 } ).then( ( res ) =>
14 res.json()
15 ).then( ( res ) => {
16 // console.log(data);
17
18 const { status, message, data } = res;
19 if ( status === 'success' ) {
20 dataHtml = data.content;
21
22 if ( dataHtml.length === 0 && elLPAdminNotices ) {
23 elLPAdminNotices.style.display = 'none';
24 }
25 } else {
26 dataHtml = message;
27 }
28 } ).catch( ( err ) => {
29 console.log( err );
30 } );
31 };
32 callAdminNotices();
33
34 /*** DOMContentLoaded ***/
35 document.addEventListener( 'DOMContentLoaded', () => {
36 elLPAdminNotices = document.querySelector( '.lp-admin-notices' );
37 elBtnDismiss = document.querySelector( '.btn-lp-notice-dismiss' );
38
39 const interval = setInterval( () => {
40 if ( dataHtml !== null ) {
41 if ( dataHtml.length > 0 ) {
42 elLPAdminNotices.innerHTML = dataHtml;
43 elLPAdminNotices.style.display = 'block';
44 }
45
46 clearInterval( interval );
47 }
48 }, 1 );
49 } );
50
51 /*** Events ***/
52 document.addEventListener( 'click', ( e ) => {
53 const el = e.target;
54
55 if ( el.classList.contains( 'btn-lp-notice-dismiss' ) ) {
56 e.preventDefault();
57
58 // eslint-disable-next-line no-alert
59 if ( confirm( 'Are you sure you want to dismiss this notice?' ) ) {
60 const parent = el.closest( '.lp-admin-notice' );
61 callAdminNotices( `dismiss=${ el.getAttribute( 'data-dismiss' ) }` );
62 parent.remove();
63 if ( elLPAdminNotices.querySelectorAll( '.lp-admin-notice' ).length === 0 ) {
64 elLPAdminNotices.style.display = 'none';
65 }
66 }
67 }
68 } );
69