cmp-loader.js
22 lines
| 1 | function a8c_cmp_callback( data ) { |
| 2 | if ( data && data.scripts && Array.isArray( data.scripts ) ) { |
| 3 | if ( data.config ) { |
| 4 | let configurationScript = document.createElement( 'script' ); |
| 5 | configurationScript.id = 'cmp-configuration'; |
| 6 | configurationScript.type = 'application/configuration'; |
| 7 | configurationScript.innerHTML = JSON.stringify( data.config ); |
| 8 | |
| 9 | // Add the cmp-configuration script element to the document's body |
| 10 | document.head.appendChild( configurationScript ); |
| 11 | } |
| 12 | |
| 13 | // Load each cmp script |
| 14 | data.scripts.forEach( function ( scriptUrl ) { |
| 15 | let script = document.createElement( 'script' ); |
| 16 | script.src = scriptUrl; |
| 17 | document.head.appendChild( script ); |
| 18 | } ); |
| 19 | } |
| 20 | } |
| 21 | window.a8c_cmp_callback = a8c_cmp_callback; |
| 22 |