-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
44 lines (38 loc) · 927 Bytes
/
index.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
<!doctype html>
<html>
<head>
<title>html-strings</title>
<body>
<script src="html.js"></script>
<script>
var insert = html.insert;
var root = document.body;
function template({title, text}) {
return html`
<h1>${title}</h1>
<p>${text || 'Some text'}</p>
`
}
function button({label, click}) {
return html({click})`<button>${label}</button>`
}
insert(root, template({
title: 'Bind to button directly',
text: html`Different text with a button: ${button({
label: 'Click me!',
click: (ev) => console.log('click!', ev)
})}`
}))
// "Delegate" binding (all events are already delegate bound,
// but here we bind all direct child elements to the same handler)
insert(root, template({
title: 'Bind to parent',
text: html({
click: (ev) => console.log('click!', ev)
})`
Multiple buttons, either of which trigger the sample handler:
${button({label: 'Click me'})}
${button({label: 'or me!'})}
`
}))
</script>