| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/*!************************************************************!*\ |
| 3 |
!*** ./assets/src/apps/js/admin/gutenberg/editor-check.js ***! |
| 4 |
\************************************************************/ |
| 5 |
document.addEventListener('DOMContentLoaded', function () { |
| 6 |
const validTemplates = ['single-lp_course', 'archive-lp_course', 'taxonomy-course_tag', 'taxonomy-course_category']; |
| 7 |
const getParamP = () => { |
| 8 |
const urlParams = new URLSearchParams(window.location.search); |
| 9 |
const paramP = urlParams.get('p')?.replace(/^\/|\/$/g, ''); |
| 10 |
return paramP === 'template' ? paramP : null; |
| 11 |
}; |
| 12 |
const debounce = (func, wait) => { |
| 13 |
let timeout; |
| 14 |
return (...args) => { |
| 15 |
clearTimeout(timeout); |
| 16 |
timeout = setTimeout(() => func(...args), wait); |
| 17 |
}; |
| 18 |
}; |
| 19 |
let previousTemplate = null; |
| 20 |
const checkAndReload = () => { |
| 21 |
const currentTemplate = wp?.data?.select('core/editor')?.getEditedPostAttribute('slug') || wp?.data?.select('core/editor')?.getCurrentPostId() || getParamP(); |
| 22 |
if (!currentTemplate || currentTemplate === previousTemplate) return; |
| 23 |
if (currentTemplate !== 'home' && previousTemplate && previousTemplate !== currentTemplate && (validTemplates.includes(currentTemplate) || validTemplates.includes(previousTemplate))) { |
| 24 |
window.location.reload(); |
| 25 |
} |
| 26 |
previousTemplate = currentTemplate; |
| 27 |
}; |
| 28 |
const debouncedCheckAndReload = debounce(checkAndReload, 200); |
| 29 |
wp?.data?.subscribe(() => { |
| 30 |
debouncedCheckAndReload(); |
| 31 |
}); |
| 32 |
}); |
| 33 |
/******/ })() |
| 34 |
; |
| 35 |
//# sourceMappingURL=editor-check.js.map |