mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
missed the animation and touch plugins in previous changes.
similarity had a bug in the naming of the plugin.
This commit is contained in:
parent
9c94b4d0b6
commit
a056b6e69c
@ -1,58 +1,66 @@
|
|||||||
// jsPsych plugin for showing animations
|
// jsPsych plugin for showing animations
|
||||||
// Josh de Leeuw
|
// Josh de Leeuw
|
||||||
|
|
||||||
function animation_create(params)
|
(function( $ ) {
|
||||||
{
|
$.fn.jsPsych.animation = (function(){
|
||||||
stims = params["stimuli"];
|
|
||||||
trials = new Array(stims.length);
|
var plugin = {};
|
||||||
for(var i = 0; i < trials.length; i++)
|
|
||||||
{
|
plugin.create = function(params) {
|
||||||
trials[i] = {};
|
stims = params["stimuli"];
|
||||||
trials[i]["type"] = "animate";
|
trials = new Array(stims.length);
|
||||||
trials[i]["stims"] = stims[i];
|
for(var i = 0; i < trials.length; i++)
|
||||||
trials[i]["frame_time"] = params["frame_time"];
|
{
|
||||||
trials[i]["repetitions"] = params["repetitions"];
|
trials[i] = {};
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["type"] = "animate";
|
||||||
if(params["prompt"] != undefined){
|
trials[i]["stims"] = stims[i];
|
||||||
trials[i]["prompt"] = params["prompt"][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;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return trials;
|
|
||||||
}
|
|
||||||
|
|
||||||
function animation_trial($this, block, trial, part)
|
plugin.trial = function($this, block, trial, part)
|
||||||
{
|
{
|
||||||
var animate_frame = -1;
|
var animate_frame = -1;
|
||||||
var reps = 0;
|
var reps = 0;
|
||||||
switch(part)
|
switch(part)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
animate_interval = setInterval(function(){
|
animate_interval = setInterval(function(){
|
||||||
showImage = true;
|
showImage = true;
|
||||||
$this.html(""); // clear everything
|
$this.html(""); // clear everything
|
||||||
animate_frame++;
|
animate_frame++;
|
||||||
if(animate_frame == trial.stims.length)
|
if(animate_frame == trial.stims.length)
|
||||||
{
|
{
|
||||||
animate_frame = 0;
|
animate_frame = 0;
|
||||||
reps++;
|
reps++;
|
||||||
if(reps >= trial.repetitions)
|
if(reps >= trial.repetitions)
|
||||||
{
|
{
|
||||||
animation_trial($this, block, trial, part + 1);
|
animation_trial($this, block, trial, part + 1);
|
||||||
clearInterval(animate_interval);
|
clearInterval(animate_interval);
|
||||||
showImage = false;
|
showImage = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(showImage){
|
if(showImage){
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": trial.stims[animate_frame],
|
"src": trial.stims[animate_frame],
|
||||||
"class": 'animate'
|
"class": 'animate'
|
||||||
}));
|
}));
|
||||||
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
||||||
}
|
}
|
||||||
}, trial.frame_time);
|
}, trial.frame_time);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
setTimeout(function(){ block.next(); }, trial.timing[0]);
|
setTimeout(function(){ block.next(); }, trial.timing[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
})();
|
||||||
|
})(jQuery);
|
@ -1,5 +1,5 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
$.fn.jsPsych.text = (function(){
|
$.fn.jsPsych.similarity = (function(){
|
||||||
|
|
||||||
var plugin = {};
|
var plugin = {};
|
||||||
|
|
||||||
|
@ -1,85 +1,96 @@
|
|||||||
function xab_touch_create(params)
|
(function( $ ) {
|
||||||
{
|
$.fn.jsPsych.xab-touch = (function(){
|
||||||
//xab_stims = shuffle(xab_stims);
|
|
||||||
xab_stims = params["stimuli"];
|
var plugin = {};
|
||||||
trials = new Array(xab_stims.length);
|
|
||||||
for(var i = 0; i < trials.length; i++)
|
plugin.create = function(params) {
|
||||||
{
|
//xab_stims = shuffle(xab_stims);
|
||||||
trials[i] = {};
|
xab_stims = params["stimuli"];
|
||||||
trials[i]["type"] = "xab_touch";
|
trials = new Array(xab_stims.length);
|
||||||
trials[i]["a_path"] = xab_stims[i][0];
|
for(var i = 0; i < trials.length; i++)
|
||||||
trials[i]["b_path"] = xab_stims[i][1];
|
{
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i] = {};
|
||||||
if(params["data"]!=undefined){
|
trials[i]["type"] = "xab_touch";
|
||||||
trials[i]["data"] = params["data"][i];
|
trials[i]["a_path"] = xab_stims[i][0];
|
||||||
}
|
trials[i]["b_path"] = xab_stims[i][1];
|
||||||
}
|
trials[i]["timing"] = params["timing"];
|
||||||
return trials;
|
if(params["data"]!=undefined){
|
||||||
}
|
trials[i]["data"] = params["data"][i];
|
||||||
|
}
|
||||||
function xab_touch_trial($this, block, trial, part)
|
|
||||||
{
|
|
||||||
switch(part){
|
|
||||||
case 1:
|
|
||||||
p1_time = (new Date()).getTime();
|
|
||||||
$.fn.jsPsych.showImage($this, trial.a_path, 'xab_touch');
|
|
||||||
setTimeout(xab_touch_trial, trial.timing[0], $this, block, trial, part + 1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
p2_time = (new Date()).getTime();
|
|
||||||
$('.xab_touch').remove();
|
|
||||||
setTimeout(xab_touch_trial, trial.timing[1], $this, block, trial, part + 1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
p3_time = (new Date()).getTime();
|
|
||||||
startTime = (new Date()).getTime();
|
|
||||||
var images = [trial.a_path, trial.b_path];
|
|
||||||
var target_left = (Math.floor(Math.random()*2)==0); // binary true/false choice
|
|
||||||
if(!target_left){
|
|
||||||
images = [trial.b_path, trial.a_path];
|
|
||||||
}
|
}
|
||||||
//$.fn.jsPsych.showImages($this, images, 'xab');
|
return trials;
|
||||||
|
}
|
||||||
var correct=false;
|
|
||||||
|
plugin.trial = function($this, block, trial, part)
|
||||||
var left_img = document.createElement('img');
|
{
|
||||||
left_img.setAttribute('src', images[0]);
|
switch(part){
|
||||||
left_img.setAttribute('class', 'xab_touch');
|
case 1:
|
||||||
left_img.setAttribute('id','left_img');
|
p1_time = (new Date()).getTime();
|
||||||
$this.append(left_img);
|
$this.append($('<img>', {
|
||||||
$("#left_img").click(function() {
|
"src": trial.a_path,
|
||||||
if(target_left) { correct = true; }
|
"class": 'xab_touch'
|
||||||
|
}));
|
||||||
endTime = (new Date()).getTime();
|
setTimeout(function(){xab_touch_trial($this, block, trial, part + 1);}, trial.timing[0]);
|
||||||
rt = (endTime-startTime);
|
break;
|
||||||
stim1_time = (p2_time-p1_time);
|
case 2:
|
||||||
isi_time = (p3_time-p2_time);
|
p2_time = (new Date()).getTime();
|
||||||
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}
|
$('.xab_touch').remove();
|
||||||
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
|
setTimeout(function(){xab_touch_trial($this, block, trial, part + 1);}, trial.timing[1]);
|
||||||
$('.xab_touch').remove();
|
break;
|
||||||
setTimeout(function(b){b.next();}, trial.timing[2], block);
|
case 3:
|
||||||
});
|
p3_time = (new Date()).getTime();
|
||||||
|
startTime = (new Date()).getTime();
|
||||||
var right_img = document.createElement('img');
|
var images = [trial.a_path, trial.b_path];
|
||||||
right_img.setAttribute('src', images[1]);
|
var target_left = (Math.floor(Math.random()*2)==0); // binary true/false choice
|
||||||
right_img.setAttribute('class', 'xab_touch');
|
if(!target_left){
|
||||||
right_img.setAttribute('id','right_img');
|
images = [trial.b_path, trial.a_path];
|
||||||
$this.append(right_img);
|
}
|
||||||
$("#right_img").click(function() {
|
//$.fn.jsPsych.showImages($this, images, 'xab');
|
||||||
if(!target_left) { correct = true; }
|
|
||||||
|
var correct=false;
|
||||||
endTime = (new Date()).getTime();
|
|
||||||
rt = (endTime-startTime);
|
$this.append($('<img>', {
|
||||||
stim1_time = (p2_time-p1_time);
|
"src": images[0],
|
||||||
isi_time = (p3_time-p2_time);
|
"class": 'xab_touch',
|
||||||
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}
|
"id": "left_img"
|
||||||
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
|
}));
|
||||||
$('.xab_touch').remove();
|
$("#left_img").click(function() {
|
||||||
setTimeout(function(b){b.next();}, trial.timing[2], block);
|
if(target_left) { correct = true; }
|
||||||
});
|
|
||||||
|
endTime = (new Date()).getTime();
|
||||||
//TODO: CHECK IF IMAGE SHOULD DISAPPEAR
|
rt = (endTime-startTime);
|
||||||
//based on timings
|
stim1_time = (p2_time-p1_time);
|
||||||
break;
|
isi_time = (p3_time-p2_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);
|
||||||
|
$('.xab_touch').remove();
|
||||||
|
setTimeout(function(){block.next();}, trial.timing[2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this.append($('<img>', {
|
||||||
|
"src": images[1],
|
||||||
|
"class": 'xab_touch',
|
||||||
|
"id": "right_img"
|
||||||
|
}));
|
||||||
|
$("#right_img").click(function() {
|
||||||
|
if(!target_left) { correct = true; }
|
||||||
|
|
||||||
|
endTime = (new Date()).getTime();
|
||||||
|
rt = (endTime-startTime);
|
||||||
|
stim1_time = (p2_time-p1_time);
|
||||||
|
isi_time = (p3_time-p2_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);
|
||||||
|
$('.xab_touch').remove();
|
||||||
|
setTimeout(function(){block.next();}, trial.timing[2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO: CHECK IF IMAGE SHOULD DISAPPEAR
|
||||||
|
//based on timings
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
})();
|
||||||
|
})(jQuery);
|
Loading…
Reference in New Issue
Block a user