Skip to content

Commit

Permalink
Create ScriptTagHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
salihozkara committed May 16, 2024
1 parent 95ede64 commit 46241bc
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers;

namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers;

[HtmlTargetElement("script")]
public class ScriptTagHelper : AbpTagHelper
{
protected AbpBundlingOptions Options { get; }

[HtmlAttributeName("src")]
public string Src { get; set; } = default!;

public ScriptTagHelper(IOptions<AbpBundlingOptions> options)
{
Options = options.Value;
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (Options.DeferScriptsByDefault)
{
output.Attributes.Add("defer", "");
}

if (!Src.IsNullOrWhiteSpace() && Options.DeferScripts.Any(x => Src.Equals(x, StringComparison.OrdinalIgnoreCase)))
{
output.Attributes.Add("defer", "");
}
}
}

0 comments on commit 46241bc

Please sign in to comment.