var jsPsychHtmlSliderResponse = (function (jspsych) {
'use strict';
const info = {
name: "html-slider-response",
parameters: {
/** The HTML string to be displayed */
stimulus: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Stimulus",
default: undefined,
},
/** Sets the minimum value of the slider. */
min: {
type: jspsych.ParameterType.INT,
pretty_name: "Min slider",
default: 0,
},
/** Sets the maximum value of the slider */
max: {
type: jspsych.ParameterType.INT,
pretty_name: "Max slider",
default: 100,
},
/** Sets the starting value of the slider */
slider_start: {
type: jspsych.ParameterType.INT,
pretty_name: "Slider starting value",
default: 50,
},
/** Sets the step of the slider */
step: {
type: jspsych.ParameterType.INT,
pretty_name: "Step",
default: 1,
},
/** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
labels: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Labels",
default: [],
array: true,
},
/** Width of the slider in pixels. */
slider_width: {
type: jspsych.ParameterType.INT,
pretty_name: "Slider width",
default: null,
},
/** Label of the button to advance. */
button_label: {
type: jspsych.ParameterType.STRING,
pretty_name: "Button label",
default: "Continue",
array: false,
},
/** If true, the participant will have to move the slider before continuing. */
require_movement: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Require movement",
default: false,
},
/** Any content here will be displayed below the slider. */
prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Prompt",
default: null,
},
/** How long to show the stimulus. */
stimulus_duration: {
type: jspsych.ParameterType.INT,
pretty_name: "Stimulus duration",
default: null,
},
/** How long to show the trial. */
trial_duration: {
type: jspsych.ParameterType.INT,
pretty_name: "Trial duration",
default: null,
},
/** If true, trial will end when user makes a response. */
response_ends_trial: {
type: jspsych.ParameterType.BOOL,
pretty_name: "Response ends trial",
default: true,
},
},
};
/**
* **html-slider-response**
*
* jsPsych plugin for showing an HTML stimulus and collecting a slider response
*
* @author Josh de Leeuw
* @see {@link https://www.jspsych.org/plugins/jspsych-html-slider-response/ html-slider-response plugin documentation on jspsych.org}
*/
class HtmlSliderResponsePlugin {
constructor(jsPsych) {
this.jsPsych = jsPsych;
}
trial(display_element, trial) {
// half of the thumb width value from jspsych.css, used to adjust the label positions
var half_thumb_width = 7.5;
var html = '
';
html += '
' + trial.stimulus + "
";
html +=
'
';
html +=
'';
html += "
";
for (var j = 0; j < trial.labels.length; j++) {
var label_width_perc = 100 / (trial.labels.length - 1);
var percent_of_range = j * (100 / (trial.labels.length - 1));
var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
var offset = (percent_dist_from_center * half_thumb_width) / 100;
html +=
'