-
Notifications
You must be signed in to change notification settings - Fork 7
/
raffle.html
176 lines (161 loc) · 6.46 KB
/
raffle.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="StartupStorm is a club for aspiring entrepreneurs, programmers and designers at the University of British Columbia." name="description">
<meta content="StartupStorm,UBC,entrepreneurs,programmers,designers,software,technology,tech,hackathon" name="keywords">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>StartupStorm</title>
<link href="css/bulma.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/aos.css" rel="stylesheet" type="text/css">
<link href="css/print.css" rel="stylesheet" media="print" type="text/css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/countUp.min.js"></script>
<!-- Favicons -->
<link rel="apple-touch-icon" sizes="57x57" href="img/favicons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="img/favicons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="img/favicons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="img/favicons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/favicons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="img/favicons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="img/favicons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="img/favicons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="img/favicons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="img/favicons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="img/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="img/favicons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="img/favicons/favicon-16x16.png">
<link rel="manifest" href="img/favicons/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="img/favicons/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
</head>
<body style="min-height: 600px">
<div class="columns no-print">
<div class="column">
</div>
<div class="column">
<br><br><br>
<center style="display: inline;"><h1 class="title" style="color:#0476F7">Raffle Ticket Generator <img width="50px" height="50px"src="http://cultofthepartyparrot.com/parrots/hd/parrot.gif"></img></h1></center>
<br>
<div class="field is-grouped">
<p class="control is-expanded">
<input class="input" id="numParticipants" type="text" placeholder="Enter number of participants">
</p>
<p class="control">
<a class="button is-info" onclick="generateTickets()">
Generate Tickets
</a>
</p>
<p class="control" id="select-winner-button" style="display: none">
<a class="button is-danger" onclick="selectWinner()">
Select Winner
</a>
</p>
</div>
</div>
<div class="column">
</div>
</div>
<div class="no-print">
<center><br>
<table style="border: 1px solid black">
<tr>
<td id="winner-cell" style="padding: 20px 80px 50px 80px; text-align: center; font-size: 20px; font-weight: bold; display: none;">
<div id="winner-cell-id"></div><br>
<div id="winner-cell-hash"></div>
</td>
</tr>
</table>
</center><br>
</div>
<div id="ticket-table"></div>
<!-- Scripts -->
<!-- <script src="js/html2pdf.bundle.min.js"></script> -->
<script>
var numTickets;
var ticketHashes;
function generateTickets(){
var strVal = document.getElementById("numParticipants").value;
if (strVal == "" || isNaN(strVal)){
window.alert("Please enter a valid number");
return
}
numTickets = parseInt(strVal);
ticketHashes = [0];
var ticketTable = generateTable(numTickets);
document.getElementById("winner-cell").style.display = "none";
document.getElementById("winner-cell-id").innerHTML = "";
document.getElementById("winner-cell-hash").innerHTML = "";
document.getElementById("ticket-table").innerHTML = "";
document.getElementById("ticket-table").appendChild(ticketTable);
document.getElementById("select-winner-button").style.display = "block";
// saveTableAsPDF(ticketTable);
}
function generateTicketHash(id){
var hash = "";
var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++){
hash += charSet.charAt(Math.floor(Math.random() * charSet.length));
}
return "#"+hash;
}
function generateTable(numTickets){
numRows = Math.ceil(numTickets/5);
var tickets = document.createElement('table');
tickets.style.border = '1px solid black';
tickets.style.margin = '50px 50px 50px 50px';
tickets.style.pageBreakInside = 'avoid';
var counter = 0;
for (var i = 0; i < numRows; i++){
var tr = tickets.insertRow();
tr.style.pageBreakInside = 'avoid';
for (var j = 0; j < 5; j++){
counter += 1;
if (counter > numTickets){
break;
}
hash = generateTicketHash(counter);
ticketHashes.push(hash);
var td = tr.insertCell();
td.style.width = '350px';
td.style.height = '120px';
td.style.padding = '30px 10px 10px 10px';
td.style.textAlign = 'center';
td.style.fontWeight = 'bold';
td.style.fontSize = '20px';
td.style.pageBreakInside = 'avoid';
td.appendChild(document.createTextNode(counter));
td.appendChild(document.createElement('br'));
td.appendChild(document.createElement('br'));
td.appendChild(document.createTextNode(hash));
td.style.border = '1px solid black';
}
}
return tickets
}
function selectWinner(){
document.getElementById("winner-cell").style.display = "block";
var winner = Math.floor(Math.random()*numTickets) + 1;
var numAnim = new CountUp("winner-cell-id", 1, winner);
if (!numAnim.error) {
numAnim.start(getAndSetWinnerHash(winner, numAnim));
} else {
console.error(numAnim.error);
}
}
function getAndSetWinnerHash(winner, numAnim){
var hash = ticketHashes[winner];
numAnim.reset();
var winnerCellHash = document.getElementById("winner-cell-hash");
winnerCellHash.style.display = "block";
winnerCellHash.innerHTML = hash;
}
// function saveTableAsPDF(table){
// var element = table;
// html2pdf(element);
// }
</script>
</body>
</html>