Refactor
This commit is contained in:
parent
b6aef2bcf8
commit
33051841f5
10 changed files with 32 additions and 39 deletions
|
|
@ -1,8 +1,11 @@
|
|||
import { html } from '../types/html';
|
||||
|
||||
export class PageElement {
|
||||
public constructor(
|
||||
public readonly htmlRoot: HTMLElement,
|
||||
protected children: Array<PageElement> = []
|
||||
) {}
|
||||
public readonly htmlRoot: HTMLElement;
|
||||
|
||||
public constructor(content: html, protected children: Array<PageElement> = []) {
|
||||
this.htmlRoot = PageElement.createElement(content);
|
||||
}
|
||||
|
||||
public attachToDOM(target: HTMLElement) {
|
||||
target.appendChild(this.htmlRoot);
|
||||
|
|
@ -27,4 +30,11 @@ export class PageElement {
|
|||
old.parentElement!.replaceChild(element.htmlRoot, old);
|
||||
this.children.push(element);
|
||||
}
|
||||
|
||||
private static createElement(from: html): HTMLElement {
|
||||
// won't work for all elements, eg.: <td>
|
||||
const element: HTMLElement = document.createElement('div');
|
||||
element.innerHTML = from;
|
||||
return element.firstElementChild as HTMLElement;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue