From 00b5556c182fa70dfca17c517488b8afae6257c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Feb 2018 10:22:53 +0100 Subject: Add ability to add custom css/javascript --- client/src/app/app.component.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'client/src/app/app.component.ts') diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 3af33ba2b..25936146c 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core' +import { DomSanitizer, SafeHtml } from '@angular/platform-browser' import { GuardsCheckStart, Router } from '@angular/router' import { AuthService, ServerService } from '@app/core' import { isInSmallView } from '@app/shared/misc/utils' @@ -24,10 +25,13 @@ export class AppComponent implements OnInit { isMenuDisplayed = true + customCSS: SafeHtml + constructor ( private router: Router, private authService: AuthService, - private serverService: ServerService + private serverService: ServerService, + private domSanitizer: DomSanitizer ) {} get serverVersion () { @@ -66,6 +70,26 @@ export class AppComponent implements OnInit { } } ) + + this.serverService.configLoaded + .subscribe(() => { + const config = this.serverService.getConfig() + + // We test customCSS in case or the admin removed the css + if (this.customCSS || config.instance.customizations.css) { + const styleTag = '' + this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag) + } + + if (config.instance.customizations.javascript) { + try { + // tslint:disable:no-eval + eval(config.instance.customizations.javascript) + } catch (err) { + console.error('Cannot eval custom JavaScript.', err) + } + } + }) } toggleMenu () { -- cgit v1.2.3