mirror of https://github.com/abpframework/abp.git
Browse Source
[dev-issue-6369]Added the "scrollable" feature for the Bootstrap Modal p…pull/6659/head
committed by
GitHub
2 changed files with 120 additions and 112 deletions
@ -1,112 +1,118 @@ |
|||||
using Microsoft.AspNetCore.Html; |
using Microsoft.AspNetCore.Html; |
||||
using Microsoft.AspNetCore.Mvc.Rendering; |
using Microsoft.AspNetCore.Mvc.Rendering; |
||||
using Microsoft.AspNetCore.Razor.TagHelpers; |
using Microsoft.AspNetCore.Razor.TagHelpers; |
||||
using System.Text; |
using System.Text; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal |
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal |
||||
{ |
{ |
||||
public class AbpModalTagHelperService : AbpTagHelperService<AbpModalTagHelper> |
public class AbpModalTagHelperService : AbpTagHelperService<AbpModalTagHelper> |
||||
{ |
{ |
||||
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
output.TagName = null; |
output.TagName = null; |
||||
|
|
||||
var childContent = await output.GetChildContentAsync(); |
var childContent = await output.GetChildContentAsync(); |
||||
|
|
||||
SetContent(context, output, childContent); |
SetContent(context, output, childContent); |
||||
} |
} |
||||
|
|
||||
protected virtual void SetContent(TagHelperContext context, TagHelperOutput output, TagHelperContent childContent) |
protected virtual void SetContent(TagHelperContext context, TagHelperOutput output, TagHelperContent childContent) |
||||
{ |
{ |
||||
var modalContent = GetModalContentElement(context, output, childContent); |
var modalContent = GetModalContentElement(context, output, childContent); |
||||
var modalDialog = GetModalDialogElement(context, output, modalContent); |
var modalDialog = GetModalDialogElement(context, output, modalContent); |
||||
var modal = GetModal(context, output, modalDialog); |
var modal = GetModal(context, output, modalDialog); |
||||
|
|
||||
output.Content.SetHtmlContent(modal); |
output.Content.SetHtmlContent(modal); |
||||
} |
} |
||||
|
|
||||
protected virtual TagBuilder GetModalContentElement(TagHelperContext context, TagHelperOutput output, TagHelperContent childContent) |
protected virtual TagBuilder GetModalContentElement(TagHelperContext context, TagHelperOutput output, TagHelperContent childContent) |
||||
{ |
{ |
||||
var element = new TagBuilder("div"); |
var element = new TagBuilder("div"); |
||||
element.AddCssClass(GetModalContentClasses()); |
element.AddCssClass(GetModalContentClasses()); |
||||
element.InnerHtml.SetHtmlContent(childContent); |
element.InnerHtml.SetHtmlContent(childContent); |
||||
return element; |
return element; |
||||
} |
} |
||||
|
|
||||
protected virtual TagBuilder GetModalDialogElement(TagHelperContext context, TagHelperOutput output, IHtmlContent innerHtml) |
protected virtual TagBuilder GetModalDialogElement(TagHelperContext context, TagHelperOutput output, IHtmlContent innerHtml) |
||||
{ |
{ |
||||
var element = new TagBuilder("div"); |
var element = new TagBuilder("div"); |
||||
element.AddCssClass(GetModalDialogClasses()); |
element.AddCssClass(GetModalDialogClasses()); |
||||
element.Attributes.Add("role", "document"); |
element.Attributes.Add("role", "document"); |
||||
element.InnerHtml.SetHtmlContent(innerHtml); |
element.InnerHtml.SetHtmlContent(innerHtml); |
||||
return element; |
return element; |
||||
} |
} |
||||
|
|
||||
protected virtual TagBuilder GetModal(TagHelperContext context, TagHelperOutput output, IHtmlContent innerHtml) |
protected virtual TagBuilder GetModal(TagHelperContext context, TagHelperOutput output, IHtmlContent innerHtml) |
||||
{ |
{ |
||||
var element = new TagBuilder("div"); |
var element = new TagBuilder("div"); |
||||
element.AddCssClass(GetModalClasses()); |
element.AddCssClass(GetModalClasses()); |
||||
element.Attributes.Add("tabindex", "-1"); |
element.Attributes.Add("tabindex", "-1"); |
||||
element.Attributes.Add("role", "dialog"); |
element.Attributes.Add("role", "dialog"); |
||||
element.Attributes.Add("aria-hidden", "true"); |
element.Attributes.Add("aria-hidden", "true"); |
||||
|
|
||||
foreach (var attr in output.Attributes) |
foreach (var attr in output.Attributes) |
||||
{ |
{ |
||||
element.Attributes.Add(attr.Name, attr.Value.ToString()); |
element.Attributes.Add(attr.Name, attr.Value.ToString()); |
||||
} |
} |
||||
|
|
||||
SetDataAttributes(element); |
SetDataAttributes(element); |
||||
|
|
||||
element.InnerHtml.SetHtmlContent(innerHtml); |
element.InnerHtml.SetHtmlContent(innerHtml); |
||||
|
|
||||
return element; |
return element; |
||||
} |
} |
||||
|
|
||||
protected virtual string GetModalClasses() |
protected virtual string GetModalClasses() |
||||
{ |
{ |
||||
return "modal fade"; |
return "modal fade"; |
||||
} |
} |
||||
|
|
||||
protected virtual string GetModalDialogClasses() |
protected virtual string GetModalDialogClasses() |
||||
{ |
{ |
||||
var classNames = new StringBuilder("modal-dialog"); |
var classNames = new StringBuilder("modal-dialog"); |
||||
|
|
||||
if (TagHelper.Centered ?? false) |
if (TagHelper.Centered ?? false) |
||||
{ |
{ |
||||
classNames.Append(" "); |
classNames.Append(" "); |
||||
classNames.Append("modal-dialog-centered"); |
classNames.Append("modal-dialog-centered"); |
||||
} |
} |
||||
|
|
||||
if (TagHelper.Size != AbpModalSize.Default) |
if (TagHelper.Scrollable ?? false) |
||||
{ |
{ |
||||
classNames.Append(" "); |
classNames.Append(" "); |
||||
classNames.Append(TagHelper.Size.ToClassName()); |
classNames.Append("modal-dialog-scrollable"); |
||||
} |
} |
||||
|
|
||||
return classNames.ToString(); |
if (TagHelper.Size != AbpModalSize.Default) |
||||
} |
{ |
||||
|
classNames.Append(" "); |
||||
protected virtual string GetModalContentClasses() |
classNames.Append(TagHelper.Size.ToClassName()); |
||||
{ |
} |
||||
return "modal-content"; |
|
||||
} |
return classNames.ToString(); |
||||
|
} |
||||
protected virtual string GetDataAttributes() |
|
||||
{ |
protected virtual string GetModalContentClasses() |
||||
if (TagHelper.Static == true) |
{ |
||||
{ |
return "modal-content"; |
||||
return "data-backdrop=\"static\" "; |
} |
||||
} |
|
||||
return string.Empty; |
protected virtual string GetDataAttributes() |
||||
} |
{ |
||||
|
if (TagHelper.Static == true) |
||||
protected virtual void SetDataAttributes(TagBuilder builder) |
{ |
||||
{ |
return "data-backdrop=\"static\" "; |
||||
if (TagHelper.Static == true) |
} |
||||
{ |
return string.Empty; |
||||
builder.Attributes.Add("data-backdrop", "static"); |
} |
||||
} |
|
||||
} |
protected virtual void SetDataAttributes(TagBuilder builder) |
||||
} |
{ |
||||
} |
if (TagHelper.Static == true) |
||||
|
{ |
||||
|
builder.Attributes.Add("data-backdrop", "static"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue