-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimple-text-input.html
44 lines (39 loc) · 1.24 KB
/
simple-text-input.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>
<meta charset="UTF-8">
<title>Example: simple text input</title>
</head>
<body>
<!-- target element -->
<div id="container"></div>
<!-- templates -->
<template class="magery-templates">
<div data-template="main" id="container">
<h1>Hello, {{name}}!</h1>
<form onsubmit="updateName(event)">
<input type="text" name="name" />
<button>Update name</button>
</form>
</div>
</template>
<script src="../build/magery.js"></script>
<script>
var templates = Magery.compile('.magery-templates');
var element = document.getElementById('container');
var data = {name: 'world'};
function patch() {
Magery.patch(templates, 'main', data, element);
}
window.app = templates['main'].bind({
updateName: function (event) {
event.preventDefault();
var form = event.target;
data.name = form.name.value;
patch();
}
});
patch();
</script>
</body>
</html>