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++)
|
||||
@ -31,7 +35,7 @@ function cf_create(params)
|
||||
return trials;
|
||||
}
|
||||
|
||||
function cf_trial($this, block, trial, part)
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
@ -115,3 +119,7 @@ function cf_trial($this, block, trial, part)
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
@ -22,7 +26,7 @@ function cu_create(params)
|
||||
return trials;
|
||||
}
|
||||
|
||||
function cu_trial($this, block, trial, part)
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
@ -73,3 +77,7 @@ function cu_trial($this, block, trial, part)
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
@ -20,7 +24,7 @@ function sd_create(params)
|
||||
return trials;
|
||||
}
|
||||
|
||||
function sd_trial($this, block, trial, part)
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
@ -87,3 +91,7 @@ function sd_trial($this, block, trial, part)
|
||||
}
|
||||
}
|
||||
|
||||
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++)
|
||||
@ -13,7 +17,7 @@ function similarity_create(params)
|
||||
return trials;
|
||||
}
|
||||
|
||||
function similarity_trial($this, block, trial, part)
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
@ -58,3 +62,7 @@ function similarity_trial($this, block, trial, part)
|
||||
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++)
|
||||
{
|
||||
@ -12,8 +17,7 @@ function text_create(params)
|
||||
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)
|
||||
@ -26,3 +30,7 @@ function text_trial($this, block, trial, part)
|
||||
}
|
||||
$(document).keyup(key_listener);
|
||||
}
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
}) (jQuery);
|
@ -1,4 +1,10 @@
|
||||
function xab_create(params)
|
||||
|
||||
(function( $ ) {
|
||||
$.fn.jsPsych.xab = (function(){
|
||||
|
||||
var plugin = {}
|
||||
|
||||
plugin.create = function(params)
|
||||
{
|
||||
//xab_stims = shuffle(xab_stims);
|
||||
xab_stims = params["stimuli"];
|
||||
@ -17,7 +23,7 @@ function xab_create(params)
|
||||
return trials;
|
||||
}
|
||||
|
||||
function xab_trial($this, block, trial, part)
|
||||
plugin.trial = function($this, block, trial, part)
|
||||
{
|
||||
switch(part){
|
||||
case 1:
|
||||
@ -84,3 +90,7 @@ function xab_trial($this, block, trial, part)
|
||||
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