-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
242 lines (214 loc) · 6.67 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
<!doctype html>
<html>
<head>
<title>Customize style</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://cdn.firebase.com/js/client/2.2.7/firebase.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<style>
body {
text-align: center;
}
#g1, #g2, #g3, #g4, #g5, #g6 {
width:200px; height:160px;
display: inline-block;
margin: 1em;
cursor: pointer;
}
p {
display: block;
width: 450px;
margin: 2em auto;
text-align: left;
}
</style>
<script src="js/raphael.2.1.0.min.js"></script>
<script src="js/justgage.1.0.1.min.js"></script>
<script>
var g1, g2, g3, g4, g5, g6;
var v1, v2, v3, v4, v5, v6 = 0;
window.onload = function(){
g1 = new JustGage({
id: "g1",
value: 0,
min: 0,
max: 100,
title: "AGHH",
label: "%",
showMinMax: false,
startAnimationTime: 2000,
startAnimationType: ">",
refreshAnimationTime: 1000,
refreshAnimationType: "bounce"
});
g2 = new JustGage({
id: "g2",
value: 0,
min: 0,
max: 100,
title: "BAD",
label: "%",
showMinMax: false,
startAnimationTime: 2000,
startAnimationType: ">",
refreshAnimationTime: 1000,
refreshAnimationType: "bounce"
});
g3 = new JustGage({
id: "g3",
value: 0,
min: 0,
max: 100,
title: "MEHHH",
label: "%",
showMinMax: false,
startAnimationTime: 2000,
startAnimationType: ">",
refreshAnimationTime: 1000,
refreshAnimationType: "bounce"
});
g4 = new JustGage({
id: "g4",
value: 0,
min: 0,
max: 100,
title: "YES!!",
label: "%",
showMinMax: false,
startAnimationTime: 2000,
startAnimationType: ">",
refreshAnimationTime: 1000,
refreshAnimationType: "bounce"
});
g5 = new JustGage({
id: "g5",
value: 0,
min: 0,
max: 100,
title: "AWESOME!!",
label: "%",
showMinMax: false,
startAnimationTime: 2000,
startAnimationType: ">",
refreshAnimationTime: 1000,
refreshAnimationType: "bounce"
});
// setInterval(function() {
// var t1 = getRandomInt(0, 100)
// g5.refresh(t1);
// var t2 = getRandomInt(0, 100-t1)
// g4.refresh(t2);
// var t3 = getRandomInt(0, 100-(t1+t2))
// g3.refresh(t3);
// var t4 = getRandomInt(0, 100-(t1+t2+t3))
// g2.refresh(t4);
// g1.refresh(100-(t1+t2+t3+t4));
// }, 2500);
var fb = new Firebase("https://votar.firebaseio.com/poll1/");
// monitors changes and updates UI
fb.child('g1').child('counter').on('value', updateG1);
fb.child('g2').child('counter').on('value', updateG2);
fb.child('g3').child('counter').on('value', updateG3);
fb.child('g4').child('counter').on('value', updateG4);
fb.child('g5').child('counter').on('value', updateG5);
// fb.on('value', updatePre); //For demo purposes
// creates a new, incremental record
$('#g1').on('click', incId1);
$('#g2').on('click', incId2);
$('#g3').on('click', incId3);
$('#g4').on('click', incId4);
$('#g5').on('click', incId5);
var errId = 0;
// creates a new, incremental record
function incId1(){
incId('g1')
}
function incId2(){
incId('g2')
}
function incId3(){
incId('g3')
}
function incId4(){
incId('g4')
}
function incId5(){
incId('g5')
}
function incId(op) {
// increment the counter
fb.child(op).child('counter').transaction(function(currentValue) {
return (currentValue||0) + 1
}, function(err, committed, ss) {
if( err ) {
setError(err);
}
else if( committed ) {
// if counter update succeeds, then create record
// probably want a recourse for failures too
addRecord(ss.val());
}
});
}
// creates new incremental record
function addRecord(id) {
setTimeout(function() {
fb.child('recs').child('rec'+id).set('rec #'+id, function(err) {
err && setError(err);
});
});
}
function actualizaPorcentajes(){
var t = v1+v2+v3+v4+v5;
var v = parseInt(v1 * 100/t);
g1.refresh(v||0);
var v = parseInt(v2 * 100/t);
g2.refresh(v||0);
var v = parseInt(v3 * 100/t);
g3.refresh(v||0);
var v = parseInt(v4 * 100/t);
g4.refresh(v||0);
var v = parseInt(v5 * 100/t);
g5.refresh(v||0);
}
function updateG1(ss) {
v1 = ss.val();
actualizaPorcentajes();
}
function updateG2(ss) {
v2 = ss.val();
actualizaPorcentajes();
}
function updateG3(ss) {
v3 = ss.val();
actualizaPorcentajes();
}
function updateG4(ss) {
v4 = ss.val();
actualizaPorcentajes();
}
function updateG5(ss) {
v5 = ss.val();
actualizaPorcentajes();
}
// for demo purposes
function updatePre(ss) {
$('#data').text(JSON.stringify(ss.val(), null, 2));
}
// resets the data
$('#reset').on('click', function() {
fb.remove();
});
};
</script>
</head>
<body>
<div id="g1"></div>
<div id="g2"></div>
<div id="g3"></div>
<div id="g4"></div>
<div id="g5"></div>
<div id="data"></div>
<button id="reset">Reset</button>
</body>
</html>