// Josh de Leeuw
// Updated October 2013
//
// This plugin is for presenting a single image and collecting a key response.
// It can be used for categorizing images (without feedback), collecting yes/no responses, etc...
//
// parameters
// stimuli: array of stimuli to present. elements of the array can be either paths to images
// or HTML strings
// choices: array of key codes that represent valid responses. other key codes will be ignored
// continue_after_response: when true, the trial will end as soon as the user gives a response.
// if false, then the trial will continue until timing_response is reached
// timing_stim: how long to show the stimulus for. -1 will show indefinitely.
// timing_response: how long to wait for a response. this timer starts at the same time as the
// timer for the stimulus presentation. if the timer is reached without a response
// given, then the user's response will be recorded as a "-1" for the trial, and the
// trial will end.
// timing_post_trial: how long to show a blank screen after the trial ends.
// is_html: must set to true when using HTML strings as the stimuli.
// prompt: optional HTML string to display with the stimulus.
// data: the optional data object
(function($) {
jsPsych["single-stim"] = (function() {
var plugin = {};
plugin.create = function(params) {
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {
trials[i] = {};
trials[i].type = "single-stim";
trials[i].a_path = params.stimuli[i];
trials[i].choices = params.choices;
// option to show image for fixed time interval, ignoring key responses
// true = image will keep displaying after response
// false = trial will immediately advance when response is recorded
trials[i].continue_after_response = params.continue_after_response || true;
// timing parameters
trials[i].timing_stim = params.timing_stim || -1; // if -1, then show indefinitely
trials[i].timing_response = params.timing_response || -1; // if -1, then wait for response forever
trials[i].timing_post_trial = params.timing_post_trial || 1000;
// optional parameters
trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html;
trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt;
trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i];
}
return trials;
};
plugin.trial = function(display_element, block, trial, part) {
var trial_complete = false;
var startTime = (new Date()).getTime();
var key_press = -1;
if (!trial.is_html) {
display_element.append($('', {
src: trial.a_path,
id: 'ss'
}));
}
else {
display_element.append($('