mirror of https://github.com/abpframework/abp.git
committed by
GitHub
1 changed files with 109 additions and 109 deletions
@ -1,115 +1,115 @@ |
|||||
using System.Linq; |
using System.Linq; |
||||
using Microsoft.AspNetCore.Razor.TagHelpers; |
using Microsoft.AspNetCore.Razor.TagHelpers; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover |
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover |
||||
{ |
{ |
||||
public class AbpPopoverTagHelperService : AbpTagHelperService<AbpPopoverTagHelper> |
public class AbpPopoverTagHelperService : AbpTagHelperService<AbpPopoverTagHelper> |
||||
{ |
{ |
||||
public override void Process(TagHelperContext context, TagHelperOutput output) |
public override void Process(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
if (!TagHelper.Disabled ?? true) |
if (!TagHelper.Disabled ?? true) |
||||
{ |
{ |
||||
SetDataToggle(context, output); |
SetDataToggle(context, output); |
||||
SetDataPlacement(context, output); |
SetDataPlacement(context, output); |
||||
SetPopoverData(context, output); |
SetPopoverData(context, output); |
||||
SetDataTriggerIfDismissible(context, output); |
SetDataTriggerIfDismissible(context, output); |
||||
} |
} |
||||
else |
else |
||||
{ |
{ |
||||
SetDisabled(context, output); |
SetDisabled(context, output); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
protected virtual void SetDisabled(TagHelperContext context, TagHelperOutput output) |
protected virtual void SetDisabled(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
var triggerAsHtml = TagHelper.Dismissible ?? false ? "datatrigger=\"focus\" " : ""; |
var triggerAsHtml = TagHelper.Dismissible ?? false ? "data-trigger=\"focus\" " : ""; |
||||
// If not dismissable for hoverable condition
|
// If not dismissable for hoverable condition
|
||||
if (string.IsNullOrEmpty(triggerAsHtml)) |
if (string.IsNullOrEmpty(triggerAsHtml)) |
||||
{ |
{ |
||||
triggerAsHtml = TagHelper.Hoverable ?? false ? "data-trigger=\"hover\" " : string.Empty; |
triggerAsHtml = TagHelper.Hoverable ?? false ? "data-trigger=\"hover\" " : string.Empty; |
||||
} |
} |
||||
var dataPlacementAsHtml = "data-placement=\"" + GetDirectory().ToString().ToLowerInvariant() + "\" "; |
var dataPlacementAsHtml = "data-placement=\"" + GetDirectory().ToString().ToLowerInvariant() + "\" "; |
||||
var titleAttribute = output.Attributes.FirstOrDefault(at => at.Name == "title"); |
var titleAttribute = output.Attributes.FirstOrDefault(at => at.Name == "title"); |
||||
var titleAsHtml = titleAttribute == null ? "" : "title=\"" + titleAttribute.Value + "\" "; |
var titleAsHtml = titleAttribute == null ? "" : "title=\"" + titleAttribute.Value + "\" "; |
||||
var preElementHtml = "<span class=\"d-inline-block\" " + titleAsHtml + triggerAsHtml + dataPlacementAsHtml + "data-toggle=\"popover\" data-content=\"" + GetDataContent() + "\">"; |
var preElementHtml = "<span class=\"d-inline-block\" " + titleAsHtml + triggerAsHtml + dataPlacementAsHtml + "data-toggle=\"popover\" data-content=\"" + GetDataContent() + "\">"; |
||||
var postElementHtml = "</span>"; |
var postElementHtml = "</span>"; |
||||
|
|
||||
output.PreElement.SetHtmlContent(preElementHtml); |
output.PreElement.SetHtmlContent(preElementHtml); |
||||
output.PostElement.SetHtmlContent(postElementHtml); |
output.PostElement.SetHtmlContent(postElementHtml); |
||||
|
|
||||
output.Attributes.Add("style", "pointer-events: none;"); |
output.Attributes.Add("style", "pointer-events: none;"); |
||||
} |
} |
||||
|
|
||||
protected virtual void SetDataTriggerIfDismissible(TagHelperContext context, TagHelperOutput output) |
protected virtual void SetDataTriggerIfDismissible(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
if (TagHelper.Dismissible ?? false) |
if (TagHelper.Dismissible ?? false) |
||||
{ |
{ |
||||
output.Attributes.Add("data-trigger", "focus"); |
output.Attributes.Add("data-trigger", "focus"); |
||||
} |
} |
||||
// Dismissible has priority over hoverable
|
// Dismissible has priority over hoverable
|
||||
else if (TagHelper.Hoverable ?? false) |
else if (TagHelper.Hoverable ?? false) |
||||
{ |
{ |
||||
output.Attributes.Add("data-trigger", "hover"); |
output.Attributes.Add("data-trigger", "hover"); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
protected virtual void SetDataToggle(TagHelperContext context, TagHelperOutput output) |
protected virtual void SetDataToggle(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
output.Attributes.Add("data-toggle", "popover"); |
output.Attributes.Add("data-toggle", "popover"); |
||||
} |
} |
||||
|
|
||||
protected virtual void SetDataPlacement(TagHelperContext context, TagHelperOutput output) |
protected virtual void SetDataPlacement(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
var directory = GetDirectory(); |
var directory = GetDirectory(); |
||||
if (directory == PopoverDirectory.Default) |
if (directory == PopoverDirectory.Default) |
||||
{ |
{ |
||||
directory = PopoverDirectory.Bottom; |
directory = PopoverDirectory.Bottom; |
||||
} |
} |
||||
output.Attributes.Add("data-placement", directory.ToString().ToLowerInvariant()); |
output.Attributes.Add("data-placement", directory.ToString().ToLowerInvariant()); |
||||
} |
} |
||||
|
|
||||
protected virtual void SetPopoverData(TagHelperContext context, TagHelperOutput output) |
protected virtual void SetPopoverData(TagHelperContext context, TagHelperOutput output) |
||||
{ |
{ |
||||
output.Attributes.Add("data-content", GetDataContent()); |
output.Attributes.Add("data-content", GetDataContent()); |
||||
} |
} |
||||
|
|
||||
protected virtual string GetDataContent() |
protected virtual string GetDataContent() |
||||
{ |
{ |
||||
switch (GetDirectory()) |
switch (GetDirectory()) |
||||
{ |
{ |
||||
case PopoverDirectory.Top: |
case PopoverDirectory.Top: |
||||
return TagHelper.AbpPopoverTop; |
return TagHelper.AbpPopoverTop; |
||||
case PopoverDirectory.Right: |
case PopoverDirectory.Right: |
||||
return TagHelper.AbpPopoverRight; |
return TagHelper.AbpPopoverRight; |
||||
case PopoverDirectory.Bottom: |
case PopoverDirectory.Bottom: |
||||
return TagHelper.AbpPopoverBottom; |
return TagHelper.AbpPopoverBottom; |
||||
case PopoverDirectory.Left: |
case PopoverDirectory.Left: |
||||
return TagHelper.AbpPopoverLeft; |
return TagHelper.AbpPopoverLeft; |
||||
default: |
default: |
||||
return TagHelper.AbpPopover; |
return TagHelper.AbpPopover; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
protected virtual PopoverDirectory GetDirectory() |
protected virtual PopoverDirectory GetDirectory() |
||||
{ |
{ |
||||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverTop)) |
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverTop)) |
||||
{ |
{ |
||||
return PopoverDirectory.Top; |
return PopoverDirectory.Top; |
||||
} |
} |
||||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverBottom)) |
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverBottom)) |
||||
{ |
{ |
||||
return PopoverDirectory.Bottom; |
return PopoverDirectory.Bottom; |
||||
} |
} |
||||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverRight)) |
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverRight)) |
||||
{ |
{ |
||||
return PopoverDirectory.Right; |
return PopoverDirectory.Right; |
||||
} |
} |
||||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverLeft)) |
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverLeft)) |
||||
{ |
{ |
||||
return PopoverDirectory.Left; |
return PopoverDirectory.Left; |
||||
} |
} |
||||
|
|
||||
return PopoverDirectory.Default; |
return PopoverDirectory.Default; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue