@jspsych/plugin-survey-multi-choice 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,137 +1,126 @@
1
1
  var jsPsychSurveyMultiChoice = (function (jspsych) {
2
2
  'use strict';
3
3
 
4
- var _package = {
5
- name: "@jspsych/plugin-survey-multi-choice",
6
- version: "2.0.0",
7
- description: "a jspsych plugin for multiple choice survey questions",
8
- type: "module",
9
- main: "dist/index.cjs",
10
- exports: {
11
- import: "./dist/index.js",
12
- require: "./dist/index.cjs"
13
- },
14
- typings: "dist/index.d.ts",
15
- unpkg: "dist/index.browser.min.js",
16
- files: [
17
- "src",
18
- "dist"
19
- ],
20
- source: "src/index.ts",
21
- scripts: {
22
- test: "jest",
23
- "test:watch": "npm test -- --watch",
24
- tsc: "tsc",
25
- build: "rollup --config",
26
- "build:watch": "npm run build -- --watch"
27
- },
28
- repository: {
29
- type: "git",
30
- url: "git+https://github.com/jspsych/jsPsych.git",
31
- directory: "packages/plugin-survey-multi-choice"
32
- },
33
- author: "Shane Martin",
34
- license: "MIT",
35
- bugs: {
36
- url: "https://github.com/jspsych/jsPsych/issues"
37
- },
38
- homepage: "https://www.jspsych.org/latest/plugins/survey-multi-choice",
39
- peerDependencies: {
40
- jspsych: ">=7.1.0"
41
- },
42
- devDependencies: {
43
- "@jspsych/config": "^3.0.0",
44
- "@jspsych/test-utils": "^1.2.0"
45
- }
46
- };
4
+ var version = "2.0.2";
47
5
 
48
6
  const info = {
49
7
  name: "survey-multi-choice",
50
- version: _package.version,
8
+ version,
51
9
  parameters: {
10
+ /**
11
+ * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
12
+ * options, required, and horizontal parameter that will be applied to the question. See examples below for further
13
+ * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
14
+ * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
15
+ * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
16
+ * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
17
+ * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
18
+ * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
19
+ * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
20
+ * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
21
+ */
52
22
  questions: {
53
23
  type: jspsych.ParameterType.COMPLEX,
54
24
  array: true,
55
25
  nested: {
26
+ /** Question prompt. */
56
27
  prompt: {
57
28
  type: jspsych.ParameterType.HTML_STRING,
58
29
  default: void 0
59
30
  },
31
+ /** Array of multiple choice options for this question. */
60
32
  options: {
61
33
  type: jspsych.ParameterType.STRING,
62
34
  array: true,
63
35
  default: void 0
64
36
  },
37
+ /** Whether or not a response to this question must be given in order to continue. */
65
38
  required: {
66
39
  type: jspsych.ParameterType.BOOL,
67
40
  default: false
68
41
  },
42
+ /** If true, then the question will be centered and options will be displayed horizontally. */
69
43
  horizontal: {
70
44
  type: jspsych.ParameterType.BOOL,
71
45
  default: false
72
46
  },
47
+ /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
73
48
  name: {
74
49
  type: jspsych.ParameterType.STRING,
75
50
  default: ""
76
51
  }
77
52
  }
78
53
  },
54
+ /**
55
+ * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
56
+ * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
57
+ */
79
58
  randomize_question_order: {
80
59
  type: jspsych.ParameterType.BOOL,
81
60
  default: false
82
61
  },
62
+ /** HTML formatted string to display at the top of the page above all the questions. */
83
63
  preamble: {
84
64
  type: jspsych.ParameterType.HTML_STRING,
85
65
  default: null
86
66
  },
67
+ /** Label of the button. */
87
68
  button_label: {
88
69
  type: jspsych.ParameterType.STRING,
89
70
  default: "Continue"
90
71
  },
72
+ /**
73
+ * This determines whether or not all of the input elements on the page should allow autocomplete. Setting
74
+ * this to true will enable autocomplete or auto-fill for the form.
75
+ */
91
76
  autocomplete: {
92
77
  type: jspsych.ParameterType.BOOL,
93
78
  default: false
94
79
  }
95
80
  },
96
81
  data: {
82
+ /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
97
83
  response: {
98
- type: jspsych.ParameterType.COMPLEX,
99
- nested: {
100
- identifier: {
101
- type: jspsych.ParameterType.STRING
102
- },
103
- response: {
104
- type: jspsych.ParameterType.STRING | jspsych.ParameterType.INT | jspsych.ParameterType.FLOAT | jspsych.ParameterType.BOOL | jspsych.ParameterType.OBJECT
105
- }
106
- }
84
+ type: jspsych.ParameterType.OBJECT
107
85
  },
86
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
108
87
  rt: {
109
88
  type: jspsych.ParameterType.INT
110
89
  },
90
+ /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
111
91
  question_order: {
112
92
  type: jspsych.ParameterType.INT,
113
93
  array: true
114
94
  }
115
95
  }
116
96
  };
97
+ const plugin_id_name = "jspsych-survey-multi-choice";
117
98
  class SurveyMultiChoicePlugin {
118
99
  constructor(jsPsych) {
119
100
  this.jsPsych = jsPsych;
120
101
  }
121
- static info = info;
102
+ static {
103
+ this.info = info;
104
+ }
122
105
  trial(display_element, trial) {
123
- var plugin_id_name = "jspsych-survey-multi-choice";
106
+ const trial_form_id = `${plugin_id_name}_form`;
124
107
  var html = "";
125
- html += '<style id="jspsych-survey-multi-choice-css">';
126
- html += ".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-choice-text span.required {color: darkred;}.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}.jspsych-survey-multi-choice-option { line-height: 2; }.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}";
127
- html += "</style>";
108
+ html += `
109
+ <style id="${plugin_id_name}-css">
110
+ .${plugin_id_name}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }
111
+ .${plugin_id_name}-text span.required {color: darkred;}
112
+ .${plugin_id_name}-horizontal .${plugin_id_name}-text { text-align: center;}
113
+ .${plugin_id_name}-option { line-height: 2; }
114
+ .${plugin_id_name}-horizontal .${plugin_id_name}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}
115
+ label.${plugin_id_name}-text input[type='radio'] {margin-right: 1em;}
116
+ </style>`;
128
117
  if (trial.preamble !== null) {
129
- html += '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' + trial.preamble + "</div>";
118
+ html += `<div id="${plugin_id_name}-preamble" class="${plugin_id_name}-preamble">${trial.preamble}</div>`;
130
119
  }
131
120
  if (trial.autocomplete) {
132
- html += '<form id="jspsych-survey-multi-choice-form">';
121
+ html += `<form id="${trial_form_id}">`;
133
122
  } else {
134
- html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
123
+ html += `<form id="${trial_form_id}" autocomplete="off">`;
135
124
  }
136
125
  var question_order = [];
137
126
  for (var i = 0; i < trial.questions.length; i++) {
@@ -143,39 +132,42 @@ var jsPsychSurveyMultiChoice = (function (jspsych) {
143
132
  for (var i = 0; i < trial.questions.length; i++) {
144
133
  var question = trial.questions[question_order[i]];
145
134
  var question_id = question_order[i];
146
- var question_classes = ["jspsych-survey-multi-choice-question"];
135
+ var question_classes = [`${plugin_id_name}-question`];
147
136
  if (question.horizontal) {
148
- question_classes.push("jspsych-survey-multi-choice-horizontal");
137
+ question_classes.push(`${plugin_id_name}-horizontal`);
149
138
  }
150
- html += '<div id="jspsych-survey-multi-choice-' + question_id + '" class="' + question_classes.join(" ") + '" data-name="' + question.name + '">';
151
- html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
139
+ html += `<div id="${plugin_id_name}-${question_id}" class="${question_classes.join(" ")}" data-name="${question.name}">`;
140
+ html += `<p class="${plugin_id_name}-text survey-multi-choice">${question.prompt}`;
152
141
  if (question.required) {
153
142
  html += "<span class='required'>*</span>";
154
143
  }
155
144
  html += "</p>";
156
145
  for (var j = 0; j < question.options.length; j++) {
157
- var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
158
- var input_name = "jspsych-survey-multi-choice-response-" + question_id;
159
- var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
146
+ var option_id_name = `${plugin_id_name}-option-${question_id}-${j}`;
147
+ var input_name = `${plugin_id_name}-response-${question_id}`;
148
+ var input_id = `${plugin_id_name}-response-${question_id}-${j}`;
160
149
  var required_attr = question.required ? "required" : "";
161
- html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
162
- html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
163
- html += '<input type="radio" name="' + input_name + '" id="' + input_id + '" value="' + question.options[j] + '" ' + required_attr + "></input>";
164
- html += question.options[j] + "</label>";
165
- html += "</div>";
150
+ html += `
151
+ <div id="${option_id_name}" class="${plugin_id_name}-option">
152
+ <label class="${plugin_id_name}-text" for="${input_id}">
153
+ <input type="radio" name="${input_name}" id="${input_id}" value="${question.options[j]}" ${required_attr} />
154
+ ${question.options[j]}
155
+ </label>
156
+ </div>`;
166
157
  }
167
158
  html += "</div>";
168
159
  }
169
- html += '<input type="submit" id="' + plugin_id_name + '-next" class="' + plugin_id_name + ' jspsych-btn"' + (trial.button_label ? ' value="' + trial.button_label + '"' : "") + "></input>";
160
+ html += `<input type="submit" id="${plugin_id_name}-next" class="${plugin_id_name} jspsych-btn"${trial.button_label ? ' value="' + trial.button_label + '"' : ""} />`;
170
161
  html += "</form>";
171
162
  display_element.innerHTML = html;
172
- document.querySelector("form").addEventListener("submit", (event) => {
163
+ const trial_form = display_element.querySelector(`#${trial_form_id}`);
164
+ trial_form.addEventListener("submit", (event) => {
173
165
  event.preventDefault();
174
166
  var endTime = performance.now();
175
167
  var response_time = Math.round(endTime - startTime);
176
168
  var question_data = {};
177
169
  for (var i2 = 0; i2 < trial.questions.length; i2++) {
178
- var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i2);
170
+ var match = display_element.querySelector(`#${plugin_id_name}-${i2}`);
179
171
  var id = "Q" + i2;
180
172
  var val;
181
173
  if (match.querySelector("input[type=radio]:checked") !== null) {
@@ -239,7 +231,7 @@ var jsPsychSurveyMultiChoice = (function (jspsych) {
239
231
  for (let i = 0; i < answers.length; i++) {
240
232
  this.jsPsych.pluginAPI.clickTarget(
241
233
  display_element.querySelector(
242
- `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(
234
+ `#${plugin_id_name}-response-${i}-${trial.questions[i].options.indexOf(
243
235
  answers[i][1]
244
236
  )}`
245
237
  ),
@@ -247,7 +239,7 @@ var jsPsychSurveyMultiChoice = (function (jspsych) {
247
239
  );
248
240
  }
249
241
  this.jsPsych.pluginAPI.clickTarget(
250
- display_element.querySelector("#jspsych-survey-multi-choice-next"),
242
+ display_element.querySelector(`#${plugin_id_name}-next`),
251
243
  data.rt
252
244
  );
253
245
  }
@@ -256,4 +248,4 @@ var jsPsychSurveyMultiChoice = (function (jspsych) {
256
248
  return SurveyMultiChoicePlugin;
257
249
 
258
250
  })(jsPsychModule);
259
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.0/dist/index.browser.js.map
251
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.2/dist/index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["version","ParameterType","i"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIA,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,qBAAA;EAAA,WACNA,gBAAA;EAAA,EACA,UAAY,EAAA;EAA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Q,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;EAAA,OAC7C,CAAA;EAAA,KACF;EAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;EAAA,MACrB,eAAA,CAAgB,cAAc,mCAAmC,CAAA;EAAA,MACjE,IAAK,CAAA,EAAA;EAAA,KACP,CAAA;EAAA,GACF;EACF;;;;;;;;"}
1
+ {"version":3,"file":"index.browser.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-multi-choice\",\n \"version\": \"2.0.2\",\n \"description\": \"a jspsych plugin for multiple choice survey questions\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-multi-choice\"\n },\n \"author\": \"Shane Martin\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-multi-choice\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\nconst plugin_id_name = \"jspsych-survey-multi-choice\";\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) { }\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n\n const trial_form_id = `${plugin_id_name}_form`;\n\n var html = \"\";\n\n // inject CSS for trial\n html += `\n <style id=\"${plugin_id_name}-css\">\n .${plugin_id_name}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\n .${plugin_id_name}-text span.required {color: darkred;}\n .${plugin_id_name}-horizontal .${plugin_id_name}-text { text-align: center;}\n .${plugin_id_name}-option { line-height: 2; }\n .${plugin_id_name}-horizontal .${plugin_id_name}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\n label.${plugin_id_name}-text input[type='radio'] {margin-right: 1em;}\n </style>`;\n\n // show preamble text\n if (trial.preamble !== null) {\n html += `<div id=\"${plugin_id_name}-preamble\" class=\"${plugin_id_name}-preamble\">${trial.preamble}</div>`;\n }\n\n // form element\n if (trial.autocomplete) {\n html += `<form id=\"${trial_form_id}\">`;\n } else {\n html += `<form id=\"${trial_form_id}\" autocomplete=\"off\">`;\n }\n\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [`${plugin_id_name}-question`];\n if (question.horizontal) {\n question_classes.push(`${plugin_id_name}-horizontal`);\n }\n\n html += `<div id=\"${plugin_id_name}-${question_id}\" class=\"${question_classes.join(\" \")}\" data-name=\"${question.name}\">`;\n\n // add question text\n html += `<p class=\"${plugin_id_name}-text survey-multi-choice\">${question.prompt}`;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = `${plugin_id_name}-option-${question_id}-${j}`;\n var input_name = `${plugin_id_name}-response-${question_id}`;\n var input_id = `${plugin_id_name}-response-${question_id}-${j}`;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += `\n <div id=\"${option_id_name}\" class=\"${plugin_id_name}-option\">\n <label class=\"${plugin_id_name}-text\" for=\"${input_id}\">\n <input type=\"radio\" name=\"${input_name}\" id=\"${input_id}\" value=\"${question.options[j]}\" ${required_attr} />\n ${question.options[j]}\n </label>\n </div>`;\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html += `<input type=\"submit\" id=\"${plugin_id_name}-next\" class=\"${plugin_id_name} jspsych-btn\"${trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\"} />`;\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n const trial_form = display_element.querySelector<HTMLFormElement>(`#${trial_form_id}`);\n\n trial_form.addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(`#${plugin_id_name}-${i}`);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#${plugin_id_name}-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(`#${plugin_id_name}-next`),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["ParameterType","i"],"mappings":";;;EAEE,IAAW,OAAA,GAAA,OAAA;;ECEb,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,qBAAA;EAAA,EACN,OAAA;EAAA,EACA,UAAY,EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA,IAaV,SAAW,EAAA;EAAA,MACT,MAAMA,qBAAc,CAAA,OAAA;EAAA,MACpB,KAAO,EAAA,IAAA;EAAA,MACP,MAAQ,EAAA;EAAA;EAAA,QAEN,MAAQ,EAAA;EAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;EAAA,UACpB,OAAS,EAAA,KAAA,CAAA;EAAA,SACX;EAAA;EAAA,QAEA,OAAS,EAAA;EAAA,UACP,MAAMA,qBAAc,CAAA,MAAA;EAAA,UACpB,KAAO,EAAA,IAAA;EAAA,UACP,OAAS,EAAA,KAAA,CAAA;EAAA,SACX;EAAA;EAAA,QAEA,QAAU,EAAA;EAAA,UACR,MAAMA,qBAAc,CAAA,IAAA;EAAA,UACpB,OAAS,EAAA,KAAA;EAAA,SACX;EAAA;EA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,WACb,CAAA,CAAA;EAAA,SACH;EAAA,QAAA,CACE,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;EAAA,OAC7C,CAAA;EAAA,KACF;EAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;EAAA,MACrB,eAAgB,CAAA,aAAA,CAAc,CAAI,CAAA,EAAA,cAAc,CAAO,KAAA,CAAA,CAAA;EAAA,MACvD,IAAK,CAAA,EAAA;EAAA,KACP,CAAA;EAAA,GACF;EACF;;;;;;;;"}
@@ -1,2 +1,16 @@
1
- var jsPsychSurveyMultiChoice=function(i){"use strict";var j={name:"@jspsych/plugin-survey-multi-choice",version:"2.0.0",description:"a jspsych plugin for multiple choice survey questions",type:"module",main:"dist/index.cjs",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},typings:"dist/index.d.ts",unpkg:"dist/index.browser.min.js",files:["src","dist"],source:"src/index.ts",scripts:{test:"jest","test:watch":"npm test -- --watch",tsc:"tsc",build:"rollup --config","build:watch":"npm run build -- --watch"},repository:{type:"git",url:"git+https://github.com/jspsych/jsPsych.git",directory:"packages/plugin-survey-multi-choice"},author:"Shane Martin",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/survey-multi-choice",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}};const P={name:"survey-multi-choice",version:j.version,parameters:{questions:{type:i.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:i.ParameterType.HTML_STRING,default:void 0},options:{type:i.ParameterType.STRING,array:!0,default:void 0},required:{type:i.ParameterType.BOOL,default:!1},horizontal:{type:i.ParameterType.BOOL,default:!1},name:{type:i.ParameterType.STRING,default:""}}},randomize_question_order:{type:i.ParameterType.BOOL,default:!1},preamble:{type:i.ParameterType.HTML_STRING,default:null},button_label:{type:i.ParameterType.STRING,default:"Continue"},autocomplete:{type:i.ParameterType.BOOL,default:!1}},data:{response:{type:i.ParameterType.COMPLEX,nested:{identifier:{type:i.ParameterType.STRING},response:{type:i.ParameterType.STRING|i.ParameterType.INT|i.ParameterType.FLOAT|i.ParameterType.BOOL|i.ParameterType.OBJECT}}},rt:{type:i.ParameterType.INT},question_order:{type:i.ParameterType.INT,array:!0}}};class m{constructor(t){this.jsPsych=t}trial(t,r){var o="jspsych-survey-multi-choice",e="";e+='<style id="jspsych-survey-multi-choice-css">',e+=".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }.jspsych-survey-multi-choice-text span.required {color: darkred;}.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}.jspsych-survey-multi-choice-option { line-height: 2; }.jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}",e+="</style>",r.preamble!==null&&(e+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+r.preamble+"</div>"),r.autocomplete?e+='<form id="jspsych-survey-multi-choice-form">':e+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var n=[],a=0;a<r.questions.length;a++)n.push(a);r.randomize_question_order&&(n=this.jsPsych.randomization.shuffle(n));for(var a=0;a<r.questions.length;a++){var s=r.questions[n[a]],u=n[a],h=["jspsych-survey-multi-choice-question"];s.horizontal&&h.push("jspsych-survey-multi-choice-horizontal"),e+='<div id="jspsych-survey-multi-choice-'+u+'" class="'+h.join(" ")+'" data-name="'+s.name+'">',e+='<p class="jspsych-survey-multi-choice-text survey-multi-choice">'+s.prompt,s.required&&(e+="<span class='required'>*</span>"),e+="</p>";for(var c=0;c<s.options.length;c++){var T="jspsych-survey-multi-choice-option-"+u+"-"+c,q="jspsych-survey-multi-choice-response-"+u,d="jspsych-survey-multi-choice-response-"+u+"-"+c,b=s.required?"required":"";e+='<div id="'+T+'" class="jspsych-survey-multi-choice-option">',e+='<label class="jspsych-survey-multi-choice-text" for="'+d+'">',e+='<input type="radio" name="'+q+'" id="'+d+'" value="'+s.options[c]+'" '+b+"></input>",e+=s.options[c]+"</label>",e+="</div>"}e+="</div>"}e+='<input type="submit" id="'+o+'-next" class="'+o+' jspsych-btn"'+(r.button_label?' value="'+r.button_label+'"':"")+"></input>",e+="</form>",t.innerHTML=e,document.querySelector("form").addEventListener("submit",x=>{x.preventDefault();for(var O=performance.now(),S=Math.round(O-_),v={},l=0;l<r.questions.length;l++){var p=t.querySelector("#jspsych-survey-multi-choice-"+l),I="Q"+l,y;p.querySelector("input[type=radio]:checked")!==null?y=p.querySelector("input[type=radio]:checked").value:y="";var g={},f=I;p.attributes["data-name"].value!==""&&(f=p.attributes["data-name"].value),g[f]=y,Object.assign(v,g)}var z={rt:S,response:v,question_order:n};this.jsPsych.finishTrial(z)});var _=performance.now()}simulate(t,r,o,e){r=="data-only"&&(e(),this.simulate_data_only(t,o)),r=="visual"&&this.simulate_visual(t,o,e)}create_simulation_data(t,r){const o={};let e=1e3;for(const s of t.questions){const u=s.name?s.name:`Q${t.questions.indexOf(s)}`;o[u]=this.jsPsych.randomization.sampleWithoutReplacement(s.options,1)[0],e+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const n={response:o,rt:e,question_order:t.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(t.questions.length).keys()]):[...Array(t.questions.length).keys()]},a=this.jsPsych.pluginAPI.mergeSimulationData(n,r);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,a),a}simulate_data_only(t,r){const o=this.create_simulation_data(t,r);this.jsPsych.finishTrial(o)}simulate_visual(t,r,o){const e=this.create_simulation_data(t,r),n=this.jsPsych.getDisplayElement();this.trial(n,t),o();const a=Object.entries(e.response);for(let s=0;s<a.length;s++)this.jsPsych.pluginAPI.clickTarget(n.querySelector(`#jspsych-survey-multi-choice-response-${s}-${t.questions[s].options.indexOf(a[s][1])}`),(e.rt-1e3)/a.length*(s+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-next"),e.rt)}}return m.info=P,m}(jsPsychModule);
2
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.0/dist/index.browser.min.js.map
1
+ var jsPsychSurveyMultiChoice=function(o){"use strict";var q="2.0.2";const T={name:"survey-multi-choice",version:q,parameters:{questions:{type:o.ParameterType.COMPLEX,array:!0,nested:{prompt:{type:o.ParameterType.HTML_STRING,default:void 0},options:{type:o.ParameterType.STRING,array:!0,default:void 0},required:{type:o.ParameterType.BOOL,default:!1},horizontal:{type:o.ParameterType.BOOL,default:!1},name:{type:o.ParameterType.STRING,default:""}}},randomize_question_order:{type:o.ParameterType.BOOL,default:!1},preamble:{type:o.ParameterType.HTML_STRING,default:null},button_label:{type:o.ParameterType.STRING,default:"Continue"},autocomplete:{type:o.ParameterType.BOOL,default:!1}},data:{response:{type:o.ParameterType.OBJECT},rt:{type:o.ParameterType.INT},question_order:{type:o.ParameterType.INT,array:!0}}},e="jspsych-survey-multi-choice";class y{constructor(a){this.jsPsych=a}trial(a,i){const s=`${e}_form`;var t="";t+=`
2
+ <style id="${e}-css">
3
+ .${e}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }
4
+ .${e}-text span.required {color: darkred;}
5
+ .${e}-horizontal .${e}-text { text-align: center;}
6
+ .${e}-option { line-height: 2; }
7
+ .${e}-horizontal .${e}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}
8
+ label.${e}-text input[type='radio'] {margin-right: 1em;}
9
+ </style>`,i.preamble!==null&&(t+=`<div id="${e}-preamble" class="${e}-preamble">${i.preamble}</div>`),i.autocomplete?t+=`<form id="${s}">`:t+=`<form id="${s}" autocomplete="off">`;for(var l=[],n=0;n<i.questions.length;n++)l.push(n);i.randomize_question_order&&(l=this.jsPsych.randomization.shuffle(l));for(var n=0;n<i.questions.length;n++){var r=i.questions[l[n]],u=l[n],h=[`${e}-question`];r.horizontal&&h.push(`${e}-horizontal`),t+=`<div id="${e}-${u}" class="${h.join(" ")}" data-name="${r.name}">`,t+=`<p class="${e}-text survey-multi-choice">${r.prompt}`,r.required&&(t+="<span class='required'>*</span>"),t+="</p>";for(var m=0;m<r.options.length;m++){var g=`${e}-option-${u}-${m}`,_=`${e}-response-${u}`,$=`${e}-response-${u}-${m}`,b=r.required?"required":"";t+=`
10
+ <div id="${g}" class="${e}-option">
11
+ <label class="${e}-text" for="${$}">
12
+ <input type="radio" name="${_}" id="${$}" value="${r.options[m]}" ${b} />
13
+ ${r.options[m]}
14
+ </label>
15
+ </div>`}t+="</div>"}t+=`<input type="submit" id="${e}-next" class="${e} jspsych-btn"${i.button_label?' value="'+i.button_label+'"':""} />`,t+="</form>",a.innerHTML=t,a.querySelector(`#${s}`).addEventListener("submit",S=>{S.preventDefault();for(var x=performance.now(),z=Math.round(x-O),f={},p=0;p<i.questions.length;p++){var d=a.querySelector(`#${e}-${p}`),I="Q"+p,c;d.querySelector("input[type=radio]:checked")!==null?c=d.querySelector("input[type=radio]:checked").value:c="";var v={},P=I;d.attributes["data-name"].value!==""&&(P=d.attributes["data-name"].value),v[P]=c,Object.assign(f,v)}var L={rt:z,response:f,question_order:l};this.jsPsych.finishTrial(L)});var O=performance.now()}simulate(a,i,s,t){i=="data-only"&&(t(),this.simulate_data_only(a,s)),i=="visual"&&this.simulate_visual(a,s,t)}create_simulation_data(a,i){const s={};let t=1e3;for(const r of a.questions){const u=r.name?r.name:`Q${a.questions.indexOf(r)}`;s[u]=this.jsPsych.randomization.sampleWithoutReplacement(r.options,1)[0],t+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}const l={response:s,rt:t,question_order:a.randomize_question_order?this.jsPsych.randomization.shuffle([...Array(a.questions.length).keys()]):[...Array(a.questions.length).keys()]},n=this.jsPsych.pluginAPI.mergeSimulationData(l,i);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(a,n),n}simulate_data_only(a,i){const s=this.create_simulation_data(a,i);this.jsPsych.finishTrial(s)}simulate_visual(a,i,s){const t=this.create_simulation_data(a,i),l=this.jsPsych.getDisplayElement();this.trial(l,a),s();const n=Object.entries(t.response);for(let r=0;r<n.length;r++)this.jsPsych.pluginAPI.clickTarget(l.querySelector(`#${e}-response-${r}-${a.questions[r].options.indexOf(n[r][1])}`),(t.rt-1e3)/n.length*(r+1));this.jsPsych.pluginAPI.clickTarget(l.querySelector(`#${e}-next`),t.rt)}}return y.info=T,y}(jsPsychModule);
16
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@2.0.2/dist/index.browser.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["info","version","ParameterType","SurveyMultiChoicePlugin","jsPsych","display_element","trial","plugin_id_name","html","question_order","i","question","question_id","question_classes","j","option_id_name","input_name","input_id","required_attr","event","endTime","response_time","startTime","question_data","match","id","val","obje","name","trial_data","simulation_mode","simulation_options","load_callback","rt","q","default_data","data","answers"],"mappings":"q5BAIA,MAAMA,EAAc,CAClB,KAAM,sBACN,QAASC,UACT,WAAY,CAaV,UAAW,CACT,KAAMC,EAAc,cAAA,QACpB,MAAO,GACP,OAAQ,CAEN,OAAQ,CACN,KAAMA,EAAAA,cAAc,YACpB,QAAS,MACX,EAEA,QAAS,CACP,KAAMA,EAAAA,cAAc,OACpB,MAAO,GACP,QAAS,MACX,EAEA,SAAU,CACR,KAAMA,gBAAc,KACpB,QAAS,EACX,EAEA,WAAY,CACV,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,KAAM,CACJ,KAAMA,EAAAA,cAAc,OACpB,QAAS,EACX,CACF,CACF,EAKA,yBAA0B,CACxB,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,SAAU,CACR,KAAMA,EAAAA,cAAc,YACpB,QAAS,IACX,EAEA,aAAc,CACZ,KAAMA,EAAAA,cAAc,OACpB,QAAS,UACX,EAKA,aAAc,CACZ,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,CACF,EACA,KAAM,CAEJ,SAAU,CACR,KAAMA,EAAAA,cAAc,QACpB,OAAQ,CACN,WAAY,CACV,KAAMA,EAAAA,cAAc,MACtB,EACA,SAAU,C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Ac,mCAAmC,EACjE+B,EAAK,EACP,CACF,CACF,CAlOMjC,OAAAA,EACG,KAAOH"}
1
+ {"version":3,"file":"index.browser.min.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-multi-choice\",\n \"version\": \"2.0.2\",\n \"description\": \"a jspsych plugin for multiple choice survey questions\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-multi-choice\"\n },\n \"author\": \"Shane Martin\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-multi-choice\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\nconst plugin_id_name = \"jspsych-survey-multi-choice\";\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) { }\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n\n const trial_form_id = `${plugin_id_name}_form`;\n\n var html = \"\";\n\n // inject CSS for trial\n html += `\n <style id=\"${plugin_id_name}-css\">\n .${plugin_id_name}-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\n .${plugin_id_name}-text span.required {color: darkred;}\n .${plugin_id_name}-horizontal .${plugin_id_name}-text { text-align: center;}\n .${plugin_id_name}-option { line-height: 2; }\n .${plugin_id_name}-horizontal .${plugin_id_name}-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\n label.${plugin_id_name}-text input[type='radio'] {margin-right: 1em;}\n </style>`;\n\n // show preamble text\n if (trial.preamble !== null) {\n html += `<div id=\"${plugin_id_name}-preamble\" class=\"${plugin_id_name}-preamble\">${trial.preamble}</div>`;\n }\n\n // form element\n if (trial.autocomplete) {\n html += `<form id=\"${trial_form_id}\">`;\n } else {\n html += `<form id=\"${trial_form_id}\" autocomplete=\"off\">`;\n }\n\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [`${plugin_id_name}-question`];\n if (question.horizontal) {\n question_classes.push(`${plugin_id_name}-horizontal`);\n }\n\n html += `<div id=\"${plugin_id_name}-${question_id}\" class=\"${question_classes.join(\" \")}\" data-name=\"${question.name}\">`;\n\n // add question text\n html += `<p class=\"${plugin_id_name}-text survey-multi-choice\">${question.prompt}`;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = `${plugin_id_name}-option-${question_id}-${j}`;\n var input_name = `${plugin_id_name}-response-${question_id}`;\n var input_id = `${plugin_id_name}-response-${question_id}-${j}`;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += `\n <div id=\"${option_id_name}\" class=\"${plugin_id_name}-option\">\n <label class=\"${plugin_id_name}-text\" for=\"${input_id}\">\n <input type=\"radio\" name=\"${input_name}\" id=\"${input_id}\" value=\"${question.options[j]}\" ${required_attr} />\n ${question.options[j]}\n </label>\n </div>`;\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html += `<input type=\"submit\" id=\"${plugin_id_name}-next\" class=\"${plugin_id_name} jspsych-btn\"${trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\"} />`;\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n const trial_form = display_element.querySelector<HTMLFormElement>(`#${trial_form_id}`);\n\n trial_form.addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(`#${plugin_id_name}-${i}`);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#${plugin_id_name}-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(`#${plugin_id_name}-next`),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["version","info","ParameterType","plugin_id_name","SurveyMultiChoicePlugin","jsPsych","display_element","trial","trial_form_id","html","question_order","i","question","question_id","question_classes","j","option_id_name","input_name","input_id","required_attr","event","endTime","response_time","startTime","question_data","match","id","val","obje","name","trial_data","simulation_mode","simulation_options","load_callback","rt","q","default_data","data","answers"],"mappings":"sDAEEA,IAAAA,EAAW,QCEb,MAAMC,EAAc,CAClB,KAAM,sBACN,QAASD,EACT,WAAY,CAaV,UAAW,CACT,KAAME,EAAAA,cAAc,QACpB,MAAO,GACP,OAAQ,CAEN,OAAQ,CACN,KAAMA,gBAAc,YACpB,QAAS,MACX,EAEA,QAAS,CACP,KAAMA,EAAAA,cAAc,OACpB,MAAO,GACP,QAAS,MACX,EAEA,SAAU,CACR,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,WAAY,CACV,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,KAAM,CACJ,KAAMA,EAAAA,cAAc,OACpB,QAAS,EACX,CACF,CACF,EAKA,yBAA0B,CACxB,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,EAEA,SAAU,CACR,KAAMA,gBAAc,YACpB,QAAS,IACX,EAEA,aAAc,CACZ,KAAMA,EAAc,cAAA,OACpB,QAAS,UACX,EAKA,aAAc,CACZ,KAAMA,EAAAA,cAAc,KACpB,QAAS,EACX,CACF,EACA,KAAM,CAEJ,SAAU,CACR,KAAMA,EAAAA,c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