Merge pull request #2493 from sbwalker/dev

fix JS Interop methods for includeScript and includeMeta
This commit is contained in:
Shaun Walker 2022-11-10 14:19:52 -05:00 committed by GitHub
commit 39a9968971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -60,13 +60,13 @@ namespace Oqtane.UI
} }
} }
public Task IncludeMeta(string id, string attribute, string name, string content, string key) public Task IncludeMeta(string id, string attribute, string name, string content)
{ {
try try
{ {
_jsRuntime.InvokeVoidAsync( _jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.includeMeta", "Oqtane.Interop.includeMeta",
id, attribute, name, content, key); id, attribute, name, content);
return Task.CompletedTask; return Task.CompletedTask;
} }
catch catch
@ -105,6 +105,7 @@ 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) public Task IncludeScript(string id, string src, string integrity, string crossorigin, string content, string location)
{ {
try try

View File

@ -27,14 +27,8 @@ Oqtane.Interop = {
document.title = title; document.title = title;
} }
}, },
includeMeta: function (id, attribute, name, content, key) { includeMeta: function (id, attribute, name, content) {
var meta; var meta = document.querySelector("meta[" + attribute + "=\"" + CSS.escape(name) + "\"]");
if (id !== "" && key === "id") {
meta = document.getElementById(id);
}
else {
meta = document.querySelector("meta[" + attribute + "=\"" + CSS.escape(name) + "\"]");
}
if (meta === null) { if (meta === null) {
meta = document.createElement("meta"); meta = document.createElement("meta");
meta.setAttribute(attribute, name); meta.setAttribute(attribute, name);
@ -120,7 +114,13 @@ Oqtane.Interop = {
} }
}, },
includeScript: function (id, src, integrity, crossorigin, content, location) { includeScript: function (id, src, integrity, crossorigin, content, location) {
var script = document.querySelector("script[src=\"" + CSS.escape(src) + "\"]"); var script;
if (src !== "") {
script = document.querySelector("script[src=\"" + CSS.escape(src) + "\"]");
}
else {
script = document.getElementById(id);
}
if (script === null) { if (script === null) {
script = document.createElement("script"); script = document.createElement("script");
if (id !== "") { if (id !== "") {