-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.js
45 lines (38 loc) · 988 Bytes
/
draw.js
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
var iterations = 20;
function random_attendee() {
var count = $(".attendee").length;
var random = Math.floor((Math.random() * count));
return $(".attendee:eq(" + random + ")");
}
function draw(count) {
$(".attendee").removeClass('highlight');
var $attendee = random_attendee();
$attendee.addClass('highlight');
if (count > 0) {
setTimeout(function() {
draw(count - 1)
}, 100);
} else {
setTimeout(function() {
win($attendee)
}, 500);
}
}
function win($attendee) {
var win_id = '#win-' + $attendee.attr('id');
$(win_id).modal('show');
// Only one win per attendee
$attendee.remove();
}
// Draw when draw button is pressed
$(document).ready(function() {
$("#draw_button").click(function() {
draw(iterations);
});
});
// Draw when "i" is pressed
$(document).keypress(function(e) {
if (e.which == 73 || e.which == 105) {
draw(iterations);
}
});