/** * jspsych plugin for categorization trials with feedback * Josh de Leeuw * * documentation: docs.jspsych.org **/ (function($) { jsPsych.categorize = (function() { var plugin = {}; plugin.create = function(params) { params = jsPsych.pluginAPI.enforceArray(params, ['choices', 'stimuli', 'key_answer', 'text_answer', 'data']); var trials = []; for (var i = 0; i < params.stimuli.length; i++) { trials.push({}); trials[i].a_path = params.stimuli[i]; trials[i].key_answer = params.key_answer[i]; trials[i].text_answer = (typeof params.text_answer === 'undefined') ? "" : params.text_answer[i]; trials[i].choices = params.choices; trials[i].correct_text = (typeof params.correct_text === 'undefined') ? "
Correct
" : params.correct_text; trials[i].incorrect_text = (typeof params.incorrect_text === 'undefined') ? "Incorrect
" : params.incorrect_text; // timing params trials[i].timing_stim = params.timing_stim || -1; // default is to show image until response trials[i].timing_feedback_duration = params.timing_feedback_duration || 2000; // optional params trials[i].show_stim_with_feedback = (typeof params.show_stim_with_feedback === 'undefined') ? true : params.show_stim_with_feedback; trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html; trials[i].force_correct_button_press = (typeof params.force_correct_button_press === 'undefined') ? false : params.force_correct_button_press; trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt; } return trials; }; 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); // this array holds handlers from setTimeout calls // that need to be cleared if the trial ends early var setTimeoutHandlers = []; if (!trial.is_html) { // add image to display display_element.append($('