/**
* jspsych-survey-text
* a jspsych plugin for free response survey questions
*
* Josh de Leeuw
*
* documentation: docs.jspsych.org
*
*/
jsPsych.plugins['survey-text'] = (function() {
var plugin = {};
plugin.trial = function(display_element, trial) {
trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble;
if (typeof trial.rows == 'undefined') {
trial.rows = [];
for (var i = 0; i < trial.questions.length; i++) {
trial.rows.push(1);
}
}
if (typeof trial.columns == 'undefined') {
trial.columns = [];
for (var i = 0; i < trial.questions.length; i++) {
trial.columns.push(40);
}
}
// 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($('
', {
"id": 'jspsych-survey-text-preamble',
"class": 'jspsych-survey-text-preamble'
}));
$('#jspsych-survey-text-preamble').html(trial.preamble);
// add questions
for (var i = 0; i < trial.questions.length; i++) {
// create div
display_element.append($('
', {
"id": 'jspsych-survey-text-' + i,
"class": 'jspsych-survey-text-question'
}));
// add question text
$("#jspsych-survey-text-" + i).append('