Skip to content

Commit 03e2aa9

Browse files
committed
fix: remove duplicate theming injection from app-lob DocsLayoutComponent and fix typeface link reuse
1 parent 9fa5123 commit 03e2aa9

3 files changed

Lines changed: 16 additions & 53 deletions

File tree

projects/app-lob/src/app/app.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ export class AppComponent implements OnInit {
5858
}
5959

6060
private createTypefaceLink(typeface: string) {
61-
const typefaceElem = this.document.createElement('link');
62-
typefaceElem.rel = 'stylesheet';
63-
typefaceElem.id = 'ignteui-theme-typeface';
61+
let typefaceElem = this.document.getElementById('igniteui-theme-typeface') as HTMLLinkElement;
62+
if (!typefaceElem) {
63+
typefaceElem = this.document.createElement('link');
64+
typefaceElem.rel = 'stylesheet';
65+
typefaceElem.id = 'igniteui-theme-typeface';
66+
this.document.head.appendChild(typefaceElem);
67+
}
6468
typefaceElem.href = this.typefaceUrl + typeface.split(' ').join('+');
65-
this.document.head.appendChild(typefaceElem);
6669
}
6770

6871
private createThemeStyle() {
Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Component, HostListener, OnInit, DOCUMENT, inject } from '@angular/core';
2+
import { Component } from '@angular/core';
33
import { RouterOutlet } from '@angular/router';
44

55
@Component({
@@ -9,48 +9,5 @@ import { RouterOutlet } from '@angular/router';
99
imports: [RouterOutlet]
1010
})
1111

12-
export class DocsLayoutComponent implements OnInit {
13-
private document = inject<Document>(DOCUMENT);
14-
15-
private theme = 'default-theme';
16-
private styleElem: HTMLStyleElement;
17-
private typefacesLoaded = ['Titillium Web', 'Roboto'];
18-
private typefaceUrl = 'https://fonts.googleapis.com/css?family=';
19-
20-
@HostListener('window:message', ['$event'])
21-
protected onMessage(e: MessageEvent) {
22-
if (e.origin === e.data.origin && typeof e.data.themeStyle === 'string') {
23-
this.styleElem.textContent = e.data.themeStyle;
24-
25-
const typeface = this.document.defaultView.getComputedStyle(this.document.body).fontFamily.replace(/\'/g, '');
26-
if (!(typeface.match(/,/g) || []).length &&
27-
!this.typefacesLoaded.includes(typeface)) {
28-
this.typefacesLoaded.push(typeface);
29-
this.createTypefaceLink(typeface);
30-
}
31-
} else if (e.origin === e.data.origin && typeof e.data.theme === 'string') {
32-
this.document.body.classList.remove(this.theme);
33-
this.document.body.classList.add(e.data.theme);
34-
this.theme = e.data.theme;
35-
}
36-
}
37-
38-
public ngOnInit() {
39-
this.createThemeStyle();
40-
}
41-
42-
private createThemeStyle() {
43-
this.styleElem = this.document.createElement('style');
44-
this.styleElem.id = 'igniteui-theme';
45-
this.document.head.appendChild(this.styleElem);
46-
this.document.body.classList.add('custom-body');
47-
}
48-
49-
private createTypefaceLink(typeface: string) {
50-
const typefaceElem = this.document.createElement('link');
51-
typefaceElem.rel = 'stylesheet';
52-
typefaceElem.id = 'ignteui-theme-typeface';
53-
typefaceElem.href = this.typefaceUrl + typeface.split(' ').join('+');
54-
this.document.head.appendChild(typefaceElem);
55-
}
12+
export class DocsLayoutComponent {
5613
}

src/app/app.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ export class AppComponent implements OnInit {
4040
}
4141

4242
private createTypefaceLink(typeface: string) {
43-
const typefaceElem = this.document.createElement('link');
44-
typefaceElem.rel = 'stylesheet';
45-
typefaceElem.id = 'ignteui-theme-typeface';
43+
let typefaceElem = this.document.getElementById('igniteui-theme-typeface') as HTMLLinkElement;
44+
if (!typefaceElem) {
45+
typefaceElem = this.document.createElement('link');
46+
typefaceElem.rel = 'stylesheet';
47+
typefaceElem.id = 'igniteui-theme-typeface';
48+
this.document.head.appendChild(typefaceElem);
49+
}
4650
typefaceElem.href = this.typefaceUrl + typeface.split(' ').join('+');
47-
this.document.head.appendChild(typefaceElem);
4851
}
4952

5053
private createThemeStyle() {

0 commit comments

Comments
 (0)