-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello-universe.html
40 lines (34 loc) · 1.2 KB
/
hello-universe.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My App</title>
</head>
<body>
<!-- target element -->
<div id="container"></div>
<!-- template -->
<template class="magery-templates">
<div data-template="app" id="container">
<h1>Hello, {{name}}!</h1>
<input type="text" value="{{name}}" oninput="updateName(event)" />
</div>
</template>
<!-- patch the target using the template -->
<script src="../build/magery.js"></script>
<script>
var templates = Magery.compile('.magery-templates');
var container = document.getElementById('container');
var data = {name: 'galaxy'};
templates['app'].bind({
updateName: function (event) {
// update the data object, then patch the page
data.name = event.target.value;
Magery.patch(templates, 'app', data, container);
}
});
// initial patch sets up event handlers
Magery.patch(templates, 'app', data, container);
</script>
</body>
</html>