-
Notifications
You must be signed in to change notification settings - Fork 4
Magic Line
Andre Kless edited this page Dec 18, 2019
·
1 revision
let b="ccm."+component.name+(component.version?"-"+component.version.join("."):"")+".js";if(window.ccm&&null===window.ccm.files[b])return window.ccm.files[b]=component;(b=window.ccm&&window.ccm.components[component.name])&&b.ccm&&(component.ccm=b.ccm);"string"===typeof component.ccm&&(component.ccm={url:component.ccm});let c=(component.ccm.url.match(/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/)||["latest"])[0];if(window.ccm&&window.ccm[c])window.ccm[c].component(component);else{var a=document.createElement("script");document.head.appendChild(a);component.ccm.integrity&&a.setAttribute("integrity",component.ccm.integrity);component.ccm.crossorigin&&a.setAttribute("crossorigin",component.ccm.crossorigin);a.onload=function(){window.ccm[c].component(component);document.head.removeChild(a)};a.src=component.ccm.url}
( function () {
const component = { /*...*/ };
// file is loaded via ccm.load call? => set result
const filename = 'ccm.' + component.name + ( component.version ? '-' + component.version.join( '.' ) : '' ) + '.js';
if ( window.ccm && window.ccm.files[ filename ] === null ) return window.ccm.files[ filename ] = component;
// global component namespace contains information about ccm framework version to be used? => change component used ccm framework version
const namespace = window.ccm && window.ccm.components[ component.name ];
if ( namespace && namespace.ccm ) component.ccm = namespace.ccm;
// load needed framework version (if not already present)
if ( typeof component.ccm === 'string' ) namespace.ccm = { ccm: namespace.ccm };
const version = ( component.ccm.url.match( /(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ ) || [ 'latest' ] )[ 0 ];
if ( !window.ccm || !window.ccm[ version ] ) {
const element = document.createElement( 'script' );
document.head.appendChild( element );
if ( component.ccm.integrity ) element.setAttribute( 'integrity', component.ccm.integrity );
if ( component.ccm.crossorigin ) element.setAttribute( 'crossorigin', component.ccm.crossorigin );
element.onload = () => { proceed(); document.head.removeChild( element ); };
element.src = component.ccm.url;
}
else proceed();
/** called when needed ccm framework version is present */
function proceed() {
window.ccm[ version ].component( component ); // register component in framework
}
} )();