From 0178b6c324e86c5ece4a1aeb460c53e1c9a1096f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 25 Sep 2020 11:36:04 +0300 Subject: [PATCH] Added IAbpUtilsService --- .../AbpUtilsService.cs | 31 +++++++++++++++++++ .../IAbpUtilsService.cs | 11 +++++++ .../wwwroot/abp_theming.js | 27 ++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpUtilsService.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/IAbpUtilsService.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/wwwroot/abp_theming.js diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpUtilsService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpUtilsService.cs new file mode 100644 index 0000000000..006674e7c5 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpUtilsService.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using Microsoft.JSInterop; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming +{ + public class AbpUtilsService : IAbpUtilsService, ITransientDependency + { + protected IJSRuntime JsRuntime { get; } + + public AbpUtilsService(IJSRuntime jsRuntime) + { + JsRuntime = jsRuntime; + } + + public ValueTask AddClassToTagAsync(string tagName, string className) + { + return JsRuntime.InvokeVoidAsync("abp.utils.addClassToTag", tagName, className); + } + + public ValueTask RemoveClassFromTagAsync(string tagName, string className) + { + return JsRuntime.InvokeVoidAsync("abp.utils.removeClassFromTag", tagName, className); + } + + public ValueTask HasClassOnTag(string tagName, string className) + { + return JsRuntime.InvokeAsync("abp.utils.hasClassOnTag", tagName, className); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/IAbpUtilsService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/IAbpUtilsService.cs new file mode 100644 index 0000000000..dddea5ff4f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/IAbpUtilsService.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming +{ + public interface IAbpUtilsService + { + ValueTask AddClassToTagAsync(string tagName, string className); + ValueTask RemoveClassFromTagAsync(string tagName, string className); + ValueTask HasClassOnTag(string tagName, string className); + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/wwwroot/abp_theming.js b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/wwwroot/abp_theming.js new file mode 100644 index 0000000000..7c7032ebbe --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/wwwroot/abp_theming.js @@ -0,0 +1,27 @@ +var abp = abp || {}; +(function () { + abp.utils = abp.utils || {}; + + abp.utils.addClassToTag = function (tagName, className) { + var tags = document.getElementsByTagName(tagName); + for (var i = 0; i < tags.length; i++) { + tags[i].classList.add(className); + } + }; + + abp.utils.removeClassFromTag = function (tagName, className) { + var tags = document.getElementsByTagName(tagName); + for (var i = 0; i < tags.length; i++) { + tags[i].classList.remove(className); + } + }; + + abp.utils.hasClassOnTag = function (tagName, className) { + var tags = document.getElementsByTagName(tagName); + if(tags.length){ + return tags[0].classList.contains(className); + } + + return false; + }; +})();