-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
77 lines (68 loc) · 1.98 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
<html>
<head>
<title>Embedding Elm</title>
<script src="elm.js"></script>
<style>
body {
background-image: url('resources/texture.png');
background-color: #d3d7cf;
font-family: "Lucida Grande","Trebuchet MS","Bitstream Vera Sans",Verdana,Helvetica,sans-serif;
font-size: 14px;
}
#elm-stamps {
width: 400px;
height: 400px;
background-color: white;
border: 1px solid #babdb6;
}
#column {
width: 420px;
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="column">
<h1>Stamps</h1>
<p>This demo shows how to:</p>
<ol>
<li>embed an Elm program in HTML</li>
<li>send events back and forth between Elm and JavaScript</li>
</ol>
<p>The white square is an Elm program, but the rest is HTML, CSS, and JS.
See the <a href="http://github.com/evancz/elm-html-and-js">source code</a>
for more info.
</p>
<div id="elm-stamps"></div>
<p>There are currently <span id="current-count">0</span> stamps.
<button onclick="resetStamps()">Reset</button>
</p>
<p>You have created <span id="total-count">0</span> stamps in total.</p>
</div>
</body>
<script type="text/javascript">
// Show the stamp module in the "elm-stamps" div.
var div = document.getElementById('elm-stamps');
var stamps = Elm.embed(Elm.Stamps, div, { reset:[] });
// Reset the number of stamps in the Elm code.
// The value we send does not matter, we just
// need the event.
function resetStamps() {
stamps.ports.reset.send([]);
}
// Always show the latest count of stamps, which is exported
// from the Stamps module as the 'count' event stream.
var currentCount = document.getElementById('current-count'),
totalCount = document.getElementById('total-count'),
total = 0;
stamps.ports.count.subscribe(function(count) {
currentCount.innerHTML = count;
if (count > 0) {
total += 1;
totalCount.innerHTML = total;
}
});
</script>
</html>