/
index.html
49 lines (39 loc) · 1.6 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
<html>
<head>
<script type='text/javascript' src='https://cdn.firebase.com/js/client/1.0.15/firebase.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
</head>
<body>
<h1>What's a better place for your next vacation?</h1>
<table>
<tr>
<td>Hawaii</td>
<td><img src="http://sbhawaii.com/images/hawaiian_beach.jpg" width="300px"> </td>
<td><input id="hawaii" type="button" value="Vote"><br/><p id="hawaiivotes"></p></td>
</tr>
<tr>
<td>New York</td>
<td><img src="http://cdn.frontpagemag.com/wp-content/uploads/2013/07/New-York-City-Skyline.jpg" width="300px"> </td>
<td><input id="ny" type="button" value="Vote"><br/><p id="nyvotes"></p></td>
</tr>
</table>
<h4>
Built and deployed in literally 10 minutes with <a href="http://www.firebase.com">Firebase</a>. Source code on <a href="https://github.com/MaxHorstmann/Vacadiscuss/blob/master/index.html">GitHub</a>.
</h4>
<script type="text/javascript">
var myDataRef = new Firebase('https://crackling-fire-7227.firebaseio.com/');
myDataRef.child('hawaii').on('value', function(snapshot) {
$('#hawaiivotes').html(snapshot.val() + ' votes');
});
myDataRef.child('ny').on('value', function(snapshot) {
$('#nyvotes').html(snapshot.val() + ' votes');
});
$('input').on('click', function() {
var vote = $(this).attr('id');
myDataRef.child(vote).transaction(function(current) {
return current+1;
});
});
</script>
</body>
</html>