-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbodies.html
82 lines (69 loc) · 1.63 KB
/
bodies.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
81
82
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="../dist/nap.js"></script>
<script type="text/javascript" src="../lib/d3/d3.js"></script>
<script type="text/javascript">
function init(){
function todo(){
var list = ["this", "that"]
function view(req){
d3.select(this)
.selectAll("li")
.data(list, function(d){return d})
.enter().append("li")
.text(function(d){return d})
}
function add(req){
list.push(req.body)
}
return {
view : view
, add : add
}
}
var myTodo = todo()
web = nap.web()
.view(d3.select("ul").node())
.resource("/todos",
nap.negotiate.method(
{ get: nap.handlers.view(myTodo.view)
, send: myTodo.add
}
)
)
function render(){
var req = web.req.bind(d3.select("ul").node())
req("/todos")
}
render()
d3.select("form")
.on("submit", function(){
d3.event.preventDefault()
var input = this
web.req(
{ uri : "/todos"
, method : "send"
, body : input.todo.value
}
, function(err, data){
input.todo.value = ""
render()
}
)
})
}
</script>
<title>Bodies</title>
</head>
<body onload="init()">
<div class="container">
<ul>
</ul>
<form>
<input name="todo" type="text"></input>
</form>
</div>
</body>
</html>