-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (52 loc) · 1.57 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
<!doctype html>
<html>
<head>
<title>Salty Voter!</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="lscache.js"></script>
<script>
$(document).ready(function(){
var socket = io();
function loadPeople(people){
var person;
for (person in people){
if(people.hasOwnProperty(person)){
$('body').append("<div class='salty_person'><p class='name'>"+person+"</p><p>Votes: "+people[person].votes+"</p></div>");
}
}
$('body').append("<div><span>Add new</span><input type='text' id='newname' name='newvote'><br><button id='submitbutton' type='button'>Vote new person</button></div>");
}
function vote(person){
if(lscache.get("voted")){
alert("You can only vote once per hour");
}else{
socket.emit('vote',person);
lscache.set("voted","yes",60);
}
}
$('body').delegate('#submitbutton','click',function(){
vote($('#newname').val());
});
$('body').delegate('.salty_person','click',function(){
var name = $(this).find('.name').text();
vote(name);
});
socket.on('vote',function(people){
$('body').html('');
loadPeople(people);
});
socket.emit('first load',"");
socket.on('load people',function(people){
loadPeople(people);
});
});
</script>
</head>
<body>
</body>
</html>