-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
235 lines (194 loc) · 8.14 KB
/
index.html
File metadata and controls
235 lines (194 loc) · 8.14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Experiment Title -->
<title>Experiment</title>
<!-- Loading in libraries -->
<script src="jspsych_v8.0.1/dist/jspsych.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-survey-html-form.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-video-rating-continuous.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-html-keyboard-response.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-image-button-response-modified.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-preload.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-fullscreen.js"></script>
<script src="jspsych_v8.0.1/dist/plugin-browser-check.js"></script>
<link rel="stylesheet" href="jspsych_v8.0.1/dist/jspsych.css">
<!-- Loading in text, scales, labels, & functions -->
<script src="components/Text.js"></script>
</head>
<!-- Determining general page style parameters -->
<body style="background-color: rgb(200, 200, 200);">
<script>
/*
This is an example of what a really simple continuous rating experiment might look like in jsPsych. I incorporated a few QA checks (checks browser compatibility and window size), an example of how I've captured consent in the past (I just used a consent from a defunct study), some instructions, and then the actual task.
Generally with jsPsych, you'll load the plugins, or functions, as we did above. Then you'll define how you actually want to use those functions, and then you need to push them to a timeline in the order that you want them to appear. You can get real crazy with randomization, counterbalancing, etc. as needed, and there's also a lot of integration with pavlovia and prolific which I didn't include in here, but this should at least give you an idea to know if it might work for your purposes.
As of now, the video-rating-continuous plugin only exists in this repo, but I'll probably try to pitch it to the jsPsych folks once it's been tested a little more. So either run this directory as I have or download the dist directory from jsPsych and add this plugin to the collection.
*/
// Creating a timeline in which to push different components of this experiment
var timeline = [];
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
// | - - - - - - - - EXPERIMENT VARIABLES - - - - - - - |
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
// Initiating the experiment, defining where to save the data output
// NOTE that is will save to your browser's default downloads directory. I am not aware of another way to do this, but this is really only a problem when you run it locally. If you host it on Pavlovia or something like that, it will save to their servers for you to download.
var jsPsych = initJsPsych({
timeline: timeline,
on_finish: function() {
jsPsych.data.get().localSave('csv', subject_id + '_' + session_date +'.csv');
}
});
// Capture today's date
var session_date = new Date().toDateString();
// Assigning screen dimensions
const width = 1250;
const height = 700;
// Preloading stimuli and functions
var preload = {
type: jsPsychPreload,
auto_preload: true,
data: {task: 'Preload'},
};
// Making the browser fullscreen to limit distractions
var enter_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: true,
data: {task: 'Fullscreen'},
on_finish: function(data) {
// Getting current time
var today = new Date();
var curr_time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
data.time = curr_time
}
};
// Checking whether the browser they are accessing this with is chrome and not a mobile device and meets our minimum dimension criteria
var browser_check = {
type: jsPsychBrowserCheck,
minimum_width: width,
minimum_height: height,
inclusion_function: (data) => {
return ((data.browser == 'chrome' || data.browser == 'firefox' || data.browser == 'safari' || data.browser == 'edge') && data.mobile === false)
},
exclusion_message: (data) => {
if (data.mobile){
return error_Laptop;
} else if (data.browser !== 'chrome' && data.browser !== 'firefox' && data.browser !== 'safari' && data.browser !== 'edge'){
return error_Browser;
}
},
data: {task: 'Browser_Check'},
};
// Asking for a subject ID
var PID = {
type: jsPsychSurveyHtmlForm,
preamble: 'Subject ID:',
html: '<p><input type="text" id="test-resp-box" name="PID" size="24" /></p>',
autofocus: 'test-resp-box',
data: {task: 'PID Entry'},
on_finish: function(data) {
// Attempt to parse the responses from the correct key
var responses = data.response;
subject_id = responses.PID;
}
};
// Asking people whether they consent to study participation
var consent = {
type: jsPsychImageButtonResponseModified,
stimulus: 'components/consent/consent.png',
upper_prompt: instr_Consent,
choices: labels_Consent,
render_on_canvas:false,
data: {task: 'Consent'},
on_finish: function (data) {
// Check the participant's response
if (data.response == 1) {
jsPsych.abortExperiment(instr_NoConsent);
}
}
};
// Run the continuous rating task
var continuous_rating = {
type: jsPsychVideoRatingContinuous,
stimulus: ['jspsych_v8.0.1/examples/video/sample_video.mp4'],
prompt: ['Press "1" to move left.<br>Press "2" to move right.'],
width: width,
height: height,
use_universal_time: true,
step: 2,
min: -100,
max: 100,
left_key: '1',
right_key: '2',
labels: ['100% A Rabbit', '100% Not A Rabbit'],
value_suffix: "% Certain",
data: {task: 'Rating'},
on_start: function(data) {
// Getting current time
var today = new Date();
curr_time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
},
on_finish: function(data) {
data.time = curr_time
}
};
// Closing the experiment
var trial_after_fullscreen = {
type: jsPsychHtmlKeyboardResponse,
stimulus: instr_ExpEnd,
choices: [' '],
data: {task: 'Instr_Closure'},
}
// Exiting Full Screen
var exit_fullscreen = {
type: jsPsychFullscreen,
fullscreen_mode: false,
delay_after: 0,
data: {task: 'Fullscreen'},
on_finish: function(data) {
// Getting current time
var today = new Date();
var curr_time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
data.time = curr_time
}
}
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
// | - - - - - - - - EXPERIMENT TIMELINE - - - - - - - - |
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
// Preloading our video stimuli
timeline.push(preload);
// | - - - - - Quality Assurance Measures - - - - - -|
// Making the browser fullscreen to limit distractions
timeline.push(enter_fullscreen);
// Checking whether the browser they are accessing this with is chrome and not a mobile device and meets our minimum dimension criteria
timeline.push(browser_check);
// | - - - - - Consent - - - - - -|
// Entering a subject ID
timeline.push(PID);
// Asking people whether they consent to study participation
timeline.push(consent);
// | - - - - - Instructions - - - - - -|
// Iterating through our sequentially-ordered array of initial instructions
for (var i = 0; i < instr_Intro.length; i++) {
var instr_IntroDisplay = {
type: jsPsychHtmlKeyboardResponse,
stimulus: instr_Intro[i],
choices: [' '],
data: {task: 'Instr_Task'},
};
timeline.push(instr_IntroDisplay);
}
// | - - - - - Tasks - - - - - - |
timeline.push(continuous_rating);
// | - - - - - Exiting - - - - - -|
// Closing the experiment
timeline.push(trial_after_fullscreen);
// Exiting Full Screen
timeline.push(exit_fullscreen);
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
// | - - - - - - - - RUNNING EXPERIMENT - - - - - - - - |
// | - - - - - - - - - - - - - - - - - - - - - - - - - - |
jsPsych.run(timeline);
</script>
</body>
</html>