Fix #3807: parsing the data attributes.
This commit is contained in:
parent
e36f13c595
commit
740b89258d
|
@ -145,6 +145,7 @@
|
|||
string integrity = "";
|
||||
string crossorigin = "";
|
||||
string type = "";
|
||||
var dataAttributes = new Dictionary<string, string>();
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
if (attribute.Contains("="))
|
||||
|
@ -167,6 +168,12 @@
|
|||
case "type":
|
||||
type = value[1];
|
||||
break;
|
||||
default:
|
||||
if(!string.IsNullOrWhiteSpace(value[0]) && value[0].StartsWith("data-"))
|
||||
{
|
||||
dataAttributes.Add(value[0], value[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +181,7 @@
|
|||
if (!string.IsNullOrEmpty(src))
|
||||
{
|
||||
src = (src.Contains("://")) ? src : PageState.Alias.BaseUrl + src;
|
||||
scripts.Add(new { href = src, bundle = "", integrity = integrity, crossorigin = crossorigin, es6module = (type == "module"), location = location.ToString().ToLower() });
|
||||
scripts.Add(new { href = src, bundle = "", integrity = integrity, crossorigin = crossorigin, es6module = (type == "module"), location = location.ToString().ToLower(), dataAttributes = dataAttributes });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -206,18 +206,25 @@ Oqtane.Interop = {
|
|||
returnPromise: true,
|
||||
before: function (path, element) {
|
||||
for (let s = 0; s < scripts.length; s++) {
|
||||
if (path === scripts[s].href && scripts[s].integrity !== '') {
|
||||
element.integrity = scripts[s].integrity;
|
||||
}
|
||||
if (path === scripts[s].href && scripts[s].crossorigin !== '') {
|
||||
element.crossOrigin = scripts[s].crossorigin;
|
||||
}
|
||||
if (path === scripts[s].href && scripts[s].es6module === true) {
|
||||
element.type = "module";
|
||||
}
|
||||
if (path === scripts[s].href && scripts[s].location === 'body') {
|
||||
document.body.appendChild(element);
|
||||
return false; // return false to bypass default DOM insertion mechanism
|
||||
if (path === scripts[s].href) {
|
||||
if (scripts[s].integrity !== '') {
|
||||
element.integrity = scripts[s].integrity;
|
||||
}
|
||||
if (scripts[s].crossorigin !== '') {
|
||||
element.crossOrigin = scripts[s].crossorigin;
|
||||
}
|
||||
if (scripts[s].es6module === true) {
|
||||
element.type = "module";
|
||||
}
|
||||
if (typeof scripts[s].dataAttributes !== "undefined" && scripts[s].dataAttributes !== null) {
|
||||
for (var key in scripts[s].dataAttributes) {
|
||||
element.setAttribute(key, scripts[s].dataAttributes[key]);
|
||||
}
|
||||
}
|
||||
if (scripts[s].location === 'body') {
|
||||
document.body.appendChild(element);
|
||||
return false; // return false to bypass default DOM insertion mechanism
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user