HtmlRendition.ts
39 lines
| 1.1 KiB
| video/mp2t
|
TypeScriptLexer
cin
|
r65 | import dom = require("dojo/dom-construct"); | ||
import { argumentNotEmptyString } from "@implab/core-amd/safe"; | ||||
import { RenditionBase } from "./RenditionBase"; | ||||
cin
|
r96 | import { placeAt } from "./traits"; | ||
import { IScope } from "./Scope"; | ||||
cin
|
r98 | import { getItemDom } from "./render"; | ||
cin
|
r65 | |||
export class HtmlRendition extends RenditionBase<HTMLElement> { | ||||
elementType: string; | ||||
_element: HTMLElement | undefined; | ||||
constructor(elementType: string) { | ||||
argumentNotEmptyString(elementType, "elementType"); | ||||
super(); | ||||
this.elementType = elementType; | ||||
} | ||||
cin
|
r96 | _addChild(child: unknown, scope: IScope): void { | ||
cin
|
r65 | if (!this._element) | ||
throw new Error("The HTML element isn't created"); | ||||
cin
|
r96 | placeAt(getItemDom(child, scope), this._element); | ||
cin
|
r65 | } | ||
cin
|
r96 | _create(attrs: object, children: unknown[], scope: IScope) { | ||
cin
|
r65 | this._element = dom.create(this.elementType, attrs); | ||
cin
|
r96 | children.forEach(v => this._addChild(v, scope)); | ||
cin
|
r65 | } | ||
_getDomNode() { | ||||
if (!this._element) | ||||
throw new Error("The HTML element isn't created"); | ||||
return this._element; | ||||
} | ||||
} | ||||