-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
80 lines (72 loc) · 1.4 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DOM Builder demo</title>
<style>
* {
font-size: 60px;
}
input[type=checkbox] {
transform: scale(3.5);
margin: 0 37px 0 30px;
vertical-align: middle;
}
button {
cursor: pointer;
padding: 0.1875em 0.375em;
border-width: 0.125em;
background: orange;
border-color: hsl(39, 100%, 60%);
}
.green {
background: green;
border-color: hsl(120, 100%, 35%);
}
</style>
</head>
<body>
<script src="bower_components/snoopy/snoopy.js"></script>
<script src="dom.js"></script>
<script>
// setup observable data
var counter = new Snoopy({count: 0});
// counter.even subscribes to counter.count
counter.snoop('count', function(val) {
counter.set('even', val % 2 === 0);
});
// <button>0</button>
var buttonModule = dom([
{
el: 'button',
text: counter.snoop('count'),
class_green: counter.snoop('even'),
on_click: function() {
counter.set('count', counter.count + 1);
}
},
{
el: 'label',
kids: [
' ',
{
el: 'input',
type: 'checkbox',
_checked: counter.snoop('even'),
_disabled: true
},
counter.snoop('count'), ' is ',
counter.snoop('even', function(even) {
return even ? 'even.' : 'not even.';
})
]
}
]);
// equivalent to: document.body.appendChild(buttonModule);
dom({
el: document.body,
kids: [buttonModule]
});
</script>
</body>
</html>