/** * jspsych-survey-multi-choice * a jspsych plugin for multiple choice survey questions * * Shane Martin * * documentation: docs.jspsych.org * */ (function($) { jsPsych['survey-multi-choice'] = (function() { var plugin = {}; plugin.create = function(params) { //params = jsPsych.pluginAPI.enforceArray(params, ['data']); var trials = []; for (var i = 0; i < params.questions.length; i++) { trials.push({ preamble: (typeof params.preamble === 'undefined') ? "" : params.preamble[i], questions: params.questions[i], options: params.options[i], }); } return trials; }; plugin.trial = function(display_element, trial) { var plugin_id_name = "jspsych-survey-multi-choice", plugin_id_selector = '#' + plugin_id_name, _join = function(/*args*/) { var arr = Array.prototype.slice.call(arguments, _join.length); return arr.join(separator='-'); } // 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 var preamble_id_name = _join(plugin_id_name, 'preamble'); display_element.append($('
' + trial.questions[i] + '
' ); // create option radio buttons for (var j = 0; j < trial.options[i].length; j++) { var option_id_name = _join(plugin_id_name, "option", i, j), option_id_selector = '#' + option_id_name; // add radio button container $(question_selector).append($('