PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.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 / src / apps / js / admin / gutenberg / editor-check.js

editor-check.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.8, at assets/src/apps/js/admin/gutenberg/editor-check.js

50 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener( 'DOMContentLoaded', function () {
2 const validTemplates = [
3 'single-lp_course',
4 'archive-lp_course',
5 'taxonomy-course_tag',
6 'taxonomy-course_category',
7 ];
8
9 const getParamP = () => {
10 const urlParams = new URLSearchParams( window.location.search );
11 const paramP = urlParams.get( 'p' )?.replace( /^\/|\/$/g, '' );
12 return paramP === 'template' ? paramP : null;
13 };
14
15 const debounce = ( func, wait ) => {
16 let timeout;
17 return ( ...args ) => {
18 clearTimeout( timeout );
19 timeout = setTimeout( () => func( ...args ), wait );
20 };
21 };
22
23 let previousTemplate = null;
24 const checkAndReload = () => {
25 const currentTemplate =
26 wp?.data?.select( 'core/editor' )?.getEditedPostAttribute( 'slug' ) ||
27 wp?.data?.select( 'core/editor' )?.getCurrentPostId() ||
28 getParamP();
29
30 if ( ! currentTemplate || currentTemplate === previousTemplate ) return;
31
32 if (
33 currentTemplate !== 'home' &&
34 previousTemplate &&
35 previousTemplate !== currentTemplate &&
36 ( validTemplates.includes( currentTemplate ) || validTemplates.includes( previousTemplate ) )
37 ) {
38 window.location.reload();
39 }
40
41 previousTemplate = currentTemplate;
42 };
43
44 const debouncedCheckAndReload = debounce( checkAndReload, 200 );
45
46 wp?.data?.subscribe( () => {
47 debouncedCheckAndReload();
48 } );
49 } );
50