-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snap2.html
282 lines (221 loc) · 8.73 KB
/
Snap2.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
<!DOCTYPE html>
<html>
<head>
<title>Patient Questionnaire</title>
<meta charset=utf-8 />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--My Own CSS-->
<link rel="stylesheet" href="themes/formatting.css" />
<!--JQuery Mobile CSS-->
<link rel="stylesheet" href="themes/MyTheme.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<!--<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>-->
<!--JQuery Mobile JavaScript-->
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<!--External scripts needed for date-picker-->
<link rel="stylesheet" href="http://code.jquery.com/mobile/git/jquery.mobile-git.css" />
<link rel="stylesheet" href="https://rawgithub.com/arschmitz/jquery-mobile-datepicker-wrapper/master/jquery.mobile.datepicker.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://rawgithub.com/jquery/jquery-ui/1-10-stable/ui/jquery.ui.datepicker.js"></script>
<script src="http://code.jquery.com/mobile/git/jquery.mobile-git.js"></script>
<script src="https://rawgithub.com/arschmitz/jquery-mobile-datepicker-wrapper/master/jquery.mobile.datepicker.js"></script>
<!--Extrenal scripts needed for knockout library-->
<script type='text/javascript' src='knockout-3.1.0.js'></script>
<!--External scripts needed for imagemapster plugin-->
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>-->
<script src="jquery.imagemapster.js"></script>
<style>
.number{position:relative;left:49%;top:15%font-weight:bold;font-size:80px;color:#5108FA;}
.snapCard{float: right;}
#step2But,#step3But,#step4But{width:20% !important;position:fixed;left:37%;}
</style>
<script>
var picture=['jackOfDiamonds.gif','queenOfClubs.jpg', 'kingOfClubs.jpg'];
var rand1 = Math.floor(Math.random()*picture.length);
var rand2 = Math.floor(Math.random()*picture.length);
window.onload = function(){
}
</script>
</head>
<body>
<div data-role="page" id="SnapInstructionsPage" data-theme="d">
<div data-role="header">
<h1>Patient Survey; Snap!</h1>
</div>
<div data-role="main" class="ui-content">
<div id='anywhere'>
<img src="themes/myImages/NHSlogo.jpg" alt="NHS Scotland" width="85" height="52" id="nhsLogo">
<div id='step1' style="width:45%;position:fixed;top:30%;left:27%;">
<h2>In order to measure your reaction time, <span style="position:relative;left:8%;">a game of 'Snap' will now follow.</span></h2>
<br>
<button id='step2But'>Learn How to Play ></button>
</div>
<div id='step2' style='display:none;width:70%;position:fixed;left:15%;top:15%;'>
<h3>1. You will be shown two picture cards. If the two cards match, touch <span style='position:relative;left:3%'>anywhere on the screen as fast as you can.</span></h3>
<img style="position:fixed;left:20%;"src="themes/myImages/snapCards.png" alt="snapCards" width="510" height="312" class="snapCard">
<button style="position:fixed;top:80%;" id='step3But'>Next ></button>
</div>
<div id='step3' style='display:none;position:fixed;'>
<h3 style="position:fixed;left:20%;top:10%;">3. If you are correct the message 'Snap!' will appear.</h3>
<img style="position:fixed;left:20%;top:25%;" src="themes/myImages/snapCorrect.png" alt="snapCorrect" width="510" height="312" class="snapCard">
<button style='top:70%;' id='step4But'>Next ></button>
</div>
<div id='step4' style='display:none;position:fixed;top:10%;left:10%;'>
<h3>4. If you are wrong a red 'X' will appear.</h3>
<img style="position:fixed;left:25%;top:20%;"src="themes/myImages/snapIncorrect.png" alt="snapWrong" width="510" height="312" class="snapCard">
<a style='position:fixed;top:70%;' data-role="button" id="playSnap" href="#">Play Snap!</a>
</div>
</div>
<p>DEBUG: <pre data-bind="text: ko.toJSON($data,null,2)"></pre> </p>
</div><!--main content-->
<div data-role="footer" data-position="fixed">
<h2>© Edinburgh University 2014</h2>
</div>
</div> <!--close anywhere-->
</div><!--End of SnapInstructionPage-->
<div data-role="page" id="SnapPage" data-theme="d">
<div data-role="header">
<h1>Patient Survey; Snap!</h1>
</div>
<div data-role="main" class="ui-content">
<div id='anywhere'>
<img src="themes/myImages/NHSlogo.jpg" alt="NHS Scotland" width="85" height="52" id="nhsLogo">
<div class="ui-grid-b">
<div class="ui-block-a" style="width: 20%; margin-left: 35%;">
<button type="button" id="card1" class='snap'></button>
</div>
<div class="ui-block-b" style="width: 20%; margin-left: 0%;">
<button type="button" id="card2" class='snap'></button>
</div>
</div><!-- /grid-a -->
<div id='snapWrapper'>
</div>
<div id='score'>
</div>
</div>
<p>DEBUG: <pre data-bind="text: ko.toJSON($data,null,2)"></pre> </p>
<a style='visibility:hidden;' data-role="button" id="nextButton" href="#" onclick="nextPage()"></a>
</div><!--main content-->
<div data-role="footer" data-position="fixed">
<h2>© Edinburgh University 2014</h2>
</div>
</div> <!--close anywhere-->
</div><!--End of SnapPage-->
<script type='text/javascript'>
var card1url;
var card2url;
var url1;
var url2;
var clicked=false;
var score=[];
var index=0;
var t0;
var t1;
var gameStart=false;
var round=1;
function recursiveTimer(round)
{
var interval = setInterval(function(){
t0 = '';
t1 = '';
round += 1;
if(round == 13)
{
clearInterval(interval);
$("#nextButton").css('visibility', 'visible');
alert('Game Over! Your average reaction time was '+ computeAvg()+'ms');
}else if(clicked)
{
clearInterval(interval);
setTimeout(function(){
clicked=false;
recursiveTimer(round-1);
}, 550);
}else{
rand1 = Math.floor(Math.random()*picture.length);
rand2 = Math.floor(Math.random()*picture.length);
$('#card1').css("background-image", "url('themes/myImages/"+picture[rand1]+"')");
$('#card2').css("background-image", "url('themes/myImages/"+picture[rand2]+"')");
gameStart=true;
t0 = Date.now();
$("#snapWrapper").html(" ");
}
}, 3000);
}//recursiveTimer
$( document ).delegate("#SnapPage", "pagecreate", function() {
$('#card1').css("background-image", "url('themes/myImages/card_back.jpg')");
$('#card2').css("background-image", "url('themes/myImages/card_back.jpg')");
$("#snapWrapper").html('<div class="number"> 3 </div>');
setTimeout(function(){
$("#snapWrapper").html('<div class="number"> 2 </div>');
}, 1000);
setTimeout(function(){
$("#snapWrapper").html('<div class="number"> 1 </div>');
}, 2000);
recursiveTimer(round);
$("#SnapPage").on('click', function(e) {
if(gameStart)
{
lookForMatch();
}
});
}); //scripts for onload of #SnapPage
$(function() {
});
$("#step2But").on('click', function(e) {
$("#step2").css('display', 'block');
$("#step1").css('display', 'none');});
$("#step3But").on('click', function(e) {
$("#step3").css('display', 'block');
$("#step2").css('display', 'none');});
$("#step4But").on('click', function(e) {
$("#step4").css('display', 'block');
$("#step3").css('display', 'none');});
function lookForMatch(){
t1 = Date.now();
clicked=true;
card1url = $('#card1').css('background-image');
card2url = $('#card2').css('background-image');
url1 = card1url.split("myImages/");
url2 = card2url.split("myImages/");
if(url1[1]==url2[1])
{
var rt = t1-t0;
score.push(rt);
//alert(score + 'ms');
$("#score").append("<br> "+score[index]+'ms');
index++;
$("#snapWrapper").append(" <br> <span style='position:relative;left:45%;top:15%font-weight:bold;font-size:80px;color:#0DBA47;'>Snap!</span>");
setTimeout(function(){
//allow time for participant to register visual feedback
}, 1000);
}else
{
$("#snapWrapper").append("<br> <span style='position:relative;left:49%;top:15%font-weight:bold;font-size:83px;color:#F5033B;'>X</span>");
};
}
$("#score").append("Reaction time: ");
function computeAvg()
{
var total=0;
for(i=0; i<score.length; i++)
{
total=total+score[i];
}
return total/score.length;
}
$("#playSnap").on('click', function(e){nextPage();});
function nextPage() {
var currentPageID = $.mobile.activePage.attr('id');
switch (currentPageID) {
case "SnapInstructionsPage":
$.mobile.changePage("#SnapPage");
break;
default:
break;
}
}
</script>
</body>
</html>