UNPKG

1.68 kBJavaScriptView Raw
1/*!
2 * OpenUI5
3 * (c) Copyright 2009-2022 SAP SE or an SAP affiliate company.
4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5 */
6
7/*
8 * IMPORTANT: This is a private module, its API must not be used and is subject to change.
9 * Code other than the Core tests must not yet introduce dependencies to this module.
10 */
11
12/*global document, sap */
13(function() {
14
15 "use strict";
16
17 //extract base URL from script tag
18 var oScriptTag, mMatch, sBaseUrl;
19
20 oScriptTag = document.getElementById("sap-ui-bootstrap");
21 if (oScriptTag) {
22 mMatch = /^(?:.*\/)?resources\//.exec(oScriptTag.getAttribute("src"));
23 if (mMatch) {
24 sBaseUrl = mMatch[0];
25 }
26 }
27
28 if (sBaseUrl == null) {
29 throw new Error("sap-ui-boot.js: could not identify script tag!");
30 }
31
32 function loadScripts(urls, callback) {
33 var pending = urls.length,
34 errors = 0;
35
36 if (pending === 0) {
37 callback();
38 return;
39 }
40
41 function listener(e) {
42 pending--;
43 if ( e.type === 'error' ) {
44 errors++;
45 }
46 e.target.removeEventListener("load", listener);
47 e.target.removeEventListener("error", listener);
48 if ( pending === 0 && errors === 0 && callback ) {
49 callback();
50 }
51 }
52
53 for ( var i = 0; i < urls.length; i++ ) {
54 var script = document.createElement("script");
55 script.addEventListener("load", listener);
56 script.addEventListener("error", listener);
57 script.src = sBaseUrl + urls[i];
58 document.head.appendChild(script);
59 }
60 }
61
62 // cascade 1: the loader
63 loadScripts([
64 "ui5loader.js"
65 ], function() {
66 // cascade 2: the loader configuration script
67 sap.ui.loader.config({
68 async:true
69 });
70 loadScripts([
71 "ui5loader-autoconfig.js"
72 ]);
73 });
74
75}());