-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.html
More file actions
504 lines (440 loc) · 17.5 KB
/
setup.html
File metadata and controls
504 lines (440 loc) · 17.5 KB
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<!doctype html>
<html>
<!--
You can easily run the oMST without this file.
Typically, JATOS studies just run in order, going through whatever tasks you have setup.
This file lets you define an "order" variable that other tasks can respect to queue up
various different tasks or task orders. You'll see at the end of the experiment code bits
about seeing if this variable exists and, if so, to use it to queue up the next task.
Otherwise, this file can be useful as a splash screen or to pre-define some variables,
such as the kind of response (button vs. keyboard) to use, what set to use, etc. You'll
find that the main experiment code looks in several places (e.g., here, Properties in the
experiment or in the Batch from JATOS) to let you flexibly override defaults.
-->
<head>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/jspsych_731/dist/jspsych.js"></script>
<script src="js/jspsych_731/dist/plugin-preload.js"></script>
<script src="js/jspsych_731/dist/plugin-html-button-response.js"></script>
<script src="js/jspsych_731/dist/plugin-html-keyboard-response.js"></script>
<script src="js/jspsych_731/dist/plugin-fullscreen.js"></script>
<script src="jatos.js"></script>
<script src="helpers.js"></script>
<link rel="stylesheet" href="css/pure-release-0.6.0/pure-min.css">
<link rel="stylesheet" href="css/jspsych.css"></link>
<link
rel="preload"
href="img/assets/blank_green.png"
as="image"
/>
<link
rel="preload"
href="img/assets/blank_green_pressed.png"
as="image"
/>
<link
rel="preload"
href="css/fonts/ComicRelief-Regular.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="css/fonts/ComicRelief-Bold.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<style>
body {
margin:0;
height:100vh;
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
text-align:center;
}
.image-btn-text text {
font-size: 1.2em;
}
.mobile .image-btn-text text{
font-size: 1.2em;
letter-spacing: 0.12em;
}
.image-btn-text.kr text,
.image-btn-text.ru text{
font-size: 0.9em;
}
.image-btn-text.kr .text-stroke,
.image-btn-text.ru .text-stroke {
stroke-width: 8;
}
.image-btn-text.nl text{
font-size: 0.8em;
}
.image-btn-text.nl .text-stroke {
stroke-width: 8;
}
.mobile .image-btn-text.kr text {
font-size: 0.9em;
}
.mobile .image-btn-text.kr .text-stroke {
stroke-width: 9;
}
.mobile .image-btn-text.nl text {
font-size: 0.8em;
}
.mobile .image-btn-text.nl .text-stroke {
stroke-width: 8;
}
.mobile .image-btn-text.ru text {
font-size: 1.0em;
}
.tablet .image-btn-text text {
font-size: 1.3em;
}
.tablet .image-btn-text.kr text {
font-size: 1em;
}
.tablet .image-btn-text.kr .text-stroke {
stroke-width: 8;
}
.tablet .image-btn-text.ru text {
font-size: 1.0em;
}
.prompt_text {
font-size: 2.6em;
}
.mobile .prompt_text {
font-size: 2em;
}
.mobile .prompt_text.nl {
font-size: 1.8em;
}
.mobile .prompt_text.ru {
font-size: 1.6em;
}
.tablet .prompt_text{
font-size: 1.2em;
}
.smallScreen .prompt_text {
font-size: 2em;
}
.tablet .prompt_text.intro {
font-size: 2em;
}
.mobile .prompt_text.es.intro,
.mobile .prompt_text.nl.intro {
font-size: 1.8em;
}
.mobile .prompt_text.ru.intro {
font-size: 1.8em;
}
.smallScreen .prompt_text.ru.intro {
font-size: 0.9em;
}
</style>
</head>
<body style="text-align: center;">
</body>
<script type="text/javascript">
function getID() {
// Try to get a reasonable ID code for this person. You can use the URL with a "sid" parameter or
// specify one in the jatos studySessionData. If not, it'll use the JATOS workerId.
// URL > studySession > workerID
var sid=jatos.urlQueryParameters.sid;
if (sid == undefined) {
sid=jatos.studySessionData['sid'];
}
if (typeof sid == 'undefined') {
if (typeof jatos.workerId !== 'undefined') { // At least try the workerID
sid = jatos.workerId;
}
else { sid=1234; }
}
return sid
}
jatos.onLoad(async function () {
// Useful for debugging. There are a number of options for keeping track of your subject's ID code.
// JATOS will create their own, but you may have one come in via a URL parameter if you're using
// something like SONA or Qualtrics. It might not be "sid" -- it's just what I use.
//console.log('In setup, URL sid= ' + jatos.urlQueryParameters.sid);
// We use JATOS' Batch Session to store the number of runs that have been
// completed and we use this to divvy up the actual counterbalance condition
// It's a simple, but effective enough scheme for this. Here, we'll use it
// to just determine which stimulus set gets used.
if (!jatos.batchSession.defined("/nruns")) { // If we don't have this field yet, make it
jatos.batchSession.set("nruns", 0);
}
var nruns = jatos.batchSession.get("nruns");
if (typeof nruns === 'undefined') { // Just catch in case of errors
var nruns=0;
}
var cond = nruns % 2; // We'll give ourselves just conditions here for 2 stimulus sets
// But, we'll also let you set JATOS' properties to force a particular condition
if (jatos.componentJsonInput && typeof jatos.componentJsonInput['force_cond'] !== 'undefined') {
cond=jatos.componentJsonInput['force_cond'];
console.log('condition forced via JSON component to ' + cond);
}
var order=[]; // Default order skips consent and demographics and does study/test -- will add "end" later
var include_consent=0;
var include_demographics=0;
var include_idcode=0;
var include_pcon=0;
var include_pairwise=0;
var include_omst=1;
// Useful little tags for the experiment and condition that will go into your log files
var exptag='oMST'
var condtag='Unk'
// Setup things for your various counter-balances. Here, we only have 2 (which set is used)
switch (cond) {
case 0: // Stimulus set 1
jatos.studySessionData['set_omst']=1;
condtag='oMST-1';
break;
case 1: // Stimulus set 2
jatos.studySessionData['set_omst']=2;
condtag='oMST-2';
break;
}
// Various manual overrides of that
let sid=getID(); // Come up with a nice ID number for this person
var urlsid=0; // Always log this as a backup
if (typeof jatos.urlQueryParameters.sid !== 'undefined') {
urlsid = jatos.urlQueryParameters.sid;
}
console.log('order: ' + order + ' cond: ' + cond + ' sid: ' + sid);
// Go stick relevant information in the studySessionData. Experiment code reads this for the defaults.
// You can use the various force_XXX options shown in the code to override this (e.g., put a force_set in the
// JATOS component properties for a task)
jatos.studySessionData['sid']=sid;
jatos.studySessionData["order"] = order; // this is that order of tasks shown, not the order of trials in a task
jatos.studySessionData["cond"] = cond;
jatos.studySessionData["taskindex"] = 0;
jatos.studySessionData['exptag'] = exptag;
jatos.studySessionData['condtag'] = condtag;
console.log(include_consent,include_demographics,include_idcode,include_pcon,order)
// Now, take any possible things we'd see in the JSON input and convert them to studySessionData so
// that the individual tasks have a consistent spot to find them.
if (jatos.studyJsonInput && typeof jatos.studyJsonInput['resp_mode'] !== 'undefined') {
jatos.studySessionData['resp_mode']=jatos.studyJsonInput['resp_mode'];
}
if (jatos.studyJsonInput && typeof jatos.studyJsonInput['selfpaced'] !== 'undefined') {
jatos.studySessionData['selfpaced']=jatos.studyJsonInput['selfpaced'];
}
if (typeof jatos.studyJsonInput['set_omst'] !== 'undefined') {
jatos.studySessionData['set_omst']=jatos.studyJsonInput['set_omst'];
}
if (typeof jatos.studyJsonInput['include_demographics'] !== 'undefined') {
include_demographics=jatos.studyJsonInput['include_demographics'];
//console.log('study json include demog' + include_demographics);
}
if (typeof jatos.studyJsonInput['include_consent'] !== 'undefined') {
include_consent=jatos.studyJsonInput['include_consent'];
}
if (typeof jatos.studyJsonInput['include_idcode'] !== 'undefined') {
include_idcode=jatos.studyJsonInput['include_idcode'];
}
if (typeof jatos.studyJsonInput['include_pcon'] !== 'undefined') {
include_pcon=jatos.studyJsonInput['include_pcon'];
}
if (typeof jatos.studyJsonInput['include_icon'] !== 'undefined') {
include_pcon=jatos.studyJsonInput['include_icon'];
}
if (typeof jatos.studyJsonInput['include_pairwise'] !== 'undefined') {
include_pairwise=jatos.studyJsonInput['include_pairwise'];
}
if (typeof jatos.studyJsonInput['include_omst'] !== 'undefined') {
include_omst=jatos.studyJsonInput['include_omst'];
}
if (jatos.studyJsonInput) { console.log('jatos.studyJsonInput: ', jatos.studyJsonInput)}
console.log(include_consent,include_demographics,include_idcode,include_pcon,include_pairwise,order);
console.log(jatos.studyJsonInput);
//console.log(jatos.batchProperties.title);
// Now, let any batch-level bits override those
if (jatos.batchJsonInput) { console.log('jatos.batchJsonInput: ', jatos.batchJsonInput)}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['resp_mode'] !== 'undefined' ) {
jatos.studySessionData['resp_mode']=jatos.batchJsonInput['resp_mode'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['set_omst'] !== 'undefined' ) {
jatos.studySessionData['set_omst']=jatos.batchJsonInput['set_omst'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['selfpaced'] !== 'undefined' ) {
jatos.studySessionData['selfpaced']=jatos.batchJsonInput['selfpaced'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_demographics'] !== 'undefined' ) {
include_demographics=jatos.batchJsonInput['include_demographics'];
console.log('include_demographics batch' + include_demographics);
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_consent'] !== 'undefined' ) {
include_consent=jatos.batchJsonInput['include_consent'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_idcode'] !== 'undefined' ) {
include_idcode=jatos.batchJsonInput['include_idcode'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_pcon'] !== 'undefined' ) {
include_pcon=jatos.batchJsonInput['include_pcon'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_icon'] !== 'undefined' ) {
include_pcon=jatos.batchJsonInput['include_icon'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_pairwise'] !== 'undefined' ) {
include_pairwise=jatos.batchJsonInput['include_pairwise'];
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['include_omst'] !== 'undefined' ) {
include_omst=jatos.batchJsonInput['include_omst'];
}
console.log(include_consent,include_demographics,include_idcode,include_pcon,include_pairwise,order)
if (typeof jatos.urlQueryParameters.set_mst !== 'undefined') {
jatos.studySessionData['set_omst'] = jatos.urlQueryParameters.set_omst;
}
if (include_omst) {
order.unshift(6);
order.unshift(5);
}
if (include_pcon) { order.unshift(8); }
if (include_pairwise) { order.unshift(9); }
if (include_demographics) { order.unshift(4); }
if (include_consent) {order.unshift(3); }
if (include_idcode) {order.unshift(2); }
//if (include_pcon) {order.push(6); }
order.push(7); // Add the "end", which is #7 currently
console.log('Final order: ' + order);
if (jatos.studySessionData['set_omst'] == -1) { // randomize the set and subset
jatos.studySessionData['set_omst'] = Math.floor(Math.random() * 6) + 1;
jatos.studySessionData['subset'] = Math.floor(Math.random() * 3) + 1;
console.log('Stimulus set randomized to ',jatos.studySessionData['set_omst'],jatos.studySessionData['subset'])
}
jatos.studySessionData["order"] = order;
console.log('Worker ID/sid=' + sid + ' URLSID='+urlsid+' omst set='+jatos.studySessionData["set_omst"] );
console.log('order: ' + order);
//console.log('set: ' + jatos.urlQueryParameters.set_mst);
console.log('full: ' + jatos.urlQueryParameters)
console.log("includes: " + include_demographics + include_consent + include_idcode)
var d= new Date();
jatos.appendResultData({
task: "setup-oMST",
subject: sid,
urlsid: urlsid,
selfpaced: jatos.studySessionData['selfpaced'],
respmode: jatos.studySessionData['resp_mode'],
oMSTSet: jatos.studySessionData["set_omst"],
lang: jatos.studySessionData["lang"],
date: d.toString()
});
var classicGraphics = 0;
if (typeof jatos.studySessionData['plain_graphics'] !== 'undefined') {
classicGraphics = jatos.studySessionData['plain_graphics'];
}
if (jatos.studyJsonInput && typeof jatos.studyJsonInput['plain_graphics'] !== 'undefined' ) {
classicGraphics=jatos.studyJsonInput['plain_graphics']
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['plain_graphics'] !== 'undefined' ) {
classicGraphics=jatos.batchJsonInput['plain_graphics']
}
// Save for next page load
localStorage.setItem('classicGraphics', classicGraphics);
// Apply it now
if (classicGraphics === 1) {
document.body.style.backgroundColor = '#ffffff';
} else {
document.body.style.backgroundColor = '#fff9e0';
}
const device = getDeviceType();
console.log("have device " + device);
const isMobile = device[0];
const isTablet = device[1];
const smallScreen = device[2];
console.log("smallScreen " + smallScreen);
const canvasWidth = isMobile ? window.innerWidth * 0.9 : window.innerWidth * .9;
const canvasHeight = isMobile ? window.innerHeight * 0.7 : smallScreen ? window.innerHeight * 0.75 : isTablet ? window.innerHeight * 0.8 : window.innerHeight * .75;
const fontScale = isMobile ? 1.5 : 1.0;
const stimScale = isMobile ? 2 : smallScreen ? 0.85: isTablet ? 1.2 : 1.0;
document.body.classList.add(isMobile ? 'mobile' : 'desktop');
if (smallScreen) {document.body.classList.add('smallScreen');}
if (isTablet) {document.body.classList.add('tablet');}
if (classicGraphics) {document.body.classList.add('classic');}
var setup = {
type: jsPsychHtmlButtonResponse,
choices: ["Continue"],
button_html: classicGraphics ?
`<div class="image-btn-wrapper">
<input type="image" src="img/assets/blank_button.png"
class="image-btn" id="continueButton">
<svg class="image-btn-text" viewBox="0 0 266 160">
<text x="50%" y="50%">Continue</text>
</svg>
</div>`
:
`<div class="image-btn-wrapper">
<input type="image" src="img/assets/blank_green.png"
class="image-btn" id="continueButton">
<svg class="image-btn-text" viewBox="0 0 266 160">
<text class="text-stroke" x="50%" y="50%">Continue</text>
<text class="text-fill" x="50%" y="50%">Continue</text>
</svg>
</div>`,
stimulus:
`<p class="prompt_text intro" style="text-align:center;">
Welcome to the experiment!
<br><br><strong>Do not hit your browser's back button or the experiment will terminate</strong>
</p>`,
on_load: function() {
setupButtonListeners();
},
on_finish: function() {
cleanupButtonListeners();
var nruns = jatos.batchSession.get("nruns");
jatos.batchSession.set("nruns", nruns+1);
var order = jatos.studySessionData["order"];
var d = new Date();
jatos.studySessionData['datecode'] = d.toLocaleDateString();
console.log('Starting component at position ' + order[jatos.studySessionData["taskindex"]]);
jatos.startComponentByPos(order[jatos.studySessionData["taskindex"]]);
console.log('=== VERIFYING CACHE BEFORE NAVIGATION ===');
const testImages = [
"img/assets/blank_green.png",
"img/assets/blank_green_pressed.png",
"img/assets/blank_red.png",
"img/assets/blank_red_pressed.png"
];
testImages.forEach(src => {
const img = document.createElement('img');
img.src = src;
console.log(`Cache test: ${src} - complete: ${img.complete}`);
});
// Wait a moment to ensure cache commits before navigating
setTimeout(() => {
var nruns = jatos.batchSession.get("nruns");
jatos.batchSession.set("nruns", nruns+1);
var order = jatos.studySessionData["order"];
var d = new Date();
jatos.studySessionData['datecode'] = d.toLocaleDateString();
jatos.startComponentByPos(order[jatos.studySessionData["taskindex"]]);
}, 100); // Small delay to ensure cache commits
},
}
var timeline = [setup];
var jsPsych = initJsPsych({
on_finish: function() {
// Optional: what to do when experiment finishes
}
});
jsPsych.run(timeline);
});
// Add event listeners once DOM is ready
document.addEventListener("DOMContentLoaded", () => {
const wrapper = document.querySelector('.image-btn-wrapper');
// Mouse hover
wrapper.addEventListener('mouseenter', handlePress, true);
wrapper.addEventListener('mouseleave', handleRelease, true);
// Touch
wrapper.addEventListener('touchstart', handlePress, { passive: true });
wrapper.addEventListener('touchend', handleRelease);
// Fallback for mouseup anywhere
document.addEventListener('mouseup', handleRelease);
});
</script>
</html>