Merge pull request #2821 from sbwalker/dev
handle id attribute automatically for headcontent inline scripts
This commit is contained in:
commit
af27c763e0
@ -134,7 +134,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags)" ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
@ -141,7 +141,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags)" ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
@ -105,7 +105,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute." ResourceKey="HeadContent">Head Content: </Label>
|
||||
<Label Class="col-sm-3" For="headcontent" HelpText="Optionally enter content to be included in the page head (ie. meta, link, or script tags)" ResourceKey="HeadContent">Head Content: </Label>
|
||||
<div class="col-sm-9">
|
||||
<textarea id="headcontent" class="form-control" @bind="@_headcontent" rows="3"></textarea>
|
||||
</div>
|
||||
|
@ -229,7 +229,7 @@
|
||||
<value>Appearance</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags)</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
@ -265,7 +265,7 @@
|
||||
<value>Clickable?</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags)</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
@ -355,7 +355,7 @@
|
||||
<value>Appearance</value>
|
||||
</data>
|
||||
<data name="HeadContent.HelpText" xml:space="preserve">
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags). Please note that inline script must include an id attribute.</value>
|
||||
<value>Optionally enter content to be included in the page head (ie. meta, link, or script tags)</value>
|
||||
</data>
|
||||
<data name="HeadContent.Text" xml:space="preserve">
|
||||
<value>Head Content:</value>
|
||||
|
@ -86,6 +86,7 @@
|
||||
if (PageState.Page.HeadContent != null && PageState.Page.HeadContent.Contains("<script"))
|
||||
{
|
||||
var interop = new Interop(JSRuntime);
|
||||
var count = 0;
|
||||
var index = PageState.Page.HeadContent.IndexOf("<script");
|
||||
while (index >= 0)
|
||||
{
|
||||
@ -128,6 +129,11 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if (id == "")
|
||||
{
|
||||
count += 1;
|
||||
id = $"page{PageState.Page.PageId}-script{count}";
|
||||
}
|
||||
index = script.IndexOf(">") + 1;
|
||||
await interop.IncludeScript(id, "", "", "", script.Substring(index, script.IndexOf("</script>") - index), "head");
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ namespace Oqtane.Pages
|
||||
}
|
||||
if (!string.IsNullOrEmpty(site.HeadContent))
|
||||
{
|
||||
ProcessHeadContent(site.HeadContent);
|
||||
ProcessHeadContent(site.HeadContent, "site");
|
||||
}
|
||||
var ThemeType = site.DefaultThemeType;
|
||||
|
||||
@ -170,7 +170,7 @@ namespace Oqtane.Pages
|
||||
}
|
||||
}
|
||||
|
||||
ProcessHeadContent(page.HeadContent);
|
||||
ProcessHeadContent(page.HeadContent, $"page{page.PageId}");
|
||||
|
||||
// include global resources
|
||||
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
|
||||
@ -382,15 +382,24 @@ namespace Oqtane.Pages
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessHeadContent(string headcontent)
|
||||
private void ProcessHeadContent(string headcontent, string id)
|
||||
{
|
||||
// iterate scripts
|
||||
if (headcontent != null)
|
||||
{
|
||||
var count = 0;
|
||||
var index = headcontent.IndexOf("<script");
|
||||
while (index >= 0)
|
||||
{
|
||||
HeadResources += headcontent.Substring(index, headcontent.IndexOf("</script>", index) + 9 - index) + Environment.NewLine;
|
||||
var script = headcontent.Substring(index, headcontent.IndexOf("</script>", index) + 9 - index);
|
||||
if (!script.Contains("src=") && !script.Contains("id="))
|
||||
{
|
||||
count += 1;
|
||||
id += $"-script{count}";
|
||||
script = script.Replace("<script", $"<script id=\"{id}\"");
|
||||
index += id.Length;
|
||||
}
|
||||
HeadResources += script + Environment.NewLine;
|
||||
index = headcontent.IndexOf("<script", index + 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user