From c4a1dd6be70920ffd8d7fcf76ebcb973c948d010 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 23 Mar 2020 10:16:16 +0300 Subject: [PATCH] Update AbpPopoverTagHelperService.cs --- .../Popover/AbpPopoverTagHelperService.cs | 218 +++++++++--------- 1 file changed, 109 insertions(+), 109 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Popover/AbpPopoverTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Popover/AbpPopoverTagHelperService.cs index de5e844888..168d2a5a96 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Popover/AbpPopoverTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Popover/AbpPopoverTagHelperService.cs @@ -1,115 +1,115 @@ -using System.Linq; -using Microsoft.AspNetCore.Razor.TagHelpers; - -namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover -{ - public class AbpPopoverTagHelperService : AbpTagHelperService - { - public override void Process(TagHelperContext context, TagHelperOutput output) - { - if (!TagHelper.Disabled ?? true) - { - SetDataToggle(context, output); - SetDataPlacement(context, output); - SetPopoverData(context, output); - SetDataTriggerIfDismissible(context, output); - } - else - { - SetDisabled(context, output); - } - } - - protected virtual void SetDisabled(TagHelperContext context, TagHelperOutput output) - { - var triggerAsHtml = TagHelper.Dismissible ?? false ? "datatrigger=\"focus\" " : ""; - // If not dismissable for hoverable condition +using System.Linq; +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover +{ + public class AbpPopoverTagHelperService : AbpTagHelperService + { + public override void Process(TagHelperContext context, TagHelperOutput output) + { + if (!TagHelper.Disabled ?? true) + { + SetDataToggle(context, output); + SetDataPlacement(context, output); + SetPopoverData(context, output); + SetDataTriggerIfDismissible(context, output); + } + else + { + SetDisabled(context, output); + } + } + + protected virtual void SetDisabled(TagHelperContext context, TagHelperOutput output) + { + var triggerAsHtml = TagHelper.Dismissible ?? false ? "data-trigger=\"focus\" " : ""; + // If not dismissable for hoverable condition if (string.IsNullOrEmpty(triggerAsHtml)) { triggerAsHtml = TagHelper.Hoverable ?? false ? "data-trigger=\"hover\" " : string.Empty; - } - var dataPlacementAsHtml = "data-placement=\"" + GetDirectory().ToString().ToLowerInvariant() + "\" "; - var titleAttribute = output.Attributes.FirstOrDefault(at => at.Name == "title"); - var titleAsHtml = titleAttribute == null ? "" : "title=\"" + titleAttribute.Value + "\" "; - var preElementHtml = ""; - var postElementHtml = ""; - - output.PreElement.SetHtmlContent(preElementHtml); - output.PostElement.SetHtmlContent(postElementHtml); - - output.Attributes.Add("style", "pointer-events: none;"); - } - - protected virtual void SetDataTriggerIfDismissible(TagHelperContext context, TagHelperOutput output) - { - if (TagHelper.Dismissible ?? false) - { - output.Attributes.Add("data-trigger", "focus"); + } + var dataPlacementAsHtml = "data-placement=\"" + GetDirectory().ToString().ToLowerInvariant() + "\" "; + var titleAttribute = output.Attributes.FirstOrDefault(at => at.Name == "title"); + var titleAsHtml = titleAttribute == null ? "" : "title=\"" + titleAttribute.Value + "\" "; + var preElementHtml = ""; + var postElementHtml = ""; + + output.PreElement.SetHtmlContent(preElementHtml); + output.PostElement.SetHtmlContent(postElementHtml); + + output.Attributes.Add("style", "pointer-events: none;"); + } + + protected virtual void SetDataTriggerIfDismissible(TagHelperContext context, TagHelperOutput output) + { + if (TagHelper.Dismissible ?? false) + { + output.Attributes.Add("data-trigger", "focus"); } // Dismissible has priority over hoverable else if (TagHelper.Hoverable ?? false) - { - output.Attributes.Add("data-trigger", "hover"); - } - } - - protected virtual void SetDataToggle(TagHelperContext context, TagHelperOutput output) - { - output.Attributes.Add("data-toggle", "popover"); - } - - protected virtual void SetDataPlacement(TagHelperContext context, TagHelperOutput output) - { - var directory = GetDirectory(); - if (directory == PopoverDirectory.Default) - { - directory = PopoverDirectory.Bottom; - } - output.Attributes.Add("data-placement", directory.ToString().ToLowerInvariant()); - } - - protected virtual void SetPopoverData(TagHelperContext context, TagHelperOutput output) - { - output.Attributes.Add("data-content", GetDataContent()); - } - - protected virtual string GetDataContent() - { - switch (GetDirectory()) - { - case PopoverDirectory.Top: - return TagHelper.AbpPopoverTop; - case PopoverDirectory.Right: - return TagHelper.AbpPopoverRight; - case PopoverDirectory.Bottom: - return TagHelper.AbpPopoverBottom; - case PopoverDirectory.Left: - return TagHelper.AbpPopoverLeft; - default: - return TagHelper.AbpPopover; - } - } - - protected virtual PopoverDirectory GetDirectory() - { - if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverTop)) - { - return PopoverDirectory.Top; - } - if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverBottom)) - { - return PopoverDirectory.Bottom; - } - if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverRight)) - { - return PopoverDirectory.Right; - } - if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverLeft)) - { - return PopoverDirectory.Left; - } - - return PopoverDirectory.Default; - } - } -} \ No newline at end of file + { + output.Attributes.Add("data-trigger", "hover"); + } + } + + protected virtual void SetDataToggle(TagHelperContext context, TagHelperOutput output) + { + output.Attributes.Add("data-toggle", "popover"); + } + + protected virtual void SetDataPlacement(TagHelperContext context, TagHelperOutput output) + { + var directory = GetDirectory(); + if (directory == PopoverDirectory.Default) + { + directory = PopoverDirectory.Bottom; + } + output.Attributes.Add("data-placement", directory.ToString().ToLowerInvariant()); + } + + protected virtual void SetPopoverData(TagHelperContext context, TagHelperOutput output) + { + output.Attributes.Add("data-content", GetDataContent()); + } + + protected virtual string GetDataContent() + { + switch (GetDirectory()) + { + case PopoverDirectory.Top: + return TagHelper.AbpPopoverTop; + case PopoverDirectory.Right: + return TagHelper.AbpPopoverRight; + case PopoverDirectory.Bottom: + return TagHelper.AbpPopoverBottom; + case PopoverDirectory.Left: + return TagHelper.AbpPopoverLeft; + default: + return TagHelper.AbpPopover; + } + } + + protected virtual PopoverDirectory GetDirectory() + { + if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverTop)) + { + return PopoverDirectory.Top; + } + if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverBottom)) + { + return PopoverDirectory.Bottom; + } + if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverRight)) + { + return PopoverDirectory.Right; + } + if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverLeft)) + { + return PopoverDirectory.Left; + } + + return PopoverDirectory.Default; + } + } +}