/** * jspsych-serial-reaction-time * Josh de Leeuw * * plugin for running a serial reaction time task * * documentation: docs.jspsych.org * **/ jsPsych.plugins["serial-reaction-time-mouse"] = (function() { var plugin = {}; plugin.info = { name: 'serial-reaction-time-mouse', description: '', parameters: { target: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Target', array: true, default: undefined, description: 'The location of the target. The array should be the [row, column] of the target.' }, grid: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Grid', array: true, default: [[1,1,1,1]], description: 'This array represents the grid of boxes shown on the screen.' }, grid_square_size: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Grid square size', default: 100, description: 'The width and height in pixels of each square in the grid.' }, target_color: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Target color', default: "#999", description: 'The color of the target square.' }, response_ends_trial: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Response ends trial', default: true, description: 'If true, the trial ends after a key press.' }, pre_target_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Pre-target duration', default: 0, description: 'The number of milliseconds to display the grid before the target changes color.' }, trial_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Trial duration', default: null, description: 'How long to show the trial' }, fade_duration: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Fade duration', default: null, description: 'If a positive number, the target will progressively change color at the start of the trial, with the transition lasting this many milliseconds.' }, allow_nontarget_responses: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Allow nontarget response', default: false, description: 'If true, then user can make nontarget response.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'Any content here will be displayed below the stimulus' }, } } plugin.trial = function(display_element, trial) { var startTime = -1; var response = { rt: null, row: null, column: null } // display stimulus var stimulus = this.stimulus(trial.grid, trial.grid_square_size); display_element.innerHTML = stimulus; if(trial.pre_target_duration <= 0){ showTarget(); } else { jsPsych.pluginAPI.setTimeout(function(){ showTarget(); }, trial.pre_target_duration); } //show prompt if there is one if (trial.prompt !== null) { display_element.innerHTML += trial.prompt; } function showTarget(){ var resp_targets; if(!trial.allow_nontarget_responses){ resp_targets = [display_element.querySelector('#jspsych-serial-reaction-time-stimulus-cell-'+trial.target[0]+'-'+trial.target[1])] } else { resp_targets = display_element.querySelectorAll('.jspsych-serial-reaction-time-stimulus-cell'); } for(var i=0; i"; for(var i=0; i