Browse Source

Added IAbpUtilsService

pull/5614/head
Halil İbrahim Kalkan 6 years ago
parent
commit
0178b6c324
  1. 31
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/AbpUtilsService.cs
  2. 11
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/IAbpUtilsService.cs
  3. 27
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/wwwroot/abp_theming.js

31
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<bool> HasClassOnTag(string tagName, string className)
{
return JsRuntime.InvokeAsync<bool>("abp.utils.hasClassOnTag", tagName, className);
}
}
}

11
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<bool> HasClassOnTag(string tagName, string className);
}
}

27
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;
};
})();
Loading…
Cancel
Save