Lots of changes:

1 - Modified animation library to allow for prompt to be displayed while animation is displayed. Prompt is optional.
2 - Added two categorization plugins, one for training and one for testing.
3 - Started fixing IE issues. Two major problems have been identified and started to be corrected.
	First: setTimeout() behaves differently in IE; optional parameters mean different things. Starting to rewrite all setTimeout calls so they work cross-browser.
	Second: Some of the plugins were using .setAttribute to give a class to an image, so that it could later be removed. IE and others have different methods to do this. Fix is to use jQuery for all of this, which has cross-browser methods.
4 - As a result of 3B, I'm going to deprecate the jsPsych.showImage and jsPsych.showImages functions. They seemed out of place anyways.
This commit is contained in:
Josh de Leeuw 2012-05-14 15:11:48 -04:00
parent 5ffc885139
commit c3a42dc358
6 changed files with 218 additions and 17 deletions

View File

@ -13,6 +13,9 @@ function animation_create(params)
trials[i]["frame_time"] = params["frame_time"]; trials[i]["frame_time"] = params["frame_time"];
trials[i]["repetitions"] = params["repetitions"]; trials[i]["repetitions"] = params["repetitions"];
trials[i]["timing"] = params["timing"]; trials[i]["timing"] = params["timing"];
if(params["prompt"] != undefined){
trials[i]["prompt"] = params["prompt"][i];
}
} }
return trials; return trials;
} }
@ -27,6 +30,7 @@ function animation_trial($this, block, trial, part)
animate_interval = setInterval(function(){ animate_interval = setInterval(function(){
showImage = true; showImage = true;
$('.animate').remove(); $('.animate').remove();
$this.html(""); // clear everything
animate_frame++; animate_frame++;
if(animate_frame == trial.stims.length) if(animate_frame == trial.stims.length)
{ {
@ -41,6 +45,7 @@ function animation_trial($this, block, trial, part)
} }
if(showImage){ if(showImage){
$.fn.jsPsych.showImage($this, trial.stims[animate_frame], 'animate'); $.fn.jsPsych.showImage($this, trial.stims[animate_frame], 'animate');
if(trial.prompt != undefined) { $this.append(trial.prompt); }
} }
}, trial.frame_time); }, trial.frame_time);
break; break;

View File

@ -0,0 +1,113 @@
// timing parameters: [length to show feedback, intertrial gap, optional length to display target]
// if optional length to display target is missing, then target is displayed until subject responds.
//TODO
// option to keep stim on screen during feedback
// way to provide corrective feedback
function cf_create(params)
{
cf_stims = params["stimuli"];
trials = new Array(cf_stims.length);
for(var i = 0; i < trials.length; i++)
{
trials[i] = {};
trials[i]["type"] = "cf";
trials[i]["a_path"] = cf_stims[i];
trials[i]["timing"] = params["timing"];
trials[i]["key_answer"] = params["key_answer"][i];
trials[i]["text_answer"] = params["text_answer"][i];
trials[i]["choices"] = params["choices"];
trials[i]["correct_text"] = params["correct_text"];
trials[i]["incorrect_text"] = params["incorrect_text"];
trials[i]["show_stim_feedback"] = params["show_stim_feedback"];
if(params["prompt"] != undefined){
trials[i]["prompt"] = params["prompt"];
}
if(params["data"]!=undefined){
trials[i]["data"] = params["data"][i];
}
}
return trials;
}
function cf_trial($this, block, trial, part)
{
//console.log(block.trial_idx);
switch(part){
case 1:
p1_time = (new Date()).getTime();
$.fn.jsPsych.showImage($this, trial.a_path, 'cf');
if(trial.timing[2]!=undefined){
setTimeout(cf_trial, trial.timing[2], $this, block, trial, part + 1);
} else {
//show prompt here
$this.append(trial.prompt);
cf_trial($this, block, trial, part + 1);
}
break;
case 2:
p2_time = (new Date()).getTime();
if(trial.timing[2]!=undefined){
$('.cf').remove();
$this.html(trial.prompt);
}
startTime = (new Date()).getTime();
var resp_func = function(e) {
var flag = false;
var correct = false;
if(e.which==trial.key_answer) // correct category
{
flag = true;
correct = true;
}
else
{
// check if the key is any of the options, or if it is an accidental keystroke
for(var i=0;i<trial.choices.length;i++)
{
if(e.which==trial.choices[i])
{
flag = true;
correct = false;
}
}
}
if(flag)
{
endTime = (new Date()).getTime();
rt = (endTime-startTime);
stim1_time = (p2_time-p1_time);
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "key_press": e.which, "stim1_time": stim1_time}
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
$(document).unbind('keyup',resp_func);
$('.cf').remove();
$this.html('');
cf_trial($this, block, trial, part + 1);
}
}
$(document).keyup(resp_func);
break;
case 3:
if(trial.show_stim_feedback)
{
$.fn.jsPsych.showImage($this, trial.a_path, 'cf');
}
// give feedback
var atext = "";
if(block.data[block.trial_idx]["correct"])
{
atext = trial.correct_text.replace("&ANS&", trial.text_answer);
} else {
atext = trial.incorrect_text.replace("&ANS&", trial.text_answer);
}
$this.append(atext);
setTimeout(cf_trial, trial.timing[0], $this, block, trial, part + 1);
break;
case 4:
$this.html("");
setTimeout(function(b){b.next();}, trial.timing[1], block);
break;
}
}

