missed the animation and touch plugins in previous changes.

similarity had a bug in the naming of the plugin.
This commit is contained in:
Josh de Leeuw 2012-05-15 16:10:10 -04:00
parent 9c94b4d0b6
commit a056b6e69c
3 changed files with 157 additions and 138 deletions

View File

@ -1,8 +1,12 @@
// 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(){
var plugin = {};
plugin.create = function(params) {
stims = params["stimuli"]; stims = params["stimuli"];
trials = new Array(stims.length); trials = new Array(stims.length);
for(var i = 0; i < trials.length; i++) for(var i = 0; i < trials.length; i++)
@ -18,10 +22,10 @@ function animation_create(params)
} }
} }
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)
@ -55,4 +59,8 @@ function animation_trial($this, block, trial, part)
setTimeout(function(){ block.next(); }, trial.timing[0]); setTimeout(function(){ block.next(); }, trial.timing[0]);
break; break;
} }
} }
return plugin;
})();
})(jQuery);

View File

@ -1,5 +1,5 @@
(function( $ ) { (function( $ ) {
$.fn.jsPsych.text = (function(){ $.fn.jsPsych.similarity = (function(){
var plugin = {}; var plugin = {};

View File

@ -1,5 +1,9 @@
function xab_touch_create(params) (function( $ ) {
{ $.fn.jsPsych.xab-touch = (function(){
var plugin = {};
plugin.create = function(params) {
//xab_stims = shuffle(xab_stims); //xab_stims = shuffle(xab_stims);
xab_stims = params["stimuli"]; xab_stims = params["stimuli"];
trials = new Array(xab_stims.length); trials = new Array(xab_stims.length);
@ -15,20 +19,23 @@ function xab_touch_create(params)
} }
} }
return trials; return trials;
} }
function xab_touch_trial($this, block, trial, part) plugin.trial = function($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_touch'); $this.append($('<img>', {
setTimeout(xab_touch_trial, trial.timing[0], $this, block, trial, part + 1); "src": trial.a_path,
"class": 'xab_touch'
}));
setTimeout(function(){xab_touch_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();
$('.xab_touch').remove(); $('.xab_touch').remove();
setTimeout(xab_touch_trial, trial.timing[1], $this, block, trial, part + 1); setTimeout(function(){xab_touch_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();
@ -42,11 +49,11 @@ function xab_touch_trial($this, block, trial, part)
var correct=false; var correct=false;
var left_img = document.createElement('img'); $this.append($('<img>', {
left_img.setAttribute('src', images[0]); "src": images[0],
left_img.setAttribute('class', 'xab_touch'); "class": 'xab_touch',
left_img.setAttribute('id','left_img'); "id": "left_img"
$this.append(left_img); }));
$("#left_img").click(function() { $("#left_img").click(function() {
if(target_left) { correct = true; } if(target_left) { correct = true; }
@ -57,14 +64,14 @@ function xab_touch_trial($this, block, trial, part)
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} 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_touch').remove(); $('.xab_touch').remove();
setTimeout(function(b){b.next();}, trial.timing[2], block); setTimeout(function(){block.next();}, trial.timing[2]);
}); });
var right_img = document.createElement('img'); $this.append($('<img>', {
right_img.setAttribute('src', images[1]); "src": images[1],
right_img.setAttribute('class', 'xab_touch'); "class": 'xab_touch',
right_img.setAttribute('id','right_img'); "id": "right_img"
$this.append(right_img); }));
$("#right_img").click(function() { $("#right_img").click(function() {
if(!target_left) { correct = true; } if(!target_left) { correct = true; }
@ -75,11 +82,15 @@ function xab_touch_trial($this, block, trial, part)
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} 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_touch').remove(); $('.xab_touch').remove();
setTimeout(function(b){b.next();}, trial.timing[2], block); setTimeout(function(){block.next();}, trial.timing[2]);
}); });
//TODO: CHECK IF IMAGE SHOULD DISAPPEAR //TODO: CHECK IF IMAGE SHOULD DISAPPEAR
//based on timings //based on timings
break; break;
} }
} }
return plugin;
})();
})(jQuery);