[Fixes #2788] Added a sample taghelper that handles IE conditional comments
This commit is contained in:
parent
6d365e9a32
commit
774219b2ef
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
|
|
||||||
|
namespace TagHelperSample.Web.Controllers
|
||||||
|
{
|
||||||
|
public class TagHelperController : Controller
|
||||||
|
{
|
||||||
|
public IActionResult ConditionalComment()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
namespace TagHelperSample.Web
|
||||||
|
{
|
||||||
|
public enum CommentMode
|
||||||
|
{
|
||||||
|
DownlevelHidden = 0,
|
||||||
|
|
||||||
|
DownlevelRevealed = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
|
|
||||||
|
namespace TagHelperSample.Web
|
||||||
|
{
|
||||||
|
[TargetElement("iecondition")]
|
||||||
|
public class ConditionalCommentTagHelper : TagHelper
|
||||||
|
{
|
||||||
|
public CommentMode Mode { get; set; }
|
||||||
|
|
||||||
|
public string Condition { get; set; }
|
||||||
|
|
||||||
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||||
|
{
|
||||||
|
output.TagName = null;
|
||||||
|
|
||||||
|
var modeModifier = string.Empty;
|
||||||
|
|
||||||
|
if (Mode == CommentMode.DownlevelHidden)
|
||||||
|
{
|
||||||
|
modeModifier = "--";
|
||||||
|
}
|
||||||
|
|
||||||
|
output.PreContent.Append("<!");
|
||||||
|
output.PreContent.Append(modeModifier);
|
||||||
|
output.PreContent.Append("[if ");
|
||||||
|
output.PreContent.Append(Condition);
|
||||||
|
output.PreContent.Append("]>");
|
||||||
|
|
||||||
|
output.PostContent.Append("<![endif]");
|
||||||
|
output.PostContent.Append(modeModifier);
|
||||||
|
output.PostContent.Append(">");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
@using TagHelperSample.Web
|
||||||
|
@addTagHelper "*, TagHelperSample.Web"
|
||||||
|
|
||||||
|
<iecondition mode="@CommentMode.DownlevelRevealed" condition="gt IE 7">
|
||||||
|
<p>Content visible to all browsers newer than Internet Explorer 7.</p>
|
||||||
|
</iecondition>
|
||||||
|
<iecondition mode="@CommentMode.DownlevelHidden" condition="IE 7">
|
||||||
|
<p>Content visible only to Internet Explorer 7 users.</p>
|
||||||
|
</iecondition>
|
||||||
Loading…
Reference in New Issue