mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00

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.
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
// jsPsych plugin for showing animations
|
|
// Josh de Leeuw
|
|
|
|
function animation_create(params)
|
|
{
|
|
stims = params["stimuli"];
|
|
trials = new Array(stims.length);
|
|
for(var i = 0; i < trials.length; i++)
|
|
{
|
|
trials[i] = {};
|
|
trials[i]["type"] = "animate";
|
|
trials[i]["stims"] = stims[i];
|
|
trials[i]["frame_time"] = params["frame_time"];
|
|
trials[i]["repetitions"] = params["repetitions"];
|
|
trials[i]["timing"] = params["timing"];
|
|
if(params["prompt"] != undefined){
|
|
trials[i]["prompt"] = params["prompt"][i];
|
|
}
|
|
}
|
|
return trials;
|
|
}
|
|
|
|
function animation_trial($this, block, trial, part)
|
|
{
|
|
animate_frame = -1;
|
|
reps = 0;
|
|
switch(part)
|
|
{
|
|
case 1:
|
|
animate_interval = setInterval(function(){
|
|
showImage = true;
|
|
$('.animate').remove();
|
|
$this.html(""); // clear everything
|
|
animate_frame++;
|
|
if(animate_frame == trial.stims.length)
|
|
{
|
|
animate_frame = 0;
|
|
reps++;
|
|
if(reps >= trial.repetitions)
|
|
{
|
|
animation_trial($this, block, trial, part + 1);
|
|
clearInterval(animate_interval);
|
|
showImage = false;
|
|
}
|
|
}
|
|
if(showImage){
|
|
$.fn.jsPsych.showImage($this, trial.stims[animate_frame], 'animate');
|
|
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
|
}
|
|
}, trial.frame_time);
|
|
break;
|
|
case 2:
|
|
setTimeout(function(b){ b.next(); }, trial.timing[0], block);
|
|
break;
|
|
}
|
|
} |