-
Notifications
You must be signed in to change notification settings - Fork 0
/
wc.html
46 lines (41 loc) · 1.03 KB
/
wc.html
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
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>WC Hello World</title>
<style type="text/css">
p {
color: red;
border: 1px solid green;
}
</style>
</head>
<body>
<script type="module">
class SimpleGreeting extends HTMLElement {
constructor() {
super(); // always call super() first in the constructor
this.name = 'Somebody';
}
connectedCallback() {
if (this.hasAttribute("name")) {
this.name = this.getAttribute("name");
}
let tmpl = document.createElement('template');
tmpl.innerHTML = `
<style> p { color: blue; } </style>
<p>Hello, ${this.name}!</p>
`;
let shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.appendChild(tmpl.content.cloneNode(true));
}
}
customElements.define('simple-greeting', SimpleGreeting);
</script>
<simple-greeting></simple-greeting>
<simple-greeting name="World"></simple-greeting>
<p>Main document paragraph</p>
</body>
</html>
<!-- stan, nick, pete -->