View File

@ -0,0 +1,73 @@
// timing parameters: [intertrial gap, optional length to display target]
// if optional length to display target is missing, then target is displayed until subject responds.
function cu_create(params)
{
cu_stims = params["stimuli"];
trials = new Array(cu_stims.length);
for(var i = 0; i < trials.length; i++)
{
trials[i] = {};
trials[i]["type"] = "cu";
trials[i]["a_path"] = cu_stims[i];
trials[i]["timing"] = params["timing"];
trials[i]["choices"] = params["choices"];
if(params["prompt"] != undefined){
trials[i]["prompt"] = params["prompt"];
}
if(params["data"]!=undefined){
trials[i]["data"] = params["data"][i];
}
}
return trials;
}
function cu_trial($this, block, trial, part)
{
switch(part){
case 1:
p1_time = (new Date()).getTime();
$.fn.jsPsych.showImage($this, trial.a_path, 'cu');
if(trial.timing[1]!=undefined){
setTimeout(cu_trial, trial.timing[1], $this, block, trial, part + 1);
} else {
//show prompt here
$this.append(trial.prompt);
cu_trial($this, block, trial, part + 1);
}
break;
case 2:
p2_time = (new Date()).getTime();
if(trial.timing[1]!=undefined){
$('.cu').remove();
$this.html(trial.prompt);
}
startTime = (new Date()).getTime();
var resp_func = function(e) {
var flag = false;
// check if the key is any of the options, or if it is an accidental keystroke
for(var i=0;i<trial.choices.length;i++)
{
if(e.which==trial.choices[i])
{
flag = true;
}
}
if(flag)
{
endTime = (new Date()).getTime();
rt = (endTime-startTime);
stim1_time = (p2_time-p1_time);
var trial_data = {"rt": rt, "a_path": trial.a_path, "key_press": e.which, "stim1_time": stim1_time}
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
$(document).unbind('keyup',resp_func);
$('.cu').remove();
$this.html('');
setTimeout(function(b){b.next();}, trial.timing[0], block);
}
}
$(document).keyup(resp_func);
break;
}
}

View File

@ -25,19 +25,25 @@ function sd_trial($this, block, trial, part)
switch(part){ switch(part){
case 1: case 1:
p1_time = (new Date()).getTime(); p1_time = (new Date()).getTime();
$.fn.jsPsych.showImage($this, trial.a_path, 'sd'); $this.append($('<img>', {
setTimeout(sd_trial, trial.timing[0], $this, block, trial, part + 1); "src": trial.a_path,
"class": 'sd'
}));
setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[0]);
break; break;
case 2: case 2:
p2_time = (new Date()).getTime(); p2_time = (new Date()).getTime();
$('.sd').remove(); $('.sd').remove();
setTimeout(sd_trial, trial.timing[1], $this, block, trial, part + 1); setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[1]);
break; break;
case 3: case 3:
p3_time = (new Date()).getTime(); p3_time = (new Date()).getTime();
$.fn.jsPsych.showImage($this, trial.b_path, 'sd'); $this.append($('<img>', {
"src": trial.b_path,
"class": 'sd'
}));
if(trial.timing[3]!=undefined){ if(trial.timing[3]!=undefined){
setTimeout(sd_trial, trial.timing[3], $this, block, trial, part + 1); setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[3]);
} else { } else {
sd_trial($this, block, trial, part + 1); sd_trial($this, block, trial, part + 1);
} }
@ -73,7 +79,7 @@ function sd_trial($this, block, trial, part)
$(document).unbind('keyup',resp_func); $(document).unbind('keyup',resp_func);
$('.sd').remove(); $('.sd').remove();
$this.html(''); $this.html('');
setTimeout(function(b){b.next();}, trial.timing[2], block); setTimeout(function(){block.next();}, trial.timing[2]);
} }
} }
$(document).keyup(resp_func); $(document).keyup(resp_func);

View File

@ -21,7 +21,7 @@ function text_trial($this, block, trial, part)
flag = true; flag = true;
$(document).unbind('keyup',key_listener); $(document).unbind('keyup',key_listener);
$this.html(''); $this.html('');
setTimeout(function(b){b.next();}, trial.timing[0], block); setTimeout(function(){block.next();}, trial.timing[0]);
} }
} }
$(document).keyup(key_listener); $(document).keyup(key_listener);

View File

@ -22,13 +22,13 @@ function xab_touch_trial($this, block, trial, part)
switch(part){ switch(part){
case 1: case 1:
p1_time = (new Date()).getTime(); p1_time = (new Date()).getTime();
$.fn.jsPsych.showImage($this, trial.a_path, 'xab'); $.fn.jsPsych.showImage($this, trial.a_path, 'xab_touch');
setTimeout(xab_trial, trial.timing[0], $this, block, trial, part + 1); setTimeout(xab_touch_trial, trial.timing[0], $this, block, trial, part + 1);
break; break;
case 2: case 2:
p2_time = (new Date()).getTime(); p2_time = (new Date()).getTime();
$('.xab').remove(); $('.xab_touch').remove();
setTimeout(xab_trial, trial.timing[1], $this, block, trial, part + 1); setTimeout(xab_touch_trial, trial.timing[1], $this, block, trial, part + 1);
break; break;
case 3: case 3:
p3_time = (new Date()).getTime(); p3_time = (new Date()).getTime();
@ -40,37 +40,41 @@ function xab_touch_trial($this, block, trial, part)
} }
//$.fn.jsPsych.showImages($this, images, 'xab'); //$.fn.jsPsych.showImages($this, images, 'xab');
var correct=false;
var left_img = document.createElement('img'); var left_img = document.createElement('img');
left_img.setAttribute('src', images[0]); left_img.setAttribute('src', images[0]);
left_img.setAttribute('class', 'xab_touch'); left_img.setAttribute('class', 'xab_touch');
left_img.setAttribute('id','left_img');
$this.append(left_img); $this.append(left_img);
left_img.click(function() { $("#left_img").click(function() {
if(target_left) { correct = true; } if(target_left) { correct = true; }
endTime = (new Date()).getTime(); endTime = (new Date()).getTime();
rt = (endTime-startTime); rt = (endTime-startTime);
stim1_time = (p2_time-p1_time); stim1_time = (p2_time-p1_time);
isi_time = (p3_time-p2_time); isi_time = (p3_time-p2_time);
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time} var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "stim1_time": stim1_time, "isi_time":isi_time}
block.data[block.trial_idx] = $.extend({},trial_data,trial.data); block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
$('.xab').remove(); $('.xab_touch').remove();
setTimeout(function(b){b.next();}, trial.timing[2], block); setTimeout(function(b){b.next();}, trial.timing[2], block);
}); });
var right_img = document.createElement('img'); var right_img = document.createElement('img');
right_img.setAttribute('src', images[1]); right_img.setAttribute('src', images[1]);
right_img.setAttribute('class', 'xab_touch'); right_img.setAttribute('class', 'xab_touch');
right_img.setAttribute('id','right_img');
$this.append(right_img); $this.append(right_img);
right_img.click(function() { $("#right_img").click(function() {
if(!target_left) { correct = true; } if(!target_left) { correct = true; }
endTime = (new Date()).getTime(); endTime = (new Date()).getTime();
rt = (endTime-startTime); rt = (endTime-startTime);
stim1_time = (p2_time-p1_time); stim1_time = (p2_time-p1_time);
isi_time = (p3_time-p2_time); isi_time = (p3_time-p2_time);
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time} var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "stim1_time": stim1_time, "isi_time":isi_time}
block.data[block.trial_idx] = $.extend({},trial_data,trial.data); block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
$('.xab').remove(); $('.xab_touch').remove();
setTimeout(function(b){b.next();}, trial.timing[2], block); setTimeout(function(b){b.next();}, trial.timing[2], block);
}); });