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