@ -1,40 +1,53 @@
using Microsoft.AspNetCore.Mvc. ViewFeatures ;
using Microsoft.AspNetCore.Mvc. Rendering ;
using Microsoft.AspNetCore.Razor.TagHelpers ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
{
public class AbpModalTagHelperService : AbpTagHelperService < AbpModalTagHelper >
{
protected IHtmlGenerator HtmlGenerator { get ; }
public AbpModalTagHelperService ( IHtmlGenerator htmlGenerator )
{
HtmlGenerator = htmlGenerator ;
}
public override void Process ( TagHelperContext context , TagHelperOutput output )
{
public override async Task ProcessAsync ( TagHelperContext context , TagHelperOutput output )
{
output . TagName = null ;
output . PreContent . SetHtmlContent ( CreatePreContent ( output ) ) ;
output . PostContent . SetHtmlContent ( CreatePostContent ( ) ) ;
}
protected virtual string CreatePreContent ( TagHelperOutput output )
{
var sb = new StringBuilder ( ) ;
var childContent = await output . GetChildContentAsync ( ) ;
var attritubutes = output . Attributes . Select ( a = > " " + HtmlGenerator . Encode ( a . Name ) + "=\"" + HtmlGenerator . Encode ( a . Value ) + "\" " ) . ToList ( ) ;
var attritubutesAsJoin = string . Join ( " " , attritubutes . ToArray ( ) ) ;
sb . AppendLine ( "<div class=\"" + GetModalClasses ( ) + "\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\" " + attritubutesAsJoin + GetDataAttributes ( ) + ">" ) ;
sb . AppendLine ( " <div class=\"" + GetModalDialogClasses ( ) + "\" role=\"document\">" ) ;
sb . AppendLine ( " <div class=\"" + GetModalContentClasses ( ) + "\">" ) ;
return sb . ToString ( ) ;
Process ( context , output , childContent ) ;
}
protected virtual void Process ( TagHelperContext context , TagHelperOutput output , TagHelperContent content )
{
var modalContent = new TagBuilder ( "div" ) ;
modalContent . AddCssClass ( GetModalContentClasses ( ) ) ;
modalContent . InnerHtml . AppendHtml ( content ) ;
var modalDialog = new TagBuilder ( "div" ) ;
modalDialog . AddCssClass ( GetModalDialogClasses ( ) ) ;
modalDialog . Attributes . Add ( "role" , "document" ) ;
modalDialog . InnerHtml . AppendHtml ( modalContent ) ;
var modal = new TagBuilder ( "div" ) ;
modal . AddCssClass ( GetModalClasses ( ) ) ;
modal . Attributes . Add ( "tabindex" , "-1" ) ;
modal . Attributes . Add ( "role" , "dialog" ) ;
modal . Attributes . Add ( "aria-hidden" , "true" ) ;
foreach ( var attr in output . Attributes )
{
modal . Attributes . Add ( attr . Name , attr . Value . ToString ( ) ) ;
}
if ( TagHelper . Static = = true )
{
modal . Attributes . Add ( "data-backdrop" , "static" ) ;
}
modal . InnerHtml . AppendHtml ( modalDialog ) ;
output . Content . SetHtmlContent ( modal ) ;
}
protected virtual string GetModalClasses ( )
{
return "modal fade" ;
@ -63,25 +76,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
{
return "modal-content" ;
}
protected virtual string GetDataAttributes ( )
{
if ( TagHelper . Static = = true )
{
return "data-backdrop=\"static\" " ;
}
return string . Empty ;
}
protected virtual string CreatePostContent ( )
{
var sb = new StringBuilder ( ) ;
sb . AppendLine ( " </div>" ) ;
sb . AppendLine ( " </div>" ) ;
sb . AppendLine ( "</div>" ) ;
return sb . ToString ( ) ;
}
}
}