refactoring of #518 to simplify registration of scripts in modules and themes
This commit is contained in:
@ -4,6 +4,7 @@ using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.Themes
|
||||
@ -22,6 +23,23 @@ namespace Oqtane.Themes
|
||||
public virtual string Panes { get; set; }
|
||||
public virtual List<Resource> Resources { get; set; }
|
||||
|
||||
// base lifecycle method for handling JSInterop script registration
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
var interop = new Interop(JSRuntime);
|
||||
foreach (var resource in Resources.Where(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
await interop.LoadScript(resource.Url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// path method
|
||||
|
||||
public string ThemePath()
|
||||
@ -60,5 +78,10 @@ namespace Oqtane.Themes
|
||||
{
|
||||
return Utilities.EditUrl(PageState.Alias.Path, path, moduleid, action, parameters);
|
||||
}
|
||||
|
||||
public string ContentUrl(int fileid)
|
||||
{
|
||||
return Utilities.ContentUrl(PageState.Alias, fileid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user