/* jspsych-xab.js
* Josh de Leeuw
*
* This plugin runs a single XAB trial, where X is an image presented in isolation, and A and B are choices, with A or B being equal to X.
* The subject's goal is to identify whether A or B is identical to X.
*
* documentation: https://github.com/jodeleeuw/jsPsych/wiki/jspsych-xab
*
*/
(function($) {
jsPsych.xab = (function() {
var plugin = {};
plugin.create = function(params) {
params = jsPsych.pluginAPI.enforceArray(params, ['data']);
// the number of trials is determined by how many entries the params.stimuli array has
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {
trials[i] = {};
trials[i].x_path = params.stimuli[i][0];
// if there is only a pair of stimuli, then the first is the target and is shown twice.
// if there is a triplet, then the first is X, the second is the target, and the third is foil (useful for non-exact-match XAB).
if (params.stimuli[i].length == 2) {
trials[i].a_path = params.stimuli[i][0];
trials[i].b_path = params.stimuli[i][1];
} else {
trials[i].a_path = params.stimuli[i][1];
trials[i].b_path = params.stimuli[i][2];
}
trials[i].left_key = params.left_key || 81; // defaults to 'q'
trials[i].right_key = params.right_key || 80; // defaults to 'p'
// timing parameters
trials[i].timing_x = params.timing_x || 1000; // defaults to 1000msec.
trials[i].timing_xab_gap = params.timing_xab_gap || 1000; // defaults to 1000msec.
trials[i].timing_ab = params.timing_ab || -1; // defaults to -1, meaning infinite time on AB. If a positive number is used, then AB will only be displayed for that length.
// optional parameters
trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html;
trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt;
}
return trials;
};
var xab_trial_complete = false;
plugin.trial = function(display_element, trial) {
// if any trial variables are functions
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
xab_trial_complete = false;
// how we display the content depends on whether the content is
// HTML code or an image path.
if (!trial.is_html) {
display_element.append($('', {
src: trial.x_path,
"class": 'jspsych-xab-stimulus'
}));
} else {
display_element.append($('