-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathem-bed.ts
More file actions
24 lines (19 loc) · 778 Bytes
/
Copy pathem-bed.ts
File metadata and controls
24 lines (19 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { parseDomFragment } from './dom.js';
class Embed extends HTMLElement {
private loaded = false;
public connectedCallback(): void {
if (this.loaded) return;
const src = this.getAttribute('src');
if (!src) throw new Error(`<em-bed /> requires a \`src\` attribute.`);
// Mark the component has loaded to avoid double-requesting the `src`
// if this element is detached and reattached to the DOM.
this.loaded = true;
(async () => {
const res = await fetch(src);
const template = await parseDomFragment(res);
const content = template.content.cloneNode(true /* deep */);
this.appendChild(content);
})();
}
}
customElements.define('em-bed', Embed);