/**
* jspsych-survey-likert
* a jspsych plugin for measuring items on a likert scale
*
* Josh de Leeuw
*
* documentation: https://github.com/jodeleeuw/jsPsych/wiki/jspsych-survey-likert
*
*/
(function($) {
jsPsych['survey-likert'] = (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({
questions: params.questions[i],
labels: params.labels[i],
intervals: params.intervals[i],
show_ticks: (typeof params.show_ticks === 'undefined') ? true : params.show_ticks
});
}
return trials;
};
plugin.trial = function(display_element, block, trial) {
// if any trial variables are functions
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
// add likert scale questions
for (var i = 0; i < trial.questions.length; i++) {
// create div
display_element.append($('
', {
"id": 'jspsych-survey-likert-' + i,
"class": 'jspsych-survey-likert-question'
}));
// add question text
$("#jspsych-survey-likert-" + i).append('