diff --git a/examples/jspsych-survey-slider.html b/examples/jspsych-survey-slider.html new file mode 100644 index 00000000..809f6bd8 --- /dev/null +++ b/examples/jspsych-survey-slider.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + diff --git a/plugins/jspsych-survey-slider.js b/plugins/jspsych-survey-slider.js new file mode 100644 index 00000000..6d2e311d --- /dev/null +++ b/plugins/jspsych-survey-slider.js @@ -0,0 +1,81 @@ +/** + * jspsych-survey-slider + * a jspsych plugin for free response survey questions + * + * Josh de Leeuw + * + * documentation: docs.jspsych.org + * + */ + + +jsPsych.plugins['survey-slider'] = (function() { + + var plugin = {}; + + plugin.info = { + name: 'survey-slider', + description: '', + parameters: { + + } + } + + plugin.trial = function(display_element, trial) { + + trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble; + trial.button_label = typeof trial.button_label === 'undefined' ? 'Next' : trial.button_label; + + // 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 html = '
'+trial.preamble+'
'; + + // add questions + for (var i = 0; i < trial.questions.length; i++) { + html += '
'; + html += '
' + trial.questions[i] + '
'; + html += ''; + html += '
'; + } + + // add submit button + html += ''; + + display_element.innerHTML = html; + + display_element.querySelector('#jspsych-survey-slider-next').addEventListener('click', function() { + // measure response time + var endTime = (new Date()).getTime(); + var response_time = endTime - startTime; + + // create object to hold responses + var question_data = {}; + var matches = display_element.querySelectorAll('div.jspsych-survey-slider-question'); + for(var index=0; index