-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo.js
84 lines (72 loc) · 2.75 KB
/
bingo.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
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
/*jslint browser: true */
/*globals window, $ */
if (window.location.hash) {
window.location.href =
window.location.protocol + '//' +
window.location.host +
(window.location.port ? ':' + window.location.port : '') +
window.location.pathname;
}
$(document).ready(function() {
function load_bingo(data) {
var count = 0;
$.each(data, function(key) {
var tmp = "",
j,
i,
tmp_index,
is_in_selection = true,
selection = [];
// Pick 5 random items
for(j=0; j<5;j++)
{
is_in_selection = true;
while(is_in_selection === true){
tmp_index = Math.floor(Math.random()*(data[key].length));
if ($.inArray(tmp_index, selection) !== -1)
{
is_in_selection = true;
}
else
{
is_in_selection = false;
selection[j]= tmp_index;
}
}
}
for(i = 0; i<5; i++) {
tmp += '<input type = "checkbox" name="'+ data[key][selection[i]].replace(/\s/g,"-") +
'" class="custom" id="'+ data[key][selection[i]].replace(/\s/g,"-") + '" />' +
'<label for="'+ data[key][selection[i]].replace(/\s/g,"-") + '">'+ data[key][selection[i]] + '</label>';
}
$("#firstlist").append('<li><a href="#show-'+key+'">'+ key + '</a></li>');
$("body").append('<div data-role="page" data-url="show-'+key+'" id="show-'+key+'"><div data-role="header"><h1>'+
key +'</h1></div><div data-role="content">'+tmp+'</div></div>');
$("#show-"+key+" input[type='checkbox']").change( function() {
count++;
// If you have 5 Items selected, it will play a sound and notify you
if(count>=5) {
$("audio").get(0).play();
window.alert("Du hast gewonnen");
window.location.reload(true);
count=0;
}
});
}); // end foreach
$('ul').listview('refresh');
}
/* Getting actual Data if your browser is online
* Save the data in the localstorage
*/
if(window.navigator.onLine) {
$.ajax({
url: 'http://buzzwords.tladesignz.com/data.pl',
dataType: 'jsonp',
success: function(data) {
localStorage.bullshit = JSON.stringify(data);
}
});
}
// Load data from localstorage
load_bingo(JSON.parse(localStorage.bullshit));
});