Skip to content

Commit

Permalink
= 4.2.6.5 =
Browse files Browse the repository at this point in the history
~ Tweak: load widgets js and call AJAX.
  • Loading branch information
tungnxt89 committed Apr 12, 2024
1 parent 04dfcd7 commit 85b1ec6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 15 additions & 3 deletions assets/src/js/frontend/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { lpFetchAPI } from '../utils';
import API from '../api';

function widgetRestAPI() {
const widgets = document.querySelectorAll( '.learnpress-widget-wrapper' );
const widgets = document.querySelectorAll( '.learnpress-widget-wrapper:not(.loaded)' );

if ( ! widgets.length ) {
return;
Expand Down Expand Up @@ -42,7 +42,10 @@ function widgetRestAPI() {
},
completed: () => {
//delete ele.dataset.widget;
ele.querySelector( '.lp-skeleton-animation' ).remove();
const elSkeleton = ele.querySelector( '.lp-skeleton-animation' );
if ( elSkeleton ) {
elSkeleton.remove();
}
},
};

Expand All @@ -51,12 +54,21 @@ function widgetRestAPI() {
};

widgets.forEach( ( ele ) => {
ele.classList.add( 'loaded' );
if ( ele.classList.contains( 'learnpress-widget-wrapper__restapi' ) ) {
getResponse( ele );
}
} );
}

document.addEventListener( 'DOMContentLoaded', function( event ) {
widgetRestAPI();

// Case 2: readystatechange, find all elements with the class '.lp-load-ajax-element' not have class 'loaded'
document.addEventListener( 'readystatechange', ( event ) => {
widgetRestAPI();
} );

// Case 3: DOMContentLoaded, find all elements with the class '.lp-load-ajax-element' not have class 'loaded'
document.addEventListener( 'DOMContentLoaded', () => {
widgetRestAPI();
} );
9 changes: 3 additions & 6 deletions inc/class-lp-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,12 @@ public function _get_scripts(): array {
),
'lp-widgets' => new LP_Asset_Key(
self::url( 'js/dist/frontend/widgets' . self::$_min_assets . '.js' ),
array_merge(
$wp_js,
array( 'wp-i18n' )
),
[],
array(),
1,
1,
0,
'',
[ 'strategy' => 'defer' ]
[ 'strategy' => 'async' ]
),
'lp-become-a-teacher' => new LP_Asset_Key(
self::url( 'js/dist/frontend/become-teacher' . self::$_min_assets . '.js' ),
Expand Down

0 comments on commit 85b1ec6

Please sign in to comment.