script reload improvements
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Models
|
||||
@ -13,7 +12,7 @@ namespace Oqtane.Models
|
||||
private string _url;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="ResourceType"/> so the Interop can properly create `script` or `link` tags
|
||||
/// A <see cref="ResourceType"/> to define the type of resource ie. Script or Stylesheet
|
||||
/// </summary>
|
||||
public ResourceType ResourceType { get; set; }
|
||||
|
||||
@ -45,7 +44,7 @@ namespace Oqtane.Models
|
||||
public string CrossOrigin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// For Scripts a Bundle can be used to identify dependencies and ordering in the script loading process
|
||||
/// For Scripts a Bundle can be used to identify dependencies and ordering in the script loading process (for Interactive rendering only)
|
||||
/// </summary>
|
||||
public string Bundle { get; set; }
|
||||
|
||||
@ -60,7 +59,7 @@ namespace Oqtane.Models
|
||||
public ResourceLocation Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allows specification of inline script - not applicable to Stylesheets
|
||||
/// For Scripts this allows for the specification of inline script - not applicable to Stylesheets
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
@ -70,9 +69,9 @@ namespace Oqtane.Models
|
||||
public string RenderMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that a script should be reloaded on every page transition - not applicable to Stylesheets
|
||||
/// Specifies how a script should be loaded in Static rendering - not applicable to Stylesheets
|
||||
/// </summary>
|
||||
public bool Reload { get; set; }
|
||||
public ResourceLoadBehavior LoadBehavior { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cusotm data-* attributes for scripts - not applicable to Stylesheets
|
||||
@ -96,7 +95,7 @@ namespace Oqtane.Models
|
||||
resource.Location = Location;
|
||||
resource.Content = Content;
|
||||
resource.RenderMode = RenderMode;
|
||||
resource.Reload = Reload;
|
||||
resource.LoadBehavior = LoadBehavior;
|
||||
resource.DataAttributes = new Dictionary<string, string>();
|
||||
if (DataAttributes != null && DataAttributes.Count > 0)
|
||||
{
|
||||
@ -125,5 +124,18 @@ namespace Oqtane.Models
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Reload is deprecated. Use LoadBehavior property instead for scripts.", false)]
|
||||
public bool Reload
|
||||
{
|
||||
get => (LoadBehavior == ResourceLoadBehavior.BlazorPageScript);
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
LoadBehavior = ResourceLoadBehavior.BlazorPageScript;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
|
||||
@ -27,6 +28,13 @@ namespace Oqtane.Models
|
||||
this.Type = Type;
|
||||
}
|
||||
|
||||
public Script(string Content, ResourceLoadBehavior LoadBehavior)
|
||||
{
|
||||
SetDefaults();
|
||||
this.Content = Content;
|
||||
this.LoadBehavior = LoadBehavior;
|
||||
}
|
||||
|
||||
public Script(string Src, string Integrity, string CrossOrigin)
|
||||
{
|
||||
SetDefaults();
|
||||
@ -35,6 +43,22 @@ namespace Oqtane.Models
|
||||
this.CrossOrigin = CrossOrigin;
|
||||
}
|
||||
|
||||
public Script(string Src, string Integrity, string CrossOrigin, string Type, string Content, ResourceLocation Location, string Bundle, ResourceLoadBehavior LoadBehavior, Dictionary<string, string> DataAttributes, string RenderMode)
|
||||
{
|
||||
SetDefaults();
|
||||
this.Url = Src;
|
||||
this.Integrity = Integrity;
|
||||
this.CrossOrigin = CrossOrigin;
|
||||
this.Type = Type;
|
||||
this.Content = Content;
|
||||
this.Location = Location;
|
||||
this.Bundle = Bundle;
|
||||
this.LoadBehavior = LoadBehavior;
|
||||
this.DataAttributes = DataAttributes;
|
||||
this.RenderMode = RenderMode;
|
||||
}
|
||||
|
||||
[Obsolete("This constructor is deprecated. Use constructor with LoadBehavior parameter instead.", false)]
|
||||
public Script(string Src, string Integrity, string CrossOrigin, string Type, string Content, ResourceLocation Location, string Bundle, bool Reload, Dictionary<string, string> DataAttributes, string RenderMode)
|
||||
{
|
||||
SetDefaults();
|
||||
@ -45,9 +69,10 @@ namespace Oqtane.Models
|
||||
this.Content = Content;
|
||||
this.Location = Location;
|
||||
this.Bundle = Bundle;
|
||||
this.Reload = Reload;
|
||||
this.LoadBehavior = (Reload) ? ResourceLoadBehavior.BlazorPageScript : ResourceLoadBehavior.Once;
|
||||
this.DataAttributes = DataAttributes;
|
||||
this.RenderMode = RenderMode;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user