-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
409 lines (371 loc) · 14 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bingo Card Generator</title>
<style type="text/css">
label,input, select {
display:block;
}
input,select {
margin-bottom:.5em;
}
legend { font-weight: bold }
div.clear { clear:both; }
div.break { clear:both; page-break-after:always; break-after:always; }
table {
background-color:black;
border-collapse:collapse;
margin-bottom:1em;
margin-right:1em;
float:left;
}
td, th {
border:1px solid black;
text-align:center;
}
th {
color:white;
height:50px;
font-family:Arial,Helvetica;
font-size:24px;
}
td {
background-color:white;
width:85px;
height:85px;
}
.freespace {
font-size:smaller;
}
#footer {
border-top:1px solid #ccc;
clear:both;
}
.daub {
background-repeat: no-repeat;
}
.daubPos1 {
background-position: 8px 8px;
}
.daubPos2 {
background-position: 3px 8px;
}
.daubPos3 {
background-position: 8px 3px;
}
.daubPos4 {
background-position: 12px 8px;
}
.daubPos5 {
background-position: 8px 12px;
}
.daubImg1 {
background-image: url(images/daub1.png);
}
.daubImg2 {
background-image: url(images/daub2.png);
}
.daubImg3 {
background-image: url(images/daub3.png);
}
.daubImg4 {
background-image: url(images/daub4.png);
}
.daubImg5 {
background-image: url(images/daub5.png);
}
</style>
<style type="text/css" media="print">
h1, form, #footer { display:none }
</style>
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js"></script>
<script type="text/javascript">
/*jslint browser: true, devel: true */
/* global $ */
var dauber = {
// If the target bingo card square has a daub, remove it. Otherwise, add a daub
toggle: function (e) {
"use strict";
var i;
var target = e.currentTarget;
if (target.classList.contains("daub")) {
for (i = 1; i <= 5; i = i + 1) {
target.classList.remove("daubImg" + i);
target.classList.remove("daubPos" + i);
}
target.classList.remove("daub");
} else {
target.classList.add("daub");
target.classList.add("daubPos" + Math.ceil(Math.random() * 5));
target.classList.add("daubImg" + Math.ceil(Math.random() * 5));
}
},
// Iterate over any bingo cards on the page and attach mouse/touch events to each square
init: function () {
"use strict";
var bingoSquare;
var bingoSquares = document.getElementById("results").getElementsByTagName("td");
for (bingoSquare of bingoSquares) {
bingoSquare.addEventListener("mousedown", this.toggle);
}
}
};
var bingoGenerator = {
pageBreaks: 'on', // automatically inserts a page break after every 2 cards
// Given an array, return the array minus any empty elements
removeEmptyElements: function (arr) {
"use strict";
var newArray = [], i = 0;
for (i = 0; i < arr.length; i += 1) {
if (arr[i]) {
newArray.push(arr[i]);
}
}
return newArray;
},
formatFreespace: function (str, subheading) {
"use strict";
return '<strong>' + str + '<div class="freespace">' + subheading + '</div></strong>';
},
bingoCard: function (title, width, height, freespace, freespaceValue, freespaceSubheadingValue, freespaceRandom, list) {
"use strict";
var possibleSpaces, enoughSpaces, spaces, centerSquare, i, j, output;
list = bingoGenerator.escapeHTML(list);
list = bingoGenerator.newlineToBR(list);
possibleSpaces = bingoGenerator.removeEmptyElements(list.split(","));
// Two options for including random Free Space:
// Option 1: We don't have enough. Include in random placement.
// Option 2:- We have enough. Overwrite other option.
enoughSpaces = true;
if (possibleSpaces.length < width * height) {
enoughSpaces = false;
}
// Option 1
if (freespace === "true" && freespaceRandom === "true" && !enoughSpaces) {
possibleSpaces.push(bingoGenerator.formatFreespace(freespaceValue, freespaceSubheadingValue));
}
// Create a random selection of the possible values
spaces = [];
// This works for squares with odd dimensions,, e.g. 3x3 or 5x5, but not for even squares or rectangles
// var centerSquare = Math.floor(width*height/2);
// We'll say center is the center row of the center column
centerSquare = Math.floor(height / 2) * width + Math.floor(width / 2);
for (i = 0; i <= width * height; i += 1) {
if (i === centerSquare && freespace === "true" && freespaceRandom === "false") {
spaces.push(bingoGenerator.formatFreespace(freespaceValue, freespaceSubheadingValue));
} else {
spaces.push(possibleSpaces.splice(Math.floor(Math.random() * possibleSpaces.length), 1)[0]);
}
}
// Option 2
if (freespace === "true" && freespaceRandom === "true" && enoughSpaces) {
spaces[Math.floor(Math.random() * spaces.length)] = bingoGenerator.formatFreespace(freespaceValue, freespaceSubheadingValue);
}
// Output
output = '<table><thead><tr><th colspan="' + width + '">' + title + '</th></tr></thead>';
output += '<tbody>';
for (i = 0; i < height; i += 1) {
output += '<tr>';
for (j = 0; j < width; j += 1) {
output += '<td>' + spaces.shift() + '</td>';
}
output += '</tr>';
}
output += "</tbody></table>";
$("#results").append(output);
},
// Generate Bingo Cards
generate: function () {
"use strict";
var colsFilled, rowsFilled, spaces, i;
// Check to make sure enough options are provided to fill the bingo card spaces
spaces = bingoGenerator.removeEmptyElements($("#words").val().split(",")).length;
if ($("#freespace").val()) {
spaces += 1;
}
if (spaces < $("#width").val() * $("#height").val()) {
alert("Warning: you do not have enough possible board options for the size of the board you selected!");
}
// Clear any previous results
$("#results").html("");
// Try to make nice printable pages -- we can fit about 10 pieces across and 6 down
colsFilled = 0;
rowsFilled = 1;
// Loop over number of cards requested
for (i = 0; i < document.getElementById("number").value; i += 1) {
colsFilled += 1;
if (bingoGenerator.pageBreaks === 'on' && colsFilled * $("#width").val() > 10) {
rowsFilled += 1;
if (rowsFilled * $("#height").val() > 6) {
$("#results").append('<div class="break"> </div>');
rowsFilled = 1;
} else {
$("#results").append('<div class="clear"></div>');
}
colsFilled = 1;
}
// Create bingo card
bingoGenerator.bingoCard(
$("#title").val(),
$("#width").val(),
$("#height").val(),
$("#freespace").val(),
$("#freespaceValue").val(),
$("#freespaceSubheadingValue").val(),
$("#freespaceRandom").val(),
$("#words").val()
);
}
// Jump to results
location.href = '#results';
},
// Replace + with spaces, <> with entities, and URL-decode &/,:;+=?%$@
urlUnencode: function (str) {
"use strict";
return decodeURI(str).replace(/</g, "<").
replace(/\+/g, " ").
replace(/%24/g, "$").
replace(/%25/g, "%").
replace(/%26/g, "&").
replace(/%2B/g, "+").
replace(/%2C/g, ",").
replace(/%2F/g, "/").
replace(/%3A/g, ":").
replace(/%3B/g, ";").
replace(/%3C/g, "<").
replace(/%3D/g, "=").
replace(/%3F/g, "?").
replace(/%40/g, "@");
},
escapeHTML: function (str) {
"use strict";
return str.replace(/</g, "<").replace(/>/g, ">");
},
newlineToBR: function (str) {
"use strict";
return str.replace(/\n/g, "<br>");
},
parseQS: function () {
"use strict";
var qsArray, json, i, kv, key, val;
// Remove leading question mark ("?") and split into array of key/value pairs
qsArray = location.search.slice(1).split("&");
// Initialize object to store key/value pairs
json = {};
// Loop through key/value pairs and separate into keys and values
for (i = 0; i < qsArray.length; i += 1) {
kv = qsArray[i].split("=");
key = kv[0];
if (kv.length === 1) {
val = key;
} else {
// A key may be present without a value, so set a placeholder value
val = kv[1];
}
json[key] = val;
}
return json;
},
checkQS: function () {
"use strict";
var qs = bingoGenerator.parseQS();
if (!(qs.title === undefined) || !(qs.words === undefined)) {
$("#intro").hide();
if (!(qs.title === undefined)) {
$("#title").val(bingoGenerator.urlUnencode(qs.title));
}
if (!(qs.words === undefined)) {
$("#words").val(bingoGenerator.urlUnencode(qs.words));
}
if (!(qs.freespace === undefined || qs.freespace === "false")) {
document.getElementById("freespace").selectedIndex = 0;
$("#freespaceValue").val(bingoGenerator.urlUnencode(qs.freespaceValue));
if (!(qs.freespaceSubheadingValue === undefined)) {
$("#freespaceSubheadingValue").val(bingoGenerator.urlUnencode(qs.freespaceSubheadingValue));
} else {
$("#freespaceSubheadingValue").val("Free Space");
}
if (!(qs.freespaceRandom === undefined) && qs.freespaceRandom === "true") {
document.getElementById("freespaceRandom").selectedIndex = 0;
}
} else {
document.getElementById("freespace").selectedIndex = 1;
$("#freespaceValue").val("");
}
if (!(qs.width === undefined)) {
$("#width").val(qs.width);
}
if (!(qs.height === undefined)) {
$("#height").val(qs.height);
}
if (!(qs.number === undefined)) {
$("#number").val(qs.number);
}
}
if (!(qs.pageBreaks === undefined)) {
bingoGenerator.pageBreaks = qs.pageBreaks;
}
if (qs.onlyCard === "true") {
$("#number").val(1);
$("h1").hide();
$("form").hide();
$("#footer").hide();
$("body").css("margin", 0);
$("table").css("margin", 0);
}
if (!(qs.title === undefined) && !(qs.words === undefined)) {
bingoGenerator.generate();
dauber.init();
}
}
};
$(document).ready(bingoGenerator.checkQS);
</script>
</head>
<body>
<h1>Make your own bingo cards</h1>
<form action="#results" method="get"><!-- onsubmit="generate();return false;" -->
<p id="intro">I've provided a sample to create bingo cards for a day in the park. You can enter your own settings to create your own custom bingo cards.</p>
<fieldset>
<legend>Bingo Card Basics</legend>
<label>Card Title <input type="text" name="title" id="title" value="Day in the Park Bingo"></label>
<label>Word List (separated by commas)</label><textarea cols="60" rows="8" name="words" id="words">Flowers,Bees,Picnickers,Ants,Little Kid Crying,Holding Hands,Person Napping,A Balloon,Dogs,Frisbee,Stroller,Chess Players,Rollerskates,Musician,Juggler,Photographer,Painter,Plastic Bag in Tree,Squirrel,Pigeon,Bicycle Built for Two,Ice Cream,Sunbather,Person Reading Newspaper,Person Listening to Radio,Sidewalk Chalk,Hopscotch</textarea>
</fieldset>
<fieldset>
<legend>Free Space</legend>
<label>Include a free space?
<select name="freespace" id="freespace">
<option value="true" selected="selected">Yes</option>
<option value="false">No</option>
</select>
</label>
<label>Free Space Text <input type="text" name="freespaceValue" id="freespaceValue" value="Park Bench"></label>
<label>Free Space Description <input type="text" name="freespaceSubheadingValue" id="freespaceSubheadingValue" value="Free Space"></label>
<label>Free Space Placement
<select name="freespaceRandom" id="freespaceRandom">
<option value="true">Random</option>
<option value="false" selected="selected">Center</option>
</select>
</label>
</fieldset>
<fieldset>
<legend>Card Size</legend>
<p>A 5x5 bingo card is traditional, but you can try other sizes</p>
<label>Number of Squares Wide <input type="text" name="width" id="width" value="5"></label>
<label>Number of Squares Tall <input type="text" name="height" id="height" value="5"></label>
</fieldset>
<fieldset>
<legend>Printing Options</legend>
<p>Select the <em>landscape</em> page layout when printing for best results</p>
<label>Number of cards to create <input type="text" name="number" id="number" value="10"></label>
</fieldset>
<label><input type="submit" value="Generate Bingo Cards"></label>
</form>
<div id="results"></div>
<div id="footer">
<a href="/bingo-card-generator/faq.html">Questions?</a> Comments? Contact chris @ osric . com
</div>
</body>
</html>