diff --git a/docs/markdown_docs/plugins/creating-a-plugin.md b/docs/markdown_docs/plugins/creating-a-plugin.md
index 1087a816..c69192fc 100644
--- a/docs/markdown_docs/plugins/creating-a-plugin.md
+++ b/docs/markdown_docs/plugins/creating-a-plugin.md
@@ -7,7 +7,7 @@ Creating new plugins is the way to add new kinds of tasks to jsPsych. A task can
Plugin files follow a specific template. Adherence to the template is what allows jsPsych to run a plugin without knowing anything about what the plugin is doing. What makes plugins so flexible is that the template imposes very few requirements on the code. Here's what an empty plugin template looks like:
```
-jsPsych['plugin-name'] = (function(){
+jsPsych.plugins['plugin-name'] = (function(){
var plugin = {};
diff --git a/jspsych.js b/jspsych.js
index 445ea7ea..c18741eb 100755
--- a/jspsych.js
+++ b/jspsych.js
@@ -263,7 +263,7 @@ var jsPsych = (function() {
var trial_type = parameters.type;
if (typeof trial_type == 'undefined') {
console.error('Trial level node is missing the "type" parameter. The parameters for the node are: ' + JSON.stringify(parameters));
- } else if (typeof jsPsych[trial_type] == 'undefined') {
+ } else if (typeof jsPsych.plugins[trial_type] == 'undefined') {
console.error('No plugin loaded for trials of type "' + trial_type + '"');
}
// create a deep copy of the parameters for the trial
@@ -555,7 +555,7 @@ var jsPsych = (function() {
opts.on_trial_start();
// execute trial method
- jsPsych[trial.type].trial(DOM_target, trial);
+ jsPsych.plugins[trial.type].trial(DOM_target, trial);
}
function drawProgressBar() {
@@ -576,6 +576,8 @@ var jsPsych = (function() {
return core;
})();
+jsPsych.plugins = {};
+
jsPsych.data = (function() {
var module = {};
diff --git a/plugins/jspsych-animation.js b/plugins/jspsych-animation.js
index d23fcafb..0622a2ca 100644
--- a/plugins/jspsych-animation.js
+++ b/plugins/jspsych-animation.js
@@ -5,7 +5,7 @@
* documentation: docs.jspsych.org
*/
-jsPsych.animation = (function() {
+jsPsych.plugins.animation = (function() {
var plugin = {};
diff --git a/plugins/jspsych-button-response.js b/plugins/jspsych-button-response.js
index 28c94b39..58612722 100644
--- a/plugins/jspsych-button-response.js
+++ b/plugins/jspsych-button-response.js
@@ -8,7 +8,7 @@
*
**/
-jsPsych["button-response"] = (function() {
+jsPsych.plugins["button-response"] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-call-function.js b/plugins/jspsych-call-function.js
index b67561a1..bffb137e 100644
--- a/plugins/jspsych-call-function.js
+++ b/plugins/jspsych-call-function.js
@@ -7,7 +7,7 @@
*
**/
-jsPsych['call-function'] = (function() {
+jsPsych.plugins['call-function'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-categorize-animation.js b/plugins/jspsych-categorize-animation.js
index 83af67e6..bea15b5a 100644
--- a/plugins/jspsych-categorize-animation.js
+++ b/plugins/jspsych-categorize-animation.js
@@ -6,7 +6,7 @@
**/
-jsPsych["categorize-animation"] = (function() {
+jsPsych.plugins["categorize-animation"] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-categorize.js b/plugins/jspsych-categorize.js
index 86032953..6a55c470 100644
--- a/plugins/jspsych-categorize.js
+++ b/plugins/jspsych-categorize.js
@@ -6,7 +6,7 @@
**/
-jsPsych.categorize = (function() {
+jsPsych.plugins.categorize = (function() {
var plugin = {};
diff --git a/plugins/jspsych-free-sort.js b/plugins/jspsych-free-sort.js
index 7bb4eebe..ef69a83a 100644
--- a/plugins/jspsych-free-sort.js
+++ b/plugins/jspsych-free-sort.js
@@ -7,7 +7,7 @@
*/
-jsPsych['free-sort'] = (function() {
+jsPsych.plugins['free-sort'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-html.js b/plugins/jspsych-html.js
index e8e4acfe..e8decb46 100644
--- a/plugins/jspsych-html.js
+++ b/plugins/jspsych-html.js
@@ -6,7 +6,7 @@ the plugin will wait of a specified time before it proceeds.
documentation: docs.jspsych.org
*/
-jsPsych.html = (function() {
+jsPsych.plugins.html = (function() {
var plugin = {};
diff --git a/plugins/jspsych-instructions.js b/plugins/jspsych-instructions.js
index 37c2c713..48af66fd 100644
--- a/plugins/jspsych-instructions.js
+++ b/plugins/jspsych-instructions.js
@@ -9,7 +9,7 @@
*
*/
-jsPsych.instructions = (function() {
+jsPsych.plugins.instructions = (function() {
var plugin = {};
diff --git a/plugins/jspsych-multi-stim-multi-response.js b/plugins/jspsych-multi-stim-multi-response.js
index cb7f350c..102509b0 100644
--- a/plugins/jspsych-multi-stim-multi-response.js
+++ b/plugins/jspsych-multi-stim-multi-response.js
@@ -10,7 +10,7 @@
**/
-jsPsych["multi-stim-multi-response"] = (function() {
+jsPsych.plugins["multi-stim-multi-response"] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-palmer.js b/plugins/jspsych-palmer.js
index d59cb64d..f1ba0479 100644
--- a/plugins/jspsych-palmer.js
+++ b/plugins/jspsych-palmer.js
@@ -16,7 +16,7 @@
*/
-jsPsych.palmer = (function() {
+jsPsych.plugins.palmer = (function() {
var plugin = {};
diff --git a/plugins/jspsych-reconstruction.js b/plugins/jspsych-reconstruction.js
index e2c70770..a90bf158 100644
--- a/plugins/jspsych-reconstruction.js
+++ b/plugins/jspsych-reconstruction.js
@@ -10,7 +10,7 @@
*/
-jsPsych['reconstruction'] = (function() {
+jsPsych.plugins['reconstruction'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-same-different.js b/plugins/jspsych-same-different.js
index 998cbe9f..4cde84bf 100644
--- a/plugins/jspsych-same-different.js
+++ b/plugins/jspsych-same-different.js
@@ -8,7 +8,7 @@
*
*/
-jsPsych['same-different'] = (function() {
+jsPsych.plugins['same-different'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-similarity.js b/plugins/jspsych-similarity.js
index 54b47b49..e083c419 100644
--- a/plugins/jspsych-similarity.js
+++ b/plugins/jspsych-similarity.js
@@ -9,7 +9,7 @@
*/
-jsPsych.similarity = (function() {
+jsPsych.plugins.similarity = (function() {
var plugin = {};
diff --git a/plugins/jspsych-single-audio.js b/plugins/jspsych-single-audio.js
index 824a615b..e372211c 100644
--- a/plugins/jspsych-single-audio.js
+++ b/plugins/jspsych-single-audio.js
@@ -8,7 +8,7 @@
*
**/
-jsPsych["single-audio"] = (function() {
+jsPsych.plugins["single-audio"] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-single-stim.js b/plugins/jspsych-single-stim.js
index cb6c3a7f..3c1056ef 100644
--- a/plugins/jspsych-single-stim.js
+++ b/plugins/jspsych-single-stim.js
@@ -9,7 +9,7 @@
**/
-jsPsych["single-stim"] = (function() {
+jsPsych.plugins["single-stim"] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-survey-likert.js b/plugins/jspsych-survey-likert.js
index 2b9f0f43..ca1859d0 100644
--- a/plugins/jspsych-survey-likert.js
+++ b/plugins/jspsych-survey-likert.js
@@ -8,7 +8,7 @@
*
*/
-jsPsych['survey-likert'] = (function() {
+jsPsych.plugins['survey-likert'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-survey-multi-choice.js b/plugins/jspsych-survey-multi-choice.js
index ce257b32..b1bd8818 100644
--- a/plugins/jspsych-survey-multi-choice.js
+++ b/plugins/jspsych-survey-multi-choice.js
@@ -9,7 +9,7 @@
*/
-jsPsych['survey-multi-choice'] = (function() {
+jsPsych.plugins['survey-multi-choice'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-survey-text.js b/plugins/jspsych-survey-text.js
index c0db7da3..e7fd5d4c 100644
--- a/plugins/jspsych-survey-text.js
+++ b/plugins/jspsych-survey-text.js
@@ -9,7 +9,7 @@
*/
-jsPsych['survey-text'] = (function() {
+jsPsych.plugins['survey-text'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-text.js b/plugins/jspsych-text.js
index 6a354963..7d3cd5bb 100644
--- a/plugins/jspsych-text.js
+++ b/plugins/jspsych-text.js
@@ -9,7 +9,7 @@
*
*/
-jsPsych.text = (function() {
+jsPsych.plugins.text = (function() {
var plugin = {};
diff --git a/plugins/jspsych-visual-search-circle.js b/plugins/jspsych-visual-search-circle.js
index 80fa3bd9..d2f0bbc7 100644
--- a/plugins/jspsych-visual-search-circle.js
+++ b/plugins/jspsych-visual-search-circle.js
@@ -14,144 +14,162 @@
*
**/
- jsPsych["visual-search-circle"] = (function() {
+jsPsych.plugins["visual-search-circle"] = (function() {
- var plugin = {};
+ var plugin = {};
- jsPsych.pluginAPI.registerPreload('visual-search-circle', 'target', 'image');
- jsPsych.pluginAPI.registerPreload('visual-search-circle', 'foil', 'image');
- jsPsych.pluginAPI.registerPreload('visual-search-circle', 'fixation_image', 'image');
+ jsPsych.pluginAPI.registerPreload('visual-search-circle', 'target', 'image');
+ jsPsych.pluginAPI.registerPreload('visual-search-circle', 'foil', 'image');
+ jsPsych.pluginAPI.registerPreload('visual-search-circle', 'fixation_image', 'image');
- plugin.create = function(params) {
+ plugin.create = function(params) {
- var trials = new Array(params.target_present.length);
+ var trials = new Array(params.target_present.length);
+
+ for (var i = 0; i < trials.length; i++) {
+ trials[i] = {};
+ trials[i].target_present = params.target_present[i];
+ trials[i].set_size = params.set_size[i];
+ trials[i].target = params.target;
+ trials[i].foil = params.foil;
+ trials[i].fixation_image = params.fixation_image;
+ trials[i].target_size = params.target_size || [50, 50];
+ trials[i].fixation_size = params.fixation_size || [16, 16];
+ trials[i].circle_diameter = params.circle_diameter || 250;
+ trials[i].target_present_key = params.target_present_key || 74;
+ trials[i].target_absent_key = params.target_absent_key || 70;
+ trials[i].timing_max_search = (typeof params.timing_max_search === 'undefined') ? -1 : params.timing_max_search;
+ trials[i].timing_fixation = (typeof params.timing_fixation === 'undefined') ? 1000 : params.timing_fixation;
+ }
+
+ return trials;
+ };
+
+ plugin.trial = function(display_element, trial) {
+
+ // default values
+ trial.target_size = trial.target_size || [50, 50];
+ trial.fixation_size = trial.fixation_size || [16, 16];
+ trial.circle_diameter = trial.circle_diameter || 250;
+ trial.target_present_key = trial.target_present_key || 74;
+ trial.target_absent_key = trial.target_absent_key || 70;
+ trial.timing_max_search = (typeof trial.timing_max_search === 'undefined') ? -1 : trial.timing_max_search;
+ trial.timing_fixation = (typeof trial.timing_fixation === 'undefined') ? 1000 : trial.timing_fixation;
+
+ trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
+
+ // screen information
+ var screenw = display_element.width();
+ var screenh = display_element.height();
+ var centerx = screenw / 2;
+ var centery = screenh / 2;
+
+ // circle params
+ var diam = trial.circle_diameter; // pixels
+ var radi = diam / 2;
+ var paper_size = diam + trial.target_size[0];
+
+ // stimuli width, height
+ var stimh = trial.target_size[0];
+ var stimw = trial.target_size[1];
+ var hstimh = stimh / 2;
+ var hstimw = stimw / 2;
+
+ // fixation location
+ var fix_loc = [Math.floor(paper_size / 2 - trial.fixation_size[0] / 2), Math.floor(paper_size / 2 - trial.fixation_size[1] / 2)];
+
+ // possible stimulus locations on the circle
+ var display_locs = [];
+ var possible_display_locs = trial.set_size;
+ var random_offset = Math.floor(Math.random() * 360);
+ for (var i = 0; i < possible_display_locs; i++) {
+ display_locs.push([
+ Math.floor(paper_size / 2 + (cosd(random_offset + (i * (360 / possible_display_locs))) * radi) - hstimw),
+ Math.floor(paper_size / 2 - (sind(random_offset + (i * (360 / possible_display_locs))) * radi) - hstimh)
+ ]);
+ }
+
+ // get target to draw on
+ display_element.append($(''));
+ var paper = Snap('#jspsych-visual-search-circle-svg');
+
+ show_fixation();
+
+ function show_fixation() {
+ // show fixation
+ var fixation = paper.image(trial.fixation_image, fix_loc[0], fix_loc[1], trial.fixation_size[0], trial.fixation_size[1]);
+
+ // wait
+ setTimeout(function() {
+ // after wait is over
+ show_search_array();
+ }, trial.timing_fixation);
+ }
+
+ function show_search_array() {
+
+ var search_array_images = [];
+
+ for (var i = 0; i < display_locs.length; i++) {
+
+ var which_image = (i == 0 && trial.target_present) ? trial.target : trial.foil;
+
+ var img = paper.image(which_image, display_locs[i][0], display_locs[i][1], trial.target_size[0], trial.target_size[1]);
+
+ search_array_images.push(img);
- for (var i = 0; i < trials.length; i++) {
- trials[i] = {};
- trials[i].target_present = params.target_present[i];
- trials[i].set_size = params.set_size[i];
- trials[i].target = params.target;
- trials[i].foil = params.foil;
- trials[i].fixation_image = params.fixation_image;
- trials[i].target_size = params.target_size || [50, 50];
- trials[i].fixation_size = params.fixation_size || [16, 16];
- trials[i].circle_diameter = params.circle_diameter || 250;
- trials[i].target_present_key = params.target_present_key || 74;
- trials[i].target_absent_key = params.target_absent_key || 70;
- trials[i].timing_max_search = (typeof params.timing_max_search === 'undefined') ? -1 : params.timing_max_search;
- trials[i].timing_fixation = (typeof params.timing_fixation === 'undefined') ? 1000 : params.timing_fixation;
}
- return trials;
- };
+ var trial_over = false;
- plugin.trial = function(display_element, trial) {
+ var after_response = function(info) {
- // default values
- trial.target_size = trial.target_size || [50, 50];
- trial.fixation_size = trial.fixation_size || [16, 16];
- trial.circle_diameter = trial.circle_diameter || 250;
- trial.target_present_key = trial.target_present_key || 74;
- trial.target_absent_key = trial.target_absent_key || 70;
- trial.timing_max_search = (typeof trial.timing_max_search === 'undefined') ? -1 : trial.timing_max_search;
- trial.timing_fixation = (typeof trial.timing_fixation === 'undefined') ? 1000 : trial.timing_fixation;
+ trial_over = true;
- trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
-
- // screen information
- var screenw = display_element.width();
- var screenh = display_element.height();
- var centerx = screenw / 2;
- var centery = screenh / 2;
-
- // circle params
- var diam = trial.circle_diameter; // pixels
- var radi = diam / 2;
- var paper_size = diam + trial.target_size[0];
-
- // stimuli width, height
- var stimh = trial.target_size[0];
- var stimw = trial.target_size[1];
- var hstimh = stimh / 2;
- var hstimw = stimw / 2;
-
- // fixation location
- var fix_loc = [Math.floor(paper_size / 2 - trial.fixation_size[0] / 2), Math.floor(paper_size / 2 - trial.fixation_size[1] / 2)];
-
- // possible stimulus locations on the circle
- var display_locs = [];
- var possible_display_locs = trial.set_size;
- var random_offset = Math.floor(Math.random() * 360);
- for (var i = 0; i < possible_display_locs; i++) {
- display_locs.push([
- Math.floor(paper_size / 2 + (cosd(random_offset + (i * (360 / possible_display_locs))) * radi) - hstimw),
- Math.floor(paper_size / 2 - (sind(random_offset + (i * (360 / possible_display_locs))) * radi) - hstimh)
- ]);
- }
-
- // get target to draw on
- display_element.append($(''));
- var paper = Snap('#jspsych-visual-search-circle-svg');
-
- show_fixation();
-
- function show_fixation() {
- // show fixation
- var fixation = paper.image(trial.fixation_image, fix_loc[0], fix_loc[1], trial.fixation_size[0], trial.fixation_size[1]);
-
- // wait
- setTimeout(function() {
- // after wait is over
- show_search_array();
- }, trial.timing_fixation);
- }
-
- function show_search_array() {
-
- var search_array_images = [];
-
- for (var i = 0; i < display_locs.length; i++) {
-
- var which_image = (i == 0 && trial.target_present) ? trial.target : trial.foil;
-
- var img = paper.image(which_image, display_locs[i][0], display_locs[i][1], trial.target_size[0], trial.target_size[1]);
-
- search_array_images.push(img);
+ var correct = 0;
+ if (info.key == trial.target_present_key && trial.target_present ||
+ info.key == trial.target_absent_key && !trial.target_present) {
+ correct = 1;
}
- var trial_over = false;
+ clear_display();
- var after_response = function(info) {
+ end_trial(info.rt, correct, info.key);
- trial_over = true;
+ }
- var correct = 0;
+ var valid_keys = [trial.target_present_key, trial.target_absent_key];
- if (info.key == trial.target_present_key && trial.target_present ||
- info.key == trial.target_absent_key && !trial.target_present) {
- correct = 1;
+ key_listener = jsPsych.pluginAPI.getKeyboardResponse({
+ callback_function: after_response,
+ valid_responses: valid_keys,
+ rt_method: 'date',
+ persist: false,
+ allow_held_key: false
+ });
+
+ if (trial.timing_max_search > -1) {
+
+ if (trial.timing_max_search == 0) {
+ if (!trial_over) {
+
+ jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
+
+ trial_over = true;
+
+ var rt = -1;
+ var correct = 0;
+ var key_press = -1;
+
+ clear_display();
+
+ end_trial(rt, correct, key_press);
}
+ } else {
- clear_display();
+ setTimeout(function() {
- end_trial(info.rt, correct, info.key);
-
- }
-
- var valid_keys = [trial.target_present_key, trial.target_absent_key];
-
- key_listener = jsPsych.pluginAPI.getKeyboardResponse({
- callback_function: after_response,
- valid_responses: valid_keys,
- rt_method: 'date',
- persist: false,
- allow_held_key: false
- });
-
- if (trial.timing_max_search > -1) {
-
- if (trial.timing_max_search == 0) {
if (!trial_over) {
jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
@@ -166,60 +184,42 @@
end_trial(rt, correct, key_press);
}
- } else {
-
- setTimeout(function() {
-
- if (!trial_over) {
-
- jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
-
- trial_over = true;
-
- var rt = -1;
- var correct = 0;
- var key_press = -1;
-
- clear_display();
-
- end_trial(rt, correct, key_press);
- }
- }, trial.timing_max_search);
- }
- }
-
- function clear_display() {
- display_element.html('');
+ }, trial.timing_max_search);
}
}
-
- function end_trial(rt, correct, key_press) {
-
- // data saving
- var trial_data = {
- correct: correct,
- rt: rt,
- key_press: key_press,
- locations: JSON.stringify(display_locs),
- target_present: trial.target_present,
- set_size: trial.set_size
- };
-
- // go to next trial
- jsPsych.finishTrial(trial_data);
+ function clear_display() {
+ display_element.html('');
}
- };
-
- // helper function for determining stimulus locations
-
- function cosd(num) {
- return Math.cos(num / 180 * Math.PI);
}
- function sind(num) {
- return Math.sin(num / 180 * Math.PI);
- }
- return plugin;
- })();
+ function end_trial(rt, correct, key_press) {
+
+ // data saving
+ var trial_data = {
+ correct: correct,
+ rt: rt,
+ key_press: key_press,
+ locations: JSON.stringify(display_locs),
+ target_present: trial.target_present,
+ set_size: trial.set_size
+ };
+
+ // go to next trial
+ jsPsych.finishTrial(trial_data);
+ }
+ };
+
+ // helper function for determining stimulus locations
+
+ function cosd(num) {
+ return Math.cos(num / 180 * Math.PI);
+ }
+
+ function sind(num) {
+ return Math.sin(num / 180 * Math.PI);
+ }
+
+ return plugin;
+})();
diff --git a/plugins/jspsych-vsl-animate-occlusion.js b/plugins/jspsych-vsl-animate-occlusion.js
index db0256b7..ac028c01 100644
--- a/plugins/jspsych-vsl-animate-occlusion.js
+++ b/plugins/jspsych-vsl-animate-occlusion.js
@@ -11,7 +11,7 @@
*
*/
-jsPsych['vsl-animate-occlusion'] = (function() {
+jsPsych.plugins['vsl-animate-occlusion'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-vsl-grid-scene.js b/plugins/jspsych-vsl-grid-scene.js
index bf79e698..037d75a7 100644
--- a/plugins/jspsych-vsl-grid-scene.js
+++ b/plugins/jspsych-vsl-grid-scene.js
@@ -11,7 +11,7 @@
*
*/
-jsPsych['vsl-grid-scene'] = (function() {
+jsPsych.plugins['vsl-grid-scene'] = (function() {
var plugin = {};
diff --git a/plugins/jspsych-xab.js b/plugins/jspsych-xab.js
index 08bc4602..b2a04d95 100644
--- a/plugins/jspsych-xab.js
+++ b/plugins/jspsych-xab.js
@@ -8,7 +8,7 @@
*
*/
-jsPsych.xab = (function() {
+jsPsych.plugins.xab = (function() {
var plugin = {};
diff --git a/plugins/template/jspsych-plugin-template.js b/plugins/template/jspsych-plugin-template.js
index 32287bfd..1f60630c 100644
--- a/plugins/template/jspsych-plugin-template.js
+++ b/plugins/template/jspsych-plugin-template.js
@@ -2,7 +2,7 @@
* Example plugin template
*/
-jsPsych["PLUGIN-NAME"] = (function() {
+jsPsych.plugins["PLUGIN-NAME"] = (function() {
var plugin = {};