This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjspsych-word-referent.js
194 lines (168 loc) · 6.32 KB
/
jspsych-word-referent.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
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
/**
* jspsych-word-referent
* a jspsych plugin for word-referent pair trails.
*
* Jordan Gunn
*
* partial documentation: docs.jspsych.org
*
*/
jsPsych.plugins['word-referent'] = (function(){
var plugin = {};
plugin.trial = function(display_element, trial){
// allow variables as functions
trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
// set default values for the parameters; no default value for images
trial.word = trial.word || "";
var timing_response = 100;
trial.is_test = trial.is_test || false;
trial.response_ends_trial = (typeof trial.response_ends_trial == 'undefined') ? true : trial.response_ends_trial;
// default data
var trialdata = {
choice: '0',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
// display prompt and word if there is one
if (trial.word !== "") {
display_element.append('<b><p style="text-align:center;">Oh look! A ' + trial.word + "!</p></b>");
}
// now two rows of three images
if (trial.is_test) {
display_element.append('<p style="text-align: center"><img border="5" id="1" src="' + trial.stimuli[0] + '" style="width: 130; margin-right: 1%; height: 130;"><img border="5" id="2" src="' + trial.stimuli[1] + '" style="width: 130; margin-right: 1%; height: 130;"></p>'); // <img border="5" id="3" src="' + trial.stimuli[2] + '" style="width: 130; margin-right: 1%; height: 130;">
display_element.append('<p style="text-align: center"><img border="5" id="3" src="' + trial.stimuli[2] + '" style="width: 130; margin-right: 1%; height: 130;"><img border="5" id="4" src="' + trial.stimuli[3] + '" style="width: 130; margin-right: 1%; height: 130;"></p>'); // <img border="5" id="6" src="' + trial.stimuli[5] + '" style="width: 130; margin-right: 1%; height: 130;">
} else {
display_element.append('<p style="text-align: center"><img border="5" src="' + trial.stimuli[0] + '" style="width: 130; margin-right: 1%; height: 130;"><img border="5" src="' + trial.stimuli[1] + '" style="width: 130; margin-right: 1%; height: 130;"></p>'); // <img border="5" src="' + trial.stimuli[2] + '" style="width: 130; margin-right: 1%; height: 130;">
display_element.append('<p style="text-align: center"><img border="5" src="' + trial.stimuli[2] + '" style="width: 130; margin-right: 1%; height: 130;"><img border="5" src="' + trial.stimuli[3] + '" style="width: 130; margin-right: 1%; height: 130;"></p>'); // <img border="5" src="' + trial.stimuli[5] + '" style="width: 130; margin-right: 1%; height: 130;">
}
// end trial at time limit if one is set
if (!trial.is_test) {
var t1 = setTimeout(function() {
display_element.html(''); // clear the display
// end
jsPsych.finishTrial(trialdata);
}, timing_response);
}
// image hover
$("#1").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
$("#2").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
$("#3").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
$("#4").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
$("#5").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
$("#6").hover(function(){
$(this).css("borderColor", "yellow");
}, function(){
$(this).css("borderColor", "black");
});
// response storage
$("#1").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '1',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
$("#2").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '2',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
$("#3").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '3',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
$("#4").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '4',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
$("#5").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '5',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
$("#6").click(function() {
display_element.html(''); // clear the display
// data saving
var trialdata = {
choice: '6',
condition: trial.condition,
block: trial.block,
options: trial.stimuli,
primary: trial.primary,
secondary: trial.secondary,
word: trial.word
};
jsPsych.finishTrial(trialdata);
});
};
return plugin;
})();