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; + }; +})();