1$Lightning = $Lightning || {}; 2$Lightning._delegate = (function() { 3 4 // private state 5 var _application, _applicationTag, _auraContextCallback; 6 var _pendingReadyRequests = []; 7 const _error = []; 8 var _ready = false; 9 var _previousRequestAuthToken; 10 11 function ready(callback) { 12 if (_ready) { 13 _auraContextCallback(callback); 14 } else { 15 _pendingReadyRequests.push(callback); 16 } 17 }; 18 19 function initAbsoluteGVP(absoluteUrl) { 20 var initGVP = function(url) { 21 var prefix = "$Absolute"; 22 if (!$A.getContext() || !$A.get(prefix)) { 23 $A.addValueProvider(prefix, { url : url}); 24 } 25 } 26 27 if (window.Aura && window.Aura.frameworkJsReady) { 28 initGVP(absoluteUrl); 29 } else { 30 var Aura = window.Aura || (window.Aura={}); 31 Aura.beforeFrameworkInit = Aura.beforeFrameworkInit || [], window.Aura.beforeFrameworkInit.push(initGVP(absoluteUrl)); 32 } 33 }; 34 35 function addScripts(urls, onload) { 36 var head = document.getElementsByTagName("HEAD")[0]; 37 for (var i = 0; i < urls.length; i++) { 38 var script = document.createElement("SCRIPT"); 39 script.type = "text/javascript"; 40 if (typeof urls[i] === "string") { 41 script.src = urls[i]; 42 } else { 43 script.src = urls[i]["url"]; 44 var crossorigin = urls[i]["crossorigin"]; 45 if (crossorigin) { 46 script.setAttribute("crossorigin", crossorigin); 47 } 48 } 49 50 script.async = false; 51 script.onerror = logError; 52 if (i == urls.length - 1) { 53 script.onload = onload; 54 } 55 head.appendChild(script); 56 } 57 }; 58 59 function addAsyncScripts(urls) { 60 var head = document.getElementsByTagName("HEAD")[0]; 61 for (var i = 0; i < urls.length; i++) { 62 var script = document.createElement("SCRIPT"); 63 script.type = "text/javascript"; 64 script.setAttribute("data-src", urls[i]); 65 head.appendChild(script); 66 } 67 }; 68 69 function addStyle(url) { 70 var link = document.createElement("LINK"); 71 link.setAttribute("data-href", url); 72 link.type = "text/css"; 73 link.rel = "stylesheet"; 74 link.classList.add("auraCss"); 75 link.onerror = logError; 76 var head = document.getElementsByTagName("HEAD")[0]; 77 head.appendChild(link); 78 }; 79 80 function logError(error) { 81 var targetURI; 82 // for <script> tags, targetURI is the src attribute 83 if (typeof error.target.src !== "undefined") { 84 targetURI = error.target.src; 85 } else { 86 // for <link> tags, targetURI is the href attribute 87 targetURI = error.target.href; 88 } 89 _error.push(targetURI); 90 } 91 92 async function reportScriptError(callback, timeout, count) { 93 /* 94 * call $A.reportError to send gack to server and log error in the console when $A finishedInit 95 * After certain times of check, if $A is still not finishedInit, will stop checking and reportError 96 */ 97 98 while ((!$A.finishedInit) && (count > 0)) { 99 count--; 100 await sleep(timeout); 101 } 102 callback(); 103 } 104 105 function sleep(ms) { 106 return new Promise(resolve => setTimeout(resolve, ms)); 107 } 108 109 function displayErrorText(error) { 110 var para = document.createElement("P"); 111 var lines = error.split("\\n"); 112 for (var n = 0; n < lines.length; n++) { 113 var t = document.createTextNode(lines[n]); 114 para.appendChild(t); 115 var br = document.createElement("BR"); 116 para.appendChild(br); 117 } 118 119 document.body.appendChild(para); 120 }; 121 122 function requestApp(applicationTag, lightningEndPointURI, authToken, paramsObj, callback) { 123 var parts = applicationTag.split(":"); 124 125 var url = parts[0] + "/" + parts[1] + ".app?aura.format=JSON&aura.formatAdapter=LIGHTNING_OUT"; 126 127 if (paramsObj) { 128 url = url + "&" + Object.keys(paramsObj).map(function(key, index) { 129 return key + "=" + paramsObj[key]; 130 }).join("&"); 131 } 132 133 if (lightningEndPointURI) { 134 url = lightningEndPointURI + "/" + url; 135 } else { 136 // Extract the base path from our own <script> include to adjust for LC4VF/Communities/Sites 137 var scripts = document.getElementsByTagName("script"); 138 for (var m = 0; m < scripts.length; m++) { 139 var script = scripts[m].src; 140 var i = script.indexOf("/lightning/lightning.out.js"); 141 if (i >= 0) { 142 var basePath = script.substring(0, i); 143 url = basePath + "/" + url; 144 break; 145 } 146 } 147 } 148 149 var xhr = new XMLHttpRequest(); 150 151 xhr.onreadystatechange = function() { 152 if (xhr.readyState == 4 && xhr.status == 200) { 153 callback(xhr); 154 } 155 }; 156 157 xhr.open("GET", url, true); 158 159 if(authToken || paramsObj) { 160 xhr.withCredentials = true; 161 } 162 if(authToken) { 163 xhr.setRequestHeader("Authorization", "OAuth " + authToken); 164 _previousRequestAuthToken = authToken; 165 } 166 167 xhr.send(); 168 }; 169 170 return { 171 use: function(applicationTag, callback, lightningEndPointURI, authToken, paramsObj) { 172 if(_applicationTag && _applicationTag !== applicationTag) { 173 throw new Error("$Lightning.use() already invoked with application: " + _applicationTag); 174 } 175 176 if(!_applicationTag) { 177 _applicationTag = applicationTag; 178 _pendingReadyRequests = []; 179 _ready = false;
180 181 requestApp(applicationTag, lightningEndPointURI, authToken, paramsObj, function(xhr) { 182 var errorMarker = xhr.responseText.indexOf("/*ERROR*/"); 183 if (errorMarker == -1) { 184 var config = JSON.parse(xhr.responseText), 185 cn = config.auraConfig && config.auraConfig["eikoocnekot"]; 186 if (cn) { 187 // Read cookie and convert it to the token config value. This is being done early so the cookie is deleted and reduces the chance the cookie unnecessarily sent to the server with subsequent requests. 188 var cookies = "; " + document.cookie + ";", 189 value, 190 key = "; " + cn + "=", 191 begin = cookies.indexOf(key); 192 if (begin !== -1) { 193 var end = cookies.indexOf(";", begin + key.length); 194 value = cookies.substring(begin + key.length, end); 195 } 196 if (!value) { 197 throw new Error("Unable to read the Aura token from the response."); 198 } 199 config.auraConfig["token"] = value; 200 // Delete cookie 201 var cookie = cn + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/"; 202 if ((cn.indexOf("__Host-") === 0)) { 203 cookie += "; secure"; 204 } 205 document.cookie = cookie; 206 config.auraConfig["csrfV2"] = true; 207 delete config.auraConfig["eikoocnekot"] 208 } 209 210 // save the delegate version to local storage 211 try { 212 localStorage.lightningOutDelegateVersion = config.delegateVersion; 213 } catch (e) {} 214 215 addAsyncScripts(config.clientLibraries); 216 217 addScripts(config.scripts, function() { 218 if ((config.absoluteURL) && !$A.util.isEmpty(config.absoluteURL)) { 219 initAbsoluteGVP(config.absoluteURL); 220 } 221 222 if (config.auraConfig) { 223 setTimeout(function () { 224 $A.initAsync(config.auraConfig); 225 }, 0); 226 } else { 227 // Backward compatibility with 198 228 $A.initConfig(config.auraInitConfig, true); 229 $Lightning.lightningLoaded(); 230 } 231 232 if (_error.length > 0) { 233 reportScriptError(() => { 234 for (var n = 0; n < _error.length; n++) { 235 $A.reportError("lightningout:client-error:script-setup:" + _error[n]); 236 }}, 250, 5); 237 } 238 239 }); 240 241 var styles = config.styles; 242 for (var n = 0; n < styles.length; n++) { 243 addStyle(styles[n]); 244 } 245 } else { 246 // Strip aura servlet error markers 247 var startIndex = (xhr.responseText.startsWith("*/")) ? 2 : 0; 248 var jsonExcptn = xhr.responseText.substring(startIndex,errorMarker);
249 jsonExcptn = jsonExcptn.replace(/\\n/g, "\\\\n"); // preserve newlines inside json stringified values by escaping them 250 var exceptn = JSON.parse(jsonExcptn); 251 displayErrorText(exceptn.message); 252 } 253 }); 254 } else if(authToken !== _previousRequestAuthToken && $A !== undefined && $A !== null) { 255 // Update the CSRF token for the new authentication context. 256 requestApp(applicationTag, lightningEndPointURI, authToken, paramsObj, function(xhr) { 257 var config = JSON.parse(xhr.responseText); 258 if(config.auraConfig && config.auraConfig.token){ 259 $A.clientService.resetToken(config.auraConfig.token); 260 } 261 }); 262 } 263 264 if(callback) { 265 ready(callback); 266 } 267 }, 268 269 ready : ready, 270 271 createComponent : function(type, attributes, locator, callback) { 272 // Check to see if we know about the component - enforce aura:dependency 273 // is used to avoid silent performance killer 274 var unknownComponent; 275 try { 276 unknownComponent = $A.componentService.getDef(type) === undefined; 277 } catch (e) { 278 if ("Unknown component: markup://" + type === e.message) { 279 unknownComponent = true; 280 } else { 281 throw e; 282 } 283 } 284 285 if (unknownComponent) { 286 $A.warning("No component definition for " + type + " in the client registry - for best performance add <aura:dependency resource=\"" 287 + type + "\"/> to your extension of " 288 + _applicationTag + "."); 289 } 290 291 _auraContextCallback(function() { 292 var config = { 293 componentDef : "markup://" + type, 294 attributes : { 295 values : attributes 296 } 297 }; 298 299 $A.createComponent(type, attributes, function(component, status, statusMessage) { 300 var error = null; 301 302 var stringLocator = $A.util.isString(locator); 303 var hostEl = stringLocator ? document.getElementById(locator) : locator; 304 305 if (!hostEl) { 306 error = "Invalid locator specified - " 307 + (stringLocator ? "no element found in the DOM with id=" + locator : "locator element not provided"); 308 } else if (status !== "SUCCESS") { 309 error = statusMessage; 310 } 311 312 if (error) { 313 throw new Error(error); 314 } 315 316 $A.util.addClass(hostEl,"slds-scope"); 317 $A.render(component, hostEl); 318 $A.afterRender(component); 319 320 hostEl.setAttribute("data-ltngout-rendered-by", component.getGlobalId()); 321 322 if (callback) { 323 try { 324 callback(component, status, statusMessage); 325 } catch (e) { 326 // Associate any callback error with the lightning out component being created to facilitate proper gack suppression 327 if (!(e instanceof $A.$auraError$)) { 328 e = new $A.$auraError$(null, e); 329 } 330 e.component = type; 331 e.componentStack = e.componentStack.concat(" > ", "[", type, "]"); 332 $A.reportError("Lightning out App error in callback function", e); 333 } 334 } 335 }); 336 }); 337 }, 338 339 lightningLoaded : function(application, auraContextCallback) { 340 if (!_application) { 341 _application = application; 342 _auraContextCallback = auraContextCallback; 343 344 if (!document.getElementById("auraErrorMessage")) { 345 var div = document.createElement("DIV"); 346 div.id = "auraErrorMessage"; 347 document.body.appendChild(div); 348 } 349 350 for (var n = 0; n < _pendingReadyRequests.length; n++) { 351 _pendingReadyRequests[n](); 352 } 353 354 _ready = true; 355 } 356 }, 357 358 getApplication : function() { 359 return _application; 360 } 361 }; 362})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.