/** * jspsych-survey-text * a jspsych plugin for free response survey questions * * Josh de Leeuw * * documentation: docs.jspsych.org * */ (function($) { jsPsych['survey-text'] = (function() { var plugin = {}; plugin.create = function(params) { //params = jsPsych.pluginAPI.enforceArray(params, ['data']); var trials = []; for (var i = 0; i < params.questions.length; i++) { var rows = [], cols = []; if(typeof params.rows == 'undefined' || typeof params.columns == 'undefined'){ for(var j = 0; j < params.questions[i].length; j++){ cols.push(40); rows.push(1); } } trials.push({ preamble: typeof params.preamble == 'undefined' ? "" : params.preamble[i], questions: params.questions[i], rows: typeof params.rows == 'undefined' ? rows : params.rows[i], columns: typeof params.columns == 'undefined' ? cols : params.columns[i] }); } 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.evaluateFunctionParameters(trial); // show preamble text display_element.append($('
' + trial.questions[i] + '
'); // add text box $("#jspsych-survey-text-" + i).append(''); } // add submit button display_element.append($('