utils.js
26 lines
| 1 | /** |
| 2 | * Loop through an Elementor element and apply the function. |
| 3 | * |
| 4 | * @param {any} element Elementor element. |
| 5 | * @param {*} applyFunc The function to apply on each child element. |
| 6 | */ |
| 7 | const loopElementorElement = ( element, applyFunc ) => { |
| 8 | applyFunc( element ); |
| 9 | |
| 10 | element?.elements?.forEach( ( item ) => { |
| 11 | loopElementorElement( item, applyFunc ); |
| 12 | } ); |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * Clean the template content from unnecessary data. |
| 17 | * |
| 18 | * @param {any} templateContent The template content. |
| 19 | * @param {Function} cleanFunc The function to apply on each element. |
| 20 | */ |
| 21 | export const cleanTemplateContent = ( templateContent, cleanFunc ) => { |
| 22 | templateContent?.content?.forEach?.( ( item ) => { |
| 23 | loopElementorElement( item, cleanFunc ); |
| 24 | } ); |
| 25 | }; |
| 26 |