-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptCollection.cs
More file actions
51 lines (46 loc) · 2.58 KB
/
ScriptCollection.cs
File metadata and controls
51 lines (46 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
namespace OnTopic.Editor.AspNetCore.Models.ClientResources {
/*============================================================================================================================
| CLASS: SCRIPT COLLECTION
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Represents a collection of <see cref="ScriptResource"/> instances.
/// </summary>
public class ScriptCollection: ClientResourceCollection<ScriptResource> {
/*==========================================================================================================================
| METHOD: REGISTER
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Registers a client-side script, optionally placing it <paramref name="inHeader"/> or making sure it is <paramref name=
/// "isDeferred"/>.
/// </summary>
/// <param name="uri">The relative or absolute URL of the client-side script.</param>
/// <param name="inHeader">Specifies that the script should be placed in the HTML header, instead of the footer.</param>
/// <param name="isDeferred">
/// Specifies that the script execution should be deferred, instead of executed immediately.
/// </param>
public void Register(Uri uri, bool inHeader, bool isDeferred = true) {
if (!Contains(uri)) {
Add(
new() {
Url = uri,
InHeader = inHeader,
IsDeferred = isDeferred
}
);
}
}
/*==========================================================================================================================
| METHOD: GET RESOURCES
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Retrieves a collection of resources, optionally filtering by
/// </summary>
public ReadOnlyCollection<ScriptResource> GetResources(bool inHeader, bool? isDeferred = null) =>
new(GetResources().Where(r => r.InHeader == inHeader && (isDeferred is null || r.IsDeferred == isDeferred)).ToList());
}
}