mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Reworking the plugin structure to use the Module javascript design pattern.
Plugins now have a consistent internal structure, with better variable scoping. This version breaks backward compatibility due to a change in the syntax of how experiment objects are declared.
This commit is contained in:
parent
9c8884f356
commit
9c94b4d0b6
@ -5,8 +5,12 @@
|
||||
// option to keep stim on screen during feedback
|
||||
// way to provide corrective feedback
|
||||
|
||||
function cf_create(params)
|
||||
{
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.categorize-feedback = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
cf_stims = params["stimuli"];
|
||||
trials = new Array(cf_stims.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
@ -29,10 +33,10 @@ function cf_create(params)
|
||||
}
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function cf_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
p1_time = (new Date()).getTime();
|
||||
@ -113,5 +117,9 @@ function cf_trial($this, block, trial, part)
|
||||
setTimeout(function(){block.next();}, trial.timing[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -1,8 +1,12 @@
|
||||
// timing parameters: [intertrial gap, optional length to display target]
|
||||
// if optional length to display target is missing, then target is displayed until subject responds.
|
||||
|
||||
function cu_create(params)
|
||||
{
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.categorize-unknown = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
cu_stims = params["stimuli"];
|
||||
trials = new Array(cu_stims.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
@ -20,10 +24,10 @@ function cu_create(params)
|
||||
}
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function cu_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
p1_time = (new Date()).getTime();
|
||||
@ -71,5 +75,9 @@ function cu_trial($this, block, trial, part)
|
||||
$(document).keyup(resp_func);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -1,5 +1,9 @@
|
||||
function sd_create(params)
|
||||
{
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.samedifferent = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
sd_stims = params["stimuli"];
|
||||
trials = new Array(sd_stims.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
@ -18,10 +22,10 @@ function sd_create(params)
|
||||
}
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function sd_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
p1_time = (new Date()).getTime();
|
||||
@ -85,5 +89,9 @@ function sd_trial($this, block, trial, part)
|
||||
$(document).keyup(resp_func);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
}) (jQuery);
|
||||
|
@ -1,5 +1,9 @@
|
||||
function similarity_create(params)
|
||||
{
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.text = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
sim_stims = params["stimuli"];
|
||||
trials = new Array(sim_stims.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
@ -11,10 +15,10 @@ function similarity_create(params)
|
||||
trials[i]["timing"] = params["timing"];
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function similarity_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
images = [trial.a_path, trial.b_path];
|
||||
@ -57,4 +61,8 @@ function similarity_trial($this, block, trial, part)
|
||||
setTimeout(function(){block.next();}, trial.timing[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
@ -1,5 +1,10 @@
|
||||
function text_create(params)
|
||||
{
|
||||
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.text = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
var trials = new Array(params.text.length);
|
||||
for(var i = 0; i < trials.length; i++)
|
||||
{
|
||||
@ -10,10 +15,9 @@ function text_create(params)
|
||||
trials[i]["timing"] = params.timing;
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function text_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part) {
|
||||
$this.html(trial.text);
|
||||
var key_listener = function(e) {
|
||||
if(e.which==trial.cont_key)
|
||||
@ -25,4 +29,8 @@ function text_trial($this, block, trial, part)
|
||||
}
|
||||
}
|
||||
$(document).keyup(key_listener);
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
}) (jQuery);
|
@ -1,5 +1,11 @@
|
||||
function xab_create(params)
|
||||
{
|
||||
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.xab = (function(){
|
||||
|
||||
var plugin = {}
|
||||
|
||||
plugin.create = function(params)
|
||||
{
|
||||
//xab_stims = shuffle(xab_stims);
|
||||
xab_stims = params["stimuli"];
|
||||
trials = new Array(xab_stims.length);
|
||||
@ -15,10 +21,10 @@ function xab_create(params)
|
||||
}
|
||||
}
|
||||
return trials;
|
||||
}
|
||||
}
|
||||
|
||||
function xab_trial($this, block, trial, part)
|
||||
{
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
p1_time = (new Date()).getTime();
|
||||
@ -83,4 +89,8 @@ function xab_trial($this, block, trial, part)
|
||||
//based on timings
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
@ -25,7 +25,7 @@
|
||||
{
|
||||
if(opts["experiment_structure"][i]["type"] == opts["plugins"][j]["type"])
|
||||
{
|
||||
trials = opts["plugins"][j]["createFunc"].call(null, opts["experiment_structure"][i]);
|
||||
trials = opts["plugins"][j]["src"]["create"].call(null, opts["experiment_structure"][i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
{
|
||||
if(trial.type == opts["plugins"][j]["type"])
|
||||
{
|
||||
opts["plugins"][j]["trialFunc"].call(this, $this, block, trial, 1);
|
||||
opts["plugins"][j]["src"]["trial"].call(this, $this, block, trial, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user