improved dynamic CSS handling

This commit is contained in:
Shaun Walker 2019-09-20 09:52:40 -04:00
parent c3ff9ff12b
commit ddf7cdbec7
4 changed files with 45 additions and 0 deletions

View File

@ -57,6 +57,21 @@ namespace Oqtane.Shared
} }
} }
public Task RemoveCSS(string filepattern)
{
try
{
jsRuntime.InvokeAsync<string>(
"interop.removeCSS",
filepattern);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
public ValueTask<string> GetElementByName(string name) public ValueTask<string> GetElementByName(string name)
{ {
try try

View File

@ -1,6 +1,8 @@
@using Oqtane.Shared @using Oqtane.Shared
@using Oqtane.Modules @using Oqtane.Modules
@using Microsoft.JSInterop
@namespace Oqtane.Shared @namespace Oqtane.Shared
@inject IJSRuntime jsRuntime
@DynamicComponent @DynamicComponent
@ -28,4 +30,12 @@
} }
}; };
} }
protected override async Task OnParametersSetAsync()
{
// remove any custom CSS
var interop = new Interop(jsRuntime);
await interop.RemoveCSS("Themes/");
await interop.RemoveCSS("Modules/");
}
} }

View File

@ -38,6 +38,16 @@ window.interop = {
head.appendChild(link); head.appendChild(link);
}, },
removeCSS: function (filePattern) {
var head = document.head;
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i++) {
var link = links[i];
if (link.rel === 'stylesheet' && link.href.includes(filePattern)) {
head.removeChild(link);
}
}
},
submitForm: function (path, fields) { submitForm: function (path, fields) {
const form = document.createElement('form'); const form = document.createElement('form');
form.method = 'post'; form.method = 'post';

View File

@ -38,6 +38,16 @@ window.interop = {
head.appendChild(link); head.appendChild(link);
}, },
removeCSS: function (filePattern) {
var head = document.head;
var links = document.getElementsByTagName("link");
for (var i = 0; i < links.length; i++) {
var link = links[i];
if (link.rel === 'stylesheet' && link.href.includes(filePattern)) {
head.removeChild(link);
}
}
},
submitForm: function (path, fields) { submitForm: function (path, fields) {
const form = document.createElement('form'); const form = document.createElement('form');
form.method = 'post'; form.method = 'post';