-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtmlcontainer.js
41 lines (34 loc) · 996 Bytes
/
htmlcontainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function () {
let template = document.createElement("template");
template.innerHTML = `
`;
class HTMLContainer extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ mode: "open" });
this._shadowRoot.appendChild(template.content.cloneNode(true));
this._dom;
this._htmlcode = "<div></div>";
}
get code() {
return this._htmlcode;
}
set code(val) {
this._htmlcode = val;
}
onCustomWidgetAfterUpdate(oChangedProperties) {
if ("code" in oChangedProperties) {
this.changeHTML(oChangedProperties["code"]);
}
}
changeHTML(val) {
if (this._dom) {
this._dom.parentNode.removeChild(this._dom);
}
this._dom = document.createElement("div");
this._dom.innerHTML = val;
this._shadowRoot.appendChild(this._dom);
}
}
customElements.define("sac-htmlcontainer", HTMLContainer);
})();