/** * 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], required: (typeof params.required === 'undefined') ? null : params.required[i], horizontal: (typeof params.horizontal === 'undefined') ? false : params.horizontal }); } 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); // form element var trial_form_id = _join(plugin_id_name, "form"); display_element.append($('