var imFilesToLoad = ["https://assets.phenompeople.com/CareerConnectResources/common/video-platform/js/1635252281835_vue.js"]; var imInstancesToKill = []; var imConfig = { "ex-succession-v1": { "PRODUCTION" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "PROD-US" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "PROD-MB" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "PROD-IR" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "PROD-AZ" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "PROD-CA" : { "scriptLink": "https://cdn.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE-AZ" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE-US" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE-IR" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE-MB" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "STAGE-CA" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/st/ex/scripts/ex-succession.min.js?r="+Date.now() }, "QA" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/q/ex/scripts/ex-succession.min.js?r="+Date.now() }, "QA-AZ" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/q/ex/scripts/ex-succession.min.js?r="+Date.now() }, "QA-US" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/q/ex/scripts/ex-succession.min.js?r="+Date.now() }, "QA2-US" : { "scriptLink": "https://pp-cdn.phenompeople.com/CareerConnectResources/q/ex/scripts/ex-succession.min.js?r="+Date.now() }, "FALLBACK" :{ "scriptLink": "https://assets.phenompeople.com/CareerConnectResources/ex/scripts/ex-succession.min.js?r="+Date.now() }, "component": "EXSuccession", "pluginComponent": "EXSuccession", "dependencies" : [{link : "https://unpkg.com/vue-i18n@8"}] } } function exPluginLoadScript(srcLoc, e, cb) { var tag = document.createElement("script"); tag.setAttribute("type", "text/javascript"); tag.setAttribute("src", srcLoc); document.head.appendChild(tag); tag.onload = cb; tag.onerror = function () { console.log('error', e); raisePluginErrorEvent(e) } } function raisePluginErrorEvent(e) { let data = { siteData: e.siteData, plugin: e.plugin, scriptLink: imConfig[e.plugin]['scriptLink'], apiPath: "vx-plugin-load-fail" } fetch(e.serverUrl, { method: 'post', body: JSON.stringify(data), headers: { authorization: "Bearer " + localStorage.getItem("CP_A_T") }, credentials: 'include' }).then(response => { console.error("Error in loading script" + e.plugin) } ) } var exBootstrapper = { initPluginBootstrapper: function (e) { loadImVueJs(imFilesToLoad[0], (res => { if (imConfig[e['plugin']]['dependencies']) { let dependencies = imConfig[e['plugin']]['dependencies']; loadIMDependencies(dependencies, e); } else { loadIMPluginScripts(e) } ; } )); } }; function loadIMDependencies(files, e) { if (files.length) { var srcLoc = files.splice(0, 1); if (srcLoc[0]['check'] && window[srcLoc[0]['check']]) { loadIMDependencies(files, e); } else if (window.require) { require([srcLoc[0]['link']], function (a) { loadIMDependencies(files, e); }) } else { var tag = document.createElement("script"); tag.setAttribute("type", "text/javascript"); tag.setAttribute("src", srcLoc[0]['link']); document.head.appendChild(tag); tag.onload = function (res) { loadIMDependencies(files, e); } ; tag.onerror = function (err) { console.log('error', e) raisePluginErrorEvent(e) } } } else { loadIMPluginScripts(e) } } function loadIMPluginScripts(e) { console.log(e); const ENVIRONMENT = e.siteData.env; let scriptLink = imConfig[e.plugin][ENVIRONMENT] && imConfig[e.plugin][ENVIRONMENT]["scriptLink"] ; if(!scriptLink){ scriptLink = imConfig[e.plugin]["FALLBACK"]["scriptLink"]; } exPluginLoadScript(scriptLink, e, async (res) => { if (window[imConfig[e['plugin']].pluginComponent]) { var componentName = imConfig[e.plugin]['component']; if (imConfig[e.plugin]['mode'] == 'dialog') { var ele = document.querySelector('body'); var newFirstElement = document.createElement("div"); var componentId = componentName + Math.ceil(Math.random() * 100000); newFirstElement.setAttribute("id", componentId); ele.insertBefore(newFirstElement, ele.firstChild); e.containerId = componentId; e.siteData['pluginInfo'] = { mode: 'dialog', componentId: componentId } } document.getElementById(e.containerId) && document.getElementById(e.containerId).classList.remove("hide"); document.getElementById(e.containerId).innerHTML = '<' + componentName + ' :site-data="$sitedata" :css-variables="$cssVariables" :go-back="$goBack" :server-url="$serverUrl">'; if (!e.innerPlugin) { imInstancesToKill.forEach(function (instance) { instance && instance._isVue && instance.$destroy(); }); } imInstancesToKill = []; Vue.use(VueI18n); const i18n = new VueI18n({ locale: 'en', messages : { en : {} } }); var vm = new Vue({i18n}); imInstancesToKill.push(vm); Vue.prototype.$sitedata = e.siteData; if (e && e.cssVariables) { Vue.prototype.$cssVariables = e.cssVariables; } Vue.prototype.$serverUrl = e.serverUrl; Vue.prototype.$goBack = function () { document.getElementById(e.containerId).innerHTML = '<' + componentName + ' :site-data="$sitedata" :css-variables="$cssVariables" :go-back="$goBack" :server-url="$serverUrl">'; document.getElementById(e.containerId) && document.getElementById(e.containerId).classList.add("hide"); // window.postMessage(JSON.stringify({ event: "exit-assessment-editor" }), "*"); } ; Vue.use(window[imConfig[e['plugin']].pluginComponent]); vm.$mount("#" + e.containerId); } else { setTimeout(() => { window.exBootstrapper.initPluginBootstrapper(e); } , 1000); } } ); } ; function loadImVueJs(url, cb) { if (window.Vue) { cb(); } else { var tag = document.createElement("script"); tag.setAttribute("type", "text/javascript"); tag.setAttribute("src", url); document.head.appendChild(tag); tag.onload = cb; } }