mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Minor bug corrections
This commit is contained in:
parent
8bd466c18f
commit
ed5034bbd0
@ -41,7 +41,7 @@
|
|||||||
reps++;
|
reps++;
|
||||||
if(reps >= trial.repetitions)
|
if(reps >= trial.repetitions)
|
||||||
{
|
{
|
||||||
animation_trial($this, block, trial, part + 1);
|
plugin.trial($this, block, trial, part + 1);
|
||||||
clearInterval(animate_interval);
|
clearInterval(animate_interval);
|
||||||
showImage = false;
|
showImage = false;
|
||||||
}
|
}
|
||||||
|
192
jspsych-samedifferent.js
Executable file → Normal file
192
jspsych-samedifferent.js
Executable file → Normal file
@ -1,97 +1,97 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
jsPsych.samedifferent = (function(){
|
jsPsych.samedifferent = (function(){
|
||||||
|
|
||||||
var plugin = {};
|
var plugin = {};
|
||||||
|
|
||||||
plugin.create = function(params) {
|
plugin.create = function(params) {
|
||||||
sd_stims = params["stimuli"];
|
sd_stims = params["stimuli"];
|
||||||
trials = new Array(sd_stims.length);
|
trials = new Array(sd_stims.length);
|
||||||
for(var i = 0; i < trials.length; i++)
|
for(var i = 0; i < trials.length; i++)
|
||||||
{
|
{
|
||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
trials[i]["type"] = "samedifferent";
|
trials[i]["type"] = "samedifferent";
|
||||||
trials[i]["a_path"] = sd_stims[i][0];
|
trials[i]["a_path"] = sd_stims[i][0];
|
||||||
trials[i]["b_path"] = sd_stims[i][1];
|
trials[i]["b_path"] = sd_stims[i][1];
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["timing"] = params["timing"];
|
||||||
trials[i]["answer"] = params["answer"][i];
|
trials[i]["answer"] = params["answer"][i];
|
||||||
if(params["prompt"] != undefined){
|
if(params["prompt"] != undefined){
|
||||||
trials[i]["prompt"] = params["prompt"];
|
trials[i]["prompt"] = params["prompt"];
|
||||||
}
|
}
|
||||||
if(params["data"]!=undefined){
|
if(params["data"]!=undefined){
|
||||||
trials[i]["data"] = params["data"][i];
|
trials[i]["data"] = params["data"][i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.trial = function($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();
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": trial.a_path,
|
"src": trial.a_path,
|
||||||
"class": 'sd'
|
"class": 'sd'
|
||||||
}));
|
}));
|
||||||
setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[0]);
|
setTimeout(function(){plugin.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(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[1]);
|
setTimeout(function(){plugin.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();
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": trial.b_path,
|
"src": trial.b_path,
|
||||||
"class": 'sd'
|
"class": 'sd'
|
||||||
}));
|
}));
|
||||||
if(trial.timing[3]!=undefined){
|
if(trial.timing[3]!=undefined){
|
||||||
setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[3]);
|
setTimeout(function(){plugin.trial($this, block, trial, part + 1);}, trial.timing[3]);
|
||||||
} else {
|
} else {
|
||||||
sd_trial($this, block, trial, part + 1);
|
plugin.trial($this, block, trial, part + 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
p4_time = (new Date()).getTime();
|
p4_time = (new Date()).getTime();
|
||||||
if(trial.timing[3]!=undefined){
|
if(trial.timing[3]!=undefined){
|
||||||
$('.sd').remove();
|
$('.sd').remove();
|
||||||
$this.html(trial.prompt);
|
$this.html(trial.prompt);
|
||||||
}
|
}
|
||||||
startTime = (new Date()).getTime();
|
startTime = (new Date()).getTime();
|
||||||
var resp_func = function(e) {
|
var resp_func = function(e) {
|
||||||
var flag = false;
|
var flag = false;
|
||||||
var correct = false;
|
var correct = false;
|
||||||
if(e.which=='80') // 'p' key -- same
|
if(e.which=='80') // 'p' key -- same
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
if(trial.answer == "same") { correct = true; }
|
if(trial.answer == "same") { correct = true; }
|
||||||
} else if(e.which=='81') // 'q' key -- different
|
} else if(e.which=='81') // 'q' key -- different
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
if(trial.answer == "different"){ correct = true; }
|
if(trial.answer == "different"){ correct = true; }
|
||||||
}
|
}
|
||||||
if(flag)
|
if(flag)
|
||||||
{
|
{
|
||||||
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);
|
||||||
stim2_time = (p4_time-p3_time);
|
stim2_time = (p4_time-p3_time);
|
||||||
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "stim2_time":stim2_time, "isi_time":isi_time}
|
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "stim2_time":stim2_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);
|
||||||
$(document).unbind('keyup',resp_func);
|
$(document).unbind('keyup',resp_func);
|
||||||
$('.sd').remove();
|
$('.sd').remove();
|
||||||
$this.html('');
|
$this.html('');
|
||||||
setTimeout(function(){block.next();}, trial.timing[2]);
|
setTimeout(function(){block.next();}, trial.timing[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(document).keyup(resp_func);
|
$(document).keyup(resp_func);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
})();
|
})();
|
||||||
}) (jQuery);
|
}) (jQuery);
|
||||||
|
|
134
jspsych-similarity.js
Executable file → Normal file
134
jspsych-similarity.js
Executable file → Normal file
@ -1,68 +1,68 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
jsPsych.similarity = (function(){
|
jsPsych.similarity = (function(){
|
||||||
|
|
||||||
var plugin = {};
|
var plugin = {};
|
||||||
|
|
||||||
plugin.create = function(params) {
|
plugin.create = function(params) {
|
||||||
sim_stims = params["stimuli"];
|
sim_stims = params["stimuli"];
|
||||||
trials = new Array(sim_stims.length);
|
trials = new Array(sim_stims.length);
|
||||||
for(var i = 0; i < trials.length; i++)
|
for(var i = 0; i < trials.length; i++)
|
||||||
{
|
{
|
||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
trials[i]["type"] = "similarity";
|
trials[i]["type"] = "similarity";
|
||||||
trials[i]["a_path"] = sim_stims[i][0];
|
trials[i]["a_path"] = sim_stims[i][0];
|
||||||
trials[i]["b_path"] = sim_stims[i][1];
|
trials[i]["b_path"] = sim_stims[i][1];
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["timing"] = params["timing"];
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.trial = function($this, block, trial, part)
|
plugin.trial = function($this, block, trial, part)
|
||||||
{
|
{
|
||||||
switch(part){
|
switch(part){
|
||||||
case 1:
|
case 1:
|
||||||
images = [trial.a_path, trial.b_path];
|
images = [trial.a_path, trial.b_path];
|
||||||
if(Math.floor(Math.random()*2)==0){
|
if(Math.floor(Math.random()*2)==0){
|
||||||
images = [trial.b_path, trial.a_path];
|
images = [trial.b_path, trial.a_path];
|
||||||
}
|
}
|
||||||
// show the images
|
// show the images
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": images[0],
|
"src": images[0],
|
||||||
"class": 'sim'
|
"class": 'sim'
|
||||||
}));
|
}));
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": images[1],
|
"src": images[1],
|
||||||
"class": 'sim'
|
"class": 'sim'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// create slider
|
// create slider
|
||||||
$this.append($('<div>', { "id": 'slider', "class": 'sim' }));
|
$this.append($('<div>', { "id": 'slider', "class": 'sim' }));
|
||||||
$("#slider").slider(
|
$("#slider").slider(
|
||||||
{
|
{
|
||||||
value:50,
|
value:50,
|
||||||
min:0,
|
min:0,
|
||||||
max:100,
|
max:100,
|
||||||
step:1,
|
step:1,
|
||||||
});
|
});
|
||||||
|
|
||||||
// create button
|
// create button
|
||||||
$this.append($('<button>', {'id':'next','class':'sim'}));
|
$this.append($('<button>', {'id':'next','class':'sim'}));
|
||||||
$("#next").html('Next');
|
$("#next").html('Next');
|
||||||
$("#next").click(function(){
|
$("#next").click(function(){
|
||||||
similarity_trial($this,block,trial,part+1);
|
plugin.trial($this,block,trial,part+1);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// get data
|
// get data
|
||||||
var score = $("#slider").slider("value");
|
var score = $("#slider").slider("value");
|
||||||
block.data[block.trial_idx] = {"score": score, "a_path": trial.a_path, "b_path": trial.b_path}
|
block.data[block.trial_idx] = {"score": score, "a_path": trial.a_path, "b_path": trial.b_path}
|
||||||
// goto next trial in block
|
// goto next trial in block
|
||||||
$('.sim').remove();
|
$('.sim').remove();
|
||||||
setTimeout(function(){block.next();}, trial.timing[0]);
|
setTimeout(function(){block.next();}, trial.timing[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
})();
|
})();
|
||||||
})(jQuery);
|
})(jQuery);
|
@ -1,5 +1,5 @@
|
|||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
jsPsych.xab-touch = (function(){
|
jsPsych.xab_touch = (function(){
|
||||||
|
|
||||||
var plugin = {};
|
var plugin = {};
|
||||||
|
|
||||||
@ -10,7 +10,7 @@
|
|||||||
for(var i = 0; i < trials.length; i++)
|
for(var i = 0; i < trials.length; i++)
|
||||||
{
|
{
|
||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
trials[i]["type"] = "xab-touch";
|
trials[i]["type"] = "xab_touch";
|
||||||
trials[i]["a_path"] = xab_stims[i][0];
|
trials[i]["a_path"] = xab_stims[i][0];
|
||||||
trials[i]["b_path"] = xab_stims[i][1];
|
trials[i]["b_path"] = xab_stims[i][1];
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["timing"] = params["timing"];
|
||||||
@ -30,12 +30,12 @@
|
|||||||
"src": trial.a_path,
|
"src": trial.a_path,
|
||||||
"class": 'xab_touch'
|
"class": 'xab_touch'
|
||||||
}));
|
}));
|
||||||
setTimeout(function(){xab_touch_trial($this, block, trial, part + 1);}, trial.timing[0]);
|
setTimeout(function(){plugin.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(function(){xab_touch_trial($this, block, trial, part + 1);}, trial.timing[1]);
|
setTimeout(function(){plugin.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();
|
||||||
|
Loading…
Reference in New Issue
Block a user