-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptLoader.js
More file actions
35 lines (32 loc) · 1.48 KB
/
Copy pathScriptLoader.js
File metadata and controls
35 lines (32 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ----------------------------------------------- */
/* ----------------- Script Loader --------------- */
/* ----------------------------------------------- */
// This helps with loading scripts and debugging
// Pass in the path of the js file and an array of url segments on which to run this code
// EG loadScript("/CustomSpace/CustomExtension/CustomExtension.js",["ServiceRequest","Incident"]);
var loadScript = function(path, urls) {
urls.forEach(function(url) {
if (window.location.href.toLowerCase().indexOf(url.toLowerCase()) !== -1) { // Verify we are on the valid page
var result = $.Deferred(),
script = document.createElement("script");
script.async = "async";
script.type = "text/javascript";
script.src = path;
script.onload = script.onreadystatechange = function(_, isAbort) {
if (!script.readyState || /loaded|complete/.test(script.readyState)) {
if (isAbort)
result.reject();
else
result.resolve();
}
};
script.onerror = function() { result.reject(); };
$("head")[0].appendChild(script);
console.log("Loaded " + path)
return result.promise();
}
})
};
/* ----------------------------------------------- */
/* --------------- END Script Loader ------------- */
/* ----------------------------------------------- */