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

The top level object is jsPsych, and plugins are defined as jsPsych.PLUGIN. The library also loads everything dynamically now, so the user only needs to load the main jsPsych script (and specify the src for any plugins). This also changes how the library is loaded initially, since it is not based on the jQuery method anymore. See wiki.
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
// jsPsych plugin for showing animations
|
|
// Josh de Leeuw
|
|
|
|
(function( $ ) {
|
|
jsPsych.animation = (function(){
|
|
|
|
var plugin = {};
|
|
|
|
plugin.create = function(params) {
|
|
stims = params["stimuli"];
|
|
trials = new Array(stims.length);
|
|
for(var i = 0; i < trials.length; i++)
|
|
{
|
|
trials[i] = {};
|
|
trials[i]["type"] = "animation";
|
|
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;
|
|
}
|
|
|
|
plugin.trial = function($this, block, trial, part)
|
|
{
|
|
var animate_frame = -1;
|
|
var reps = 0;
|
|
switch(part)
|
|
{
|
|
case 1:
|
|
animate_interval = setInterval(function(){
|
|
showImage = true;
|
|
$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){
|
|
$this.append($('<img>', {
|
|
"src": trial.stims[animate_frame],
|
|
"class": 'animate'
|
|
}));
|
|
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
|
}
|
|
}, trial.frame_time);
|
|
break;
|
|
case 2:
|
|
setTimeout(function(){ block.next(); }, trial.timing[0]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return plugin;
|
|
})();
|
|
})(jQuery); |