Merge pull request #2823 from sbwalker/dev
add support for type attribute in JSInterop IncludeScript
This commit is contained in:
commit
d16659890c
|
@ -92,12 +92,17 @@ namespace Oqtane.UI
|
|||
|
||||
// external scripts need to specify src, inline scripts need to specify id and content
|
||||
public Task IncludeScript(string id, string src, string integrity, string crossorigin, string content, string location)
|
||||
{
|
||||
return IncludeScript(id, src, integrity, crossorigin, "", content, location);
|
||||
}
|
||||
|
||||
public Task IncludeScript(string id, string src, string integrity, string crossorigin, string type, string content, string location)
|
||||
{
|
||||
try
|
||||
{
|
||||
_jsRuntime.InvokeVoidAsync(
|
||||
"Oqtane.Interop.includeScript",
|
||||
id, src, integrity, crossorigin, content, location);
|
||||
id, src, integrity, crossorigin, type, content, location);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch
|
||||
|
|
|
@ -84,10 +84,10 @@
|
|||
var script = PageState.Page.HeadContent.Substring(index, PageState.Page.HeadContent.IndexOf("</script>", index) + 9 - index);
|
||||
var attributes = script.Substring(0, script.IndexOf(">")).Replace("\"", "").Split(" ");
|
||||
string id = "";
|
||||
string url = "";
|
||||
string src = "";
|
||||
string integrity = "";
|
||||
string crossorigin = "";
|
||||
bool es6module = false;
|
||||
string type = "";
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.Contains("="))
|
||||
|
@ -99,7 +99,7 @@
|
|||
id = value[1];
|
||||
break;
|
||||
case "src":
|
||||
url = value[1];
|
||||
src = value[1];
|
||||
break;
|
||||
case "integrity":
|
||||
integrity = value[1];
|
||||
|
@ -108,15 +108,15 @@
|
|||
crossorigin = value[1];
|
||||
break;
|
||||
case "type":
|
||||
es6module = (value[1] == "module");
|
||||
type = value[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
if (!string.IsNullOrEmpty(src))
|
||||
{
|
||||
url = (url.Contains("://")) ? url : PageState.Alias.BaseUrl + url;
|
||||
await interop.IncludeScript(id, url, integrity, crossorigin, "", "head");
|
||||
src = (src.Contains("://")) ? src : PageState.Alias.BaseUrl + src;
|
||||
await interop.IncludeScript(id, src, integrity, crossorigin, type, "", "head");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -108,7 +108,7 @@ Oqtane.Interop = {
|
|||
}
|
||||
}
|
||||
},
|
||||
includeScript: function (id, src, integrity, crossorigin, content, location) {
|
||||
includeScript: function (id, src, integrity, crossorigin, type, content, location) {
|
||||
var script;
|
||||
if (src !== "") {
|
||||
script = document.querySelector("script[src=\"" + CSS.escape(src) + "\"]");
|
||||
|
@ -121,6 +121,9 @@ Oqtane.Interop = {
|
|||
if (id !== "") {
|
||||
script.id = id;
|
||||
}
|
||||
if (type !== "") {
|
||||
script.type = type;
|
||||
}
|
||||
if (src !== "") {
|
||||
script.src = src;
|
||||
if (integrity !== "") {
|
||||
|
@ -146,6 +149,13 @@ Oqtane.Interop = {
|
|||
if (script.id !== id) {
|
||||
script.setAttribute('id', id);
|
||||
}
|
||||
if (type !== "") {
|
||||
if (script.type !== type) {
|
||||
script.setAttribute('type', type);
|
||||
}
|
||||
} else {
|
||||
script.removeAttribute('type');
|
||||
}
|
||||
if (src !== "") {
|
||||
if (script.src !== this.getAbsoluteUrl(src)) {
|
||||
script.removeAttribute('integrity');
|
||||
|
|
Loading…
Reference in New Issue
Block a user