MCPcopy
hub / github.com/winjs/winjs / addScript

Function addScript

src/js/WinJS/Fragments.js:36–86  ·  view source on GitHub ↗
(scriptTag, fragmentHref, position, lastNonInlineScriptPromise)

Source from the content-addressed store, hash-verified

34 var uniqueId = 1;
35
36 function addScript(scriptTag, fragmentHref, position, lastNonInlineScriptPromise) {
37 // We synthesize a name for inline scripts because today we put the
38 // inline scripts in the same processing pipeline as src scripts. If
39 // we seperated inline scripts into their own logic, we could simplify
40 // this somewhat.
41 //
42 var src = scriptTag.src;
43 var inline = !src;
44 if (inline) {
45 src = fragmentHref + "script[" + position + "]";
46 }
47 src = src.toLowerCase();
48
49 if (!(src in scripts)) {
50 var promise = null;
51
52 scripts[src] = true;
53 var n = _Global.document.createElement("script");
54 if (scriptTag.language) {
55 n.setAttribute("language", "javascript");
56 }
57 n.setAttribute("type", scriptTag.type);
58 n.setAttribute("async", "false");
59 if (scriptTag.id) {
60 n.setAttribute("id", scriptTag.id);
61 }
62 if (inline) {
63 var text = scriptTag.text;
64 promise = lastNonInlineScriptPromise.then(function () {
65 n.text = text;
66 }).then(null, function () {
67 // eat error
68 });
69 } else {
70 promise = new Promise(function (c) {
71 n.onload = n.onerror = function () {
72 c();
73 };
74
75 // Using scriptTag.src to maintain the original casing
76 n.setAttribute("src", scriptTag.src);
77 });
78 }
79 head.appendChild(n);
80
81 return {
82 promise: promise,
83 inline: inline,
84 };
85 }
86 }
87
88 function addStyle(styleTag, fragmentHref, position) {
89 var src = (fragmentHref + "script[" + position + "]").toLowerCase();

Callers 1

processDocumentFunction · 0.85

Calls 5

toLowerCaseMethod · 0.80
createElementMethod · 0.80
appendChildMethod · 0.80
setAttributeMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected