-
Notifications
You must be signed in to change notification settings - Fork 0
/
wcf.js
39 lines (36 loc) · 873 Bytes
/
wcf.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
function register_component(name, url, shadow) {
let cel;
if (shadow) {
cel = class CustomElement extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
const template = document.createElement("template");
// Fetch the template HTML file
fetch(url)
.then((response) => response.text())
.then((data) => {
template.innerHTML = data;
this.shadowRoot.appendChild(template.content.cloneNode(true));
})
.catch((error) => console.error(error));
}
}
}
else {
cel = class CustomElement extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
fetch(url)
.then((response) => response.text())
.then((data) => {
this.innerHTML = data;
})
.catch((error) => console.error(error));
}
}
}
customElements.define(name, cel);
}