@jspsych/plugin-survey-multi-choice 1.1.2 → 1.1.3

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.
package/README.md CHANGED
@@ -27,9 +27,15 @@ See the [contributing to jsPsych](https://www.jspsych.org/latest/developers/cont
27
27
 
28
28
  ## Citation
29
29
 
30
- If you use this library in academic work, please cite the [paper that describes jsPsych](http://link.springer.com/article/10.3758%2Fs13428-014-0458-y):
30
+ If you use this library in academic work, the preferred citation is:
31
31
 
32
- de Leeuw, J.R. (2015). jsPsych: A JavaScript library for creating behavioral experiments in a Web browser. _Behavior Research Methods_, _47_(1), 1-12. doi:10.3758/s13428-014-0458-y
32
+ de Leeuw, J.R., Gilbert, R.A., & Luchterhandt, B. (2023). jsPsych: Enabling an open-source collaborative ecosystem of behavioral experiments. *Journal of Open Source Software*, *8*(85), 5351, [https://joss.theoj.org/papers/10.21105/joss.05351](https://joss.theoj.org/papers/10.21105/joss.05351).
33
+
34
+ This paper is an updated description of jsPsych and includes all current core team members. It replaces the earlier paper that described jsPsych:
35
+
36
+ de Leeuw, J.R. (2015). jsPsych: A JavaScript library for creating behavioral experiments in a Web browser. *Behavior Research Methods*, _47_(1), 1-12. doi:[10.3758/s13428-014-0458-y](http://link.springer.com/article/10.3758%2Fs13428-014-0458-y)
37
+
38
+ Citations help us demonstrate that this library is used and valued, which allows us to continue working on it.
33
39
 
34
40
  ## Contributors
35
41
 
@@ -1,267 +1,267 @@
1
1
  var jsPsychSurveyMultiChoice = (function (jspsych) {
2
2
  'use strict';
3
3
 
4
- const info = {
5
- name: "survey-multi-choice",
6
- parameters: {
7
- /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
8
- questions: {
9
- type: jspsych.ParameterType.COMPLEX,
10
- array: true,
11
- pretty_name: "Questions",
12
- nested: {
13
- /** Question prompt. */
14
- prompt: {
15
- type: jspsych.ParameterType.HTML_STRING,
16
- pretty_name: "Prompt",
17
- default: undefined,
18
- },
19
- /** Array of multiple choice options for this question. */
20
- options: {
21
- type: jspsych.ParameterType.STRING,
22
- pretty_name: "Options",
23
- array: true,
24
- default: undefined,
25
- },
26
- /** Whether or not a response to this question must be given in order to continue. */
27
- required: {
28
- type: jspsych.ParameterType.BOOL,
29
- pretty_name: "Required",
30
- default: false,
31
- },
32
- /** If true, then the question will be centered and options will be displayed horizontally. */
33
- horizontal: {
34
- type: jspsych.ParameterType.BOOL,
35
- pretty_name: "Horizontal",
36
- default: false,
37
- },
38
- /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
39
- name: {
40
- type: jspsych.ParameterType.STRING,
41
- pretty_name: "Question Name",
42
- default: "",
43
- },
44
- },
45
- },
46
- /** If true, the order of the questions in the 'questions' array will be randomized. */
47
- randomize_question_order: {
48
- type: jspsych.ParameterType.BOOL,
49
- pretty_name: "Randomize Question Order",
50
- default: false,
51
- },
52
- /** HTML-formatted string to display at top of the page above all of the questions. */
53
- preamble: {
54
- type: jspsych.ParameterType.HTML_STRING,
55
- pretty_name: "Preamble",
56
- default: null,
57
- },
58
- /** Label of the button to submit responses. */
59
- button_label: {
60
- type: jspsych.ParameterType.STRING,
61
- pretty_name: "Button label",
62
- default: "Continue",
63
- },
64
- /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
65
- autocomplete: {
66
- type: jspsych.ParameterType.BOOL,
67
- pretty_name: "Allow autocomplete",
68
- default: false,
69
- },
70
- },
71
- };
72
- /**
73
- * **survey-multi-choice**
74
- *
75
- * jsPsych plugin for presenting multiple choice survey questions
76
- *
77
- * @author Shane Martin
78
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
79
- */
80
- class SurveyMultiChoicePlugin {
81
- constructor(jsPsych) {
82
- this.jsPsych = jsPsych;
83
- }
84
- trial(display_element, trial) {
85
- var plugin_id_name = "jspsych-survey-multi-choice";
86
- var html = "";
87
- // inject CSS for trial
88
- html += '<style id="jspsych-survey-multi-choice-css">';
89
- html +=
90
- ".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }" +
91
- ".jspsych-survey-multi-choice-text span.required {color: darkred;}" +
92
- ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}" +
93
- ".jspsych-survey-multi-choice-option { line-height: 2; }" +
94
- ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}" +
95
- "label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}";
96
- html += "</style>";
97
- // show preamble text
98
- if (trial.preamble !== null) {
99
- html +=
100
- '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' +
101
- trial.preamble +
102
- "</div>";
103
- }
104
- // form element
105
- if (trial.autocomplete) {
106
- html += '<form id="jspsych-survey-multi-choice-form">';
107
- }
108
- else {
109
- html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
110
- }
111
- // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
112
- // so that the data are always associated with the same question regardless of order
113
- var question_order = [];
114
- for (var i = 0; i < trial.questions.length; i++) {
115
- question_order.push(i);
116
- }
117
- if (trial.randomize_question_order) {
118
- question_order = this.jsPsych.randomization.shuffle(question_order);
119
- }
120
- // add multiple-choice questions
121
- for (var i = 0; i < trial.questions.length; i++) {
122
- // get question based on question_order
123
- var question = trial.questions[question_order[i]];
124
- var question_id = question_order[i];
125
- // create question container
126
- var question_classes = ["jspsych-survey-multi-choice-question"];
127
- if (question.horizontal) {
128
- question_classes.push("jspsych-survey-multi-choice-horizontal");
129
- }
130
- html +=
131
- '<div id="jspsych-survey-multi-choice-' +
132
- question_id +
133
- '" class="' +
134
- question_classes.join(" ") +
135
- '" data-name="' +
136
- question.name +
137
- '">';
138
- // add question text
139
- html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
140
- if (question.required) {
141
- html += "<span class='required'>*</span>";
142
- }
143
- html += "</p>";
144
- // create option radio buttons
145
- for (var j = 0; j < question.options.length; j++) {
146
- // add label and question text
147
- var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
148
- var input_name = "jspsych-survey-multi-choice-response-" + question_id;
149
- var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
150
- var required_attr = question.required ? "required" : "";
151
- // add radio button container
152
- html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
153
- html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
154
- html +=
155
- '<input type="radio" name="' +
156
- input_name +
157
- '" id="' +
158
- input_id +
159
- '" value="' +
160
- question.options[j] +
161
- '" ' +
162
- required_attr +
163
- "></input>";
164
- html += question.options[j] + "</label>";
165
- html += "</div>";
166
- }
167
- html += "</div>";
168
- }
169
- // add submit button
170
- html +=
171
- '<input type="submit" id="' +
172
- plugin_id_name +
173
- '-next" class="' +
174
- plugin_id_name +
175
- ' jspsych-btn"' +
176
- (trial.button_label ? ' value="' + trial.button_label + '"' : "") +
177
- "></input>";
178
- html += "</form>";
179
- // render
180
- display_element.innerHTML = html;
181
- document.querySelector("form").addEventListener("submit", (event) => {
182
- event.preventDefault();
183
- // measure response time
184
- var endTime = performance.now();
185
- var response_time = Math.round(endTime - startTime);
186
- // create object to hold responses
187
- var question_data = {};
188
- for (var i = 0; i < trial.questions.length; i++) {
189
- var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i);
190
- var id = "Q" + i;
191
- var val;
192
- if (match.querySelector("input[type=radio]:checked") !== null) {
193
- val = match.querySelector("input[type=radio]:checked").value;
194
- }
195
- else {
196
- val = "";
197
- }
198
- var obje = {};
199
- var name = id;
200
- if (match.attributes["data-name"].value !== "") {
201
- name = match.attributes["data-name"].value;
202
- }
203
- obje[name] = val;
204
- Object.assign(question_data, obje);
205
- }
206
- // save data
207
- var trial_data = {
208
- rt: response_time,
209
- response: question_data,
210
- question_order: question_order,
211
- };
212
- display_element.innerHTML = "";
213
- // next trial
214
- this.jsPsych.finishTrial(trial_data);
215
- });
216
- var startTime = performance.now();
217
- }
218
- simulate(trial, simulation_mode, simulation_options, load_callback) {
219
- if (simulation_mode == "data-only") {
220
- load_callback();
221
- this.simulate_data_only(trial, simulation_options);
222
- }
223
- if (simulation_mode == "visual") {
224
- this.simulate_visual(trial, simulation_options, load_callback);
225
- }
226
- }
227
- create_simulation_data(trial, simulation_options) {
228
- const question_data = {};
229
- let rt = 1000;
230
- for (const q of trial.questions) {
231
- const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
232
- question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];
233
- rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
234
- }
235
- const default_data = {
236
- response: question_data,
237
- rt: rt,
238
- question_order: trial.randomize_question_order
239
- ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
240
- : [...Array(trial.questions.length).keys()],
241
- };
242
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
243
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
244
- return data;
245
- }
246
- simulate_data_only(trial, simulation_options) {
247
- const data = this.create_simulation_data(trial, simulation_options);
248
- this.jsPsych.finishTrial(data);
249
- }
250
- simulate_visual(trial, simulation_options, load_callback) {
251
- const data = this.create_simulation_data(trial, simulation_options);
252
- const display_element = this.jsPsych.getDisplayElement();
253
- this.trial(display_element, trial);
254
- load_callback();
255
- const answers = Object.entries(data.response);
256
- for (let i = 0; i < answers.length; i++) {
257
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(answers[i][1])}`), ((data.rt - 1000) / answers.length) * (i + 1));
258
- }
259
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-multi-choice-next"), data.rt);
260
- }
261
- }
4
+ const info = {
5
+ name: "survey-multi-choice",
6
+ parameters: {
7
+ /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
8
+ questions: {
9
+ type: jspsych.ParameterType.COMPLEX,
10
+ array: true,
11
+ pretty_name: "Questions",
12
+ nested: {
13
+ /** Question prompt. */
14
+ prompt: {
15
+ type: jspsych.ParameterType.HTML_STRING,
16
+ pretty_name: "Prompt",
17
+ default: undefined,
18
+ },
19
+ /** Array of multiple choice options for this question. */
20
+ options: {
21
+ type: jspsych.ParameterType.STRING,
22
+ pretty_name: "Options",
23
+ array: true,
24
+ default: undefined,
25
+ },
26
+ /** Whether or not a response to this question must be given in order to continue. */
27
+ required: {
28
+ type: jspsych.ParameterType.BOOL,
29
+ pretty_name: "Required",
30
+ default: false,
31
+ },
32
+ /** If true, then the question will be centered and options will be displayed horizontally. */
33
+ horizontal: {
34
+ type: jspsych.ParameterType.BOOL,
35
+ pretty_name: "Horizontal",
36
+ default: false,
37
+ },
38
+ /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
39
+ name: {
40
+ type: jspsych.ParameterType.STRING,
41
+ pretty_name: "Question Name",
42
+ default: "",
43
+ },
44
+ },
45
+ },
46
+ /** If true, the order of the questions in the 'questions' array will be randomized. */
47
+ randomize_question_order: {
48
+ type: jspsych.ParameterType.BOOL,
49
+ pretty_name: "Randomize Question Order",
50
+ default: false,
51
+ },
52
+ /** HTML-formatted string to display at top of the page above all of the questions. */
53
+ preamble: {
54
+ type: jspsych.ParameterType.HTML_STRING,
55
+ pretty_name: "Preamble",
56
+ default: null,
57
+ },
58
+ /** Label of the button to submit responses. */
59
+ button_label: {
60
+ type: jspsych.ParameterType.STRING,
61
+ pretty_name: "Button label",
62
+ default: "Continue",
63
+ },
64
+ /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
65
+ autocomplete: {
66
+ type: jspsych.ParameterType.BOOL,
67
+ pretty_name: "Allow autocomplete",
68
+ default: false,
69
+ },
70
+ },
71
+ };
72
+ /**
73
+ * **survey-multi-choice**
74
+ *
75
+ * jsPsych plugin for presenting multiple choice survey questions
76
+ *
77
+ * @author Shane Martin
78
+ * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
79
+ */
80
+ class SurveyMultiChoicePlugin {
81
+ constructor(jsPsych) {
82
+ this.jsPsych = jsPsych;
83
+ }
84
+ trial(display_element, trial) {
85
+ var plugin_id_name = "jspsych-survey-multi-choice";
86
+ var html = "";
87
+ // inject CSS for trial
88
+ html += '<style id="jspsych-survey-multi-choice-css">';
89
+ html +=
90
+ ".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }" +
91
+ ".jspsych-survey-multi-choice-text span.required {color: darkred;}" +
92
+ ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}" +
93
+ ".jspsych-survey-multi-choice-option { line-height: 2; }" +
94
+ ".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}" +
95
+ "label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}";
96
+ html += "</style>";
97
+ // show preamble text
98
+ if (trial.preamble !== null) {
99
+ html +=
100
+ '<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">' +
101
+ trial.preamble +
102
+ "</div>";
103
+ }
104
+ // form element
105
+ if (trial.autocomplete) {
106
+ html += '<form id="jspsych-survey-multi-choice-form">';
107
+ }
108
+ else {
109
+ html += '<form id="jspsych-survey-multi-choice-form" autocomplete="off">';
110
+ }
111
+ // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
112
+ // so that the data are always associated with the same question regardless of order
113
+ var question_order = [];
114
+ for (var i = 0; i < trial.questions.length; i++) {
115
+ question_order.push(i);
116
+ }
117
+ if (trial.randomize_question_order) {
118
+ question_order = this.jsPsych.randomization.shuffle(question_order);
119
+ }
120
+ // add multiple-choice questions
121
+ for (var i = 0; i < trial.questions.length; i++) {
122
+ // get question based on question_order
123
+ var question = trial.questions[question_order[i]];
124
+ var question_id = question_order[i];
125
+ // create question container
126
+ var question_classes = ["jspsych-survey-multi-choice-question"];
127
+ if (question.horizontal) {
128
+ question_classes.push("jspsych-survey-multi-choice-horizontal");
129
+ }
130
+ html +=
131
+ '<div id="jspsych-survey-multi-choice-' +
132
+ question_id +
133
+ '" class="' +
134
+ question_classes.join(" ") +
135
+ '" data-name="' +
136
+ question.name +
137
+ '">';
138
+ // add question text
139
+ html += '<p class="jspsych-survey-multi-choice-text survey-multi-choice">' + question.prompt;
140
+ if (question.required) {
141
+ html += "<span class='required'>*</span>";
142
+ }
143
+ html += "</p>";
144
+ // create option radio buttons
145
+ for (var j = 0; j < question.options.length; j++) {
146
+ // add label and question text
147
+ var option_id_name = "jspsych-survey-multi-choice-option-" + question_id + "-" + j;
148
+ var input_name = "jspsych-survey-multi-choice-response-" + question_id;
149
+ var input_id = "jspsych-survey-multi-choice-response-" + question_id + "-" + j;
150
+ var required_attr = question.required ? "required" : "";
151
+ // add radio button container
152
+ html += '<div id="' + option_id_name + '" class="jspsych-survey-multi-choice-option">';
153
+ html += '<label class="jspsych-survey-multi-choice-text" for="' + input_id + '">';
154
+ html +=
155
+ '<input type="radio" name="' +
156
+ input_name +
157
+ '" id="' +
158
+ input_id +
159
+ '" value="' +
160
+ question.options[j] +
161
+ '" ' +
162
+ required_attr +
163
+ "></input>";
164
+ html += question.options[j] + "</label>";
165
+ html += "</div>";
166
+ }
167
+ html += "</div>";
168
+ }
169
+ // add submit button
170
+ html +=
171
+ '<input type="submit" id="' +
172
+ plugin_id_name +
173
+ '-next" class="' +
174
+ plugin_id_name +
175
+ ' jspsych-btn"' +
176
+ (trial.button_label ? ' value="' + trial.button_label + '"' : "") +
177
+ "></input>";
178
+ html += "</form>";
179
+ // render
180
+ display_element.innerHTML = html;
181
+ document.querySelector("form").addEventListener("submit", (event) => {
182
+ event.preventDefault();
183
+ // measure response time
184
+ var endTime = performance.now();
185
+ var response_time = Math.round(endTime - startTime);
186
+ // create object to hold responses
187
+ var question_data = {};
188
+ for (var i = 0; i < trial.questions.length; i++) {
189
+ var match = display_element.querySelector("#jspsych-survey-multi-choice-" + i);
190
+ var id = "Q" + i;
191
+ var val;
192
+ if (match.querySelector("input[type=radio]:checked") !== null) {
193
+ val = match.querySelector("input[type=radio]:checked").value;
194
+ }
195
+ else {
196
+ val = "";
197
+ }
198
+ var obje = {};
199
+ var name = id;
200
+ if (match.attributes["data-name"].value !== "") {
201
+ name = match.attributes["data-name"].value;
202
+ }
203
+ obje[name] = val;
204
+ Object.assign(question_data, obje);
205
+ }
206
+ // save data
207
+ var trial_data = {
208
+ rt: response_time,
209
+ response: question_data,
210
+ question_order: question_order,
211
+ };
212
+ display_element.innerHTML = "";
213
+ // next trial
214
+ this.jsPsych.finishTrial(trial_data);
215
+ });
216
+ var startTime = performance.now();
217
+ }
218
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
219
+ if (simulation_mode == "data-only") {
220
+ load_callback();
221
+ this.simulate_data_only(trial, simulation_options);
222
+ }
223
+ if (simulation_mode == "visual") {
224
+ this.simulate_visual(trial, simulation_options, load_callback);
225
+ }
226
+ }
227
+ create_simulation_data(trial, simulation_options) {
228
+ const question_data = {};
229
+ let rt = 1000;
230
+ for (const q of trial.questions) {
231
+ const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
232
+ question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];
233
+ rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
234
+ }
235
+ const default_data = {
236
+ response: question_data,
237
+ rt: rt,
238
+ question_order: trial.randomize_question_order
239
+ ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
240
+ : [...Array(trial.questions.length).keys()],
241
+ };
242
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
243
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
244
+ return data;
245
+ }
246
+ simulate_data_only(trial, simulation_options) {
247
+ const data = this.create_simulation_data(trial, simulation_options);
248
+ this.jsPsych.finishTrial(data);
249
+ }
250
+ simulate_visual(trial, simulation_options, load_callback) {
251
+ const data = this.create_simulation_data(trial, simulation_options);
252
+ const display_element = this.jsPsych.getDisplayElement();
253
+ this.trial(display_element, trial);
254
+ load_callback();
255
+ const answers = Object.entries(data.response);
256
+ for (let i = 0; i < answers.length; i++) {
257
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(answers[i][1])}`), ((data.rt - 1000) / answers.length) * (i + 1));
258
+ }
259
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-multi-choice-next"), data.rt);
260
+ }
261
+ }
262
262
  SurveyMultiChoicePlugin.info = info;
263
263
 
264
264
  return SurveyMultiChoicePlugin;
265
265
 
266
266
  })(jsPsychModule);
267
- //# sourceMappingURL=index.browser.js.map
267
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@1.1.3/dist/index.browser.js.map
@@ -1,2 +1,2 @@
1
- var jsPsychSurveyMultiChoice=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function r(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||i(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}var a={name:"survey-multi-choice",parameters:{questions:{type:e.ParameterType.COMPLEX,array:!0,pretty_name:"Questions",nested:{prompt:{type:e.ParameterType.HTML_STRING,pretty_name:"Prompt",default:void 0},options:{type:e.ParameterType.STRING,pretty_name:"Options",array:!0,default:void 0},required:{type:e.ParameterType.BOOL,pretty_name:"Required",default:!1},horizontal:{type:e.ParameterType.BOOL,pretty_name:"Horizontal",default:!1},name:{type:e.ParameterType.STRING,pretty_name:"Question Name",default:""}}},randomize_question_order:{type:e.ParameterType.BOOL,pretty_name:"Randomize Question Order",default:!1},preamble:{type:e.ParameterType.HTML_STRING,pretty_name:"Preamble",default:null},button_label:{type:e.ParameterType.STRING,pretty_name:"Button label",default:"Continue"},autocomplete:{type:e.ParameterType.BOOL,pretty_name:"Allow autocomplete",default:!1}}},o=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.jsPsych=t}var n,a,o;return n=e,(a=[{key:"trial",value:function(e,t){var r=this,i="jspsych-survey-multi-choice",n="";n+='<style id="jspsych-survey-multi-choice-css">',n+=".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;}",n+="</style>",null!==t.preamble&&(n+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+t.preamble+"</div>"),t.autocomplete?n+='<form id="jspsych-survey-multi-choice-form">':n+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var a=[],o=0;o<t.questions.length;o++)a.push(o);for(t.randomize_question_order&&(a=this.jsPsych.randomization.shuffle(a)),o=0;o<t.questions.length;o++){var s=t.questions[a[o]],u=a[o],l=["jspsych-survey-multi-choice-question"];s.horizontal&&l.push("jspsych-survey-multi-choice-horizontal"),n+='<div id="jspsych-survey-multi-choice-'+u+'" class="'+l.join(" ")+'" data-name="'+s.name+'">',n+='<p class="jspsych-survey-multi-choice-text survey-multi-choice">'+s.prompt,s.required&&(n+="<span class='required'>*</span>"),n+="</p>";for(var c=0;c<s.options.length;c++){var y="jspsych-survey-multi-choice-option-"+u+"-"+c,p="jspsych-survey-multi-choice-response-"+u,m="jspsych-survey-multi-choice-response-"+u+"-"+c,h=s.required?"required":"";n+='<div id="'+y+'" class="jspsych-survey-multi-choice-option">',n+='<label class="jspsych-survey-multi-choice-text" for="'+m+'">',n+='<input type="radio" name="'+p+'" id="'+m+'" value="'+s.options[c]+'" '+h+"></input>",n+=s.options[c]+"</label>",n+="</div>"}n+="</div>"}n+='<input type="submit" id="'+i+'-next" class="'+i+' jspsych-btn"'+(t.button_label?' value="'+t.button_label+'"':"")+"></input>",n+="</form>",e.innerHTML=n,document.querySelector("form").addEventListener("submit",(function(i){i.preventDefault();for(var n=performance.now(),o=Math.round(n-d),s={},u=0;u<t.questions.length;u++){var l,c=e.querySelector("#jspsych-survey-multi-choice-"+u),y="Q"+u;l=null!==c.querySelector("input[type=radio]:checked")?c.querySelector("input[type=radio]:checked").value:"";var p={},m=y;""!==c.attributes["data-name"].value&&(m=c.attributes["data-name"].value),p[m]=l,Object.assign(s,p)}var h={rt:o,response:s,question_order:a};e.innerHTML="",r.jsPsych.finishTrial(h)}));var d=performance.now()}},{key:"simulate",value:function(e,t,r,i){"data-only"==t&&(i(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,i)}},{key:"create_simulation_data",value:function(e,t){var n,a={},o=1e3,s=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=i(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){u=!0,o=e},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw o}}}}(e.questions);try{for(s.s();!(n=s.n()).done;){var u=n.value;a[u.name?u.name:"Q".concat(e.questions.indexOf(u))]=this.jsPsych.randomization.sampleWithoutReplacement(u.options,1)[0],o+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){s.e(e)}finally{s.f()}var l={response:a,rt:o,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},c=this.jsPsych.pluginAPI.mergeSimulationData(l,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,c),c}},{key:"simulate_data_only",value:function(e,t){var r=this.create_simulation_data(e,t);this.jsPsych.finishTrial(r)}},{key:"simulate_visual",value:function(e,t,r){var i=this.create_simulation_data(e,t),n=this.jsPsych.getDisplayElement();this.trial(n,e),r();for(var a=Object.entries(i.response),o=0;o<a.length;o++)this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-response-".concat(o,"-").concat(e.questions[o].options.indexOf(a[o][1]))),(i.rt-1e3)/a.length*(o+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-next"),i.rt)}}])&&t(n.prototype,a),o&&t(n,o),Object.defineProperty(n,"prototype",{writable:!1}),e}();return o.info=a,o}(jsPsychModule);
2
- //# sourceMappingURL=index.browser.min.js.map
1
+ var jsPsychSurveyMultiChoice=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(n=i.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(n,"string"))?o:String(o)),i)}var n,o}function r(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||i(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,i=new Array(t);r<t;r++)i[r]=e[r];return i}var o={name:"survey-multi-choice",parameters:{questions:{type:e.ParameterType.COMPLEX,array:!0,pretty_name:"Questions",nested:{prompt:{type:e.ParameterType.HTML_STRING,pretty_name:"Prompt",default:void 0},options:{type:e.ParameterType.STRING,pretty_name:"Options",array:!0,default:void 0},required:{type:e.ParameterType.BOOL,pretty_name:"Required",default:!1},horizontal:{type:e.ParameterType.BOOL,pretty_name:"Horizontal",default:!1},name:{type:e.ParameterType.STRING,pretty_name:"Question Name",default:""}}},randomize_question_order:{type:e.ParameterType.BOOL,pretty_name:"Randomize Question Order",default:!1},preamble:{type:e.ParameterType.HTML_STRING,pretty_name:"Preamble",default:null},button_label:{type:e.ParameterType.STRING,pretty_name:"Button label",default:"Continue"},autocomplete:{type:e.ParameterType.BOOL,pretty_name:"Allow autocomplete",default:!1}}},a=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.jsPsych=t}var n,o,a;return n=e,(o=[{key:"trial",value:function(e,t){var r=this,i="jspsych-survey-multi-choice",n="";n+='<style id="jspsych-survey-multi-choice-css">',n+=".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;}",n+="</style>",null!==t.preamble&&(n+='<div id="jspsych-survey-multi-choice-preamble" class="jspsych-survey-multi-choice-preamble">'+t.preamble+"</div>"),t.autocomplete?n+='<form id="jspsych-survey-multi-choice-form">':n+='<form id="jspsych-survey-multi-choice-form" autocomplete="off">';for(var o=[],a=0;a<t.questions.length;a++)o.push(a);for(t.randomize_question_order&&(o=this.jsPsych.randomization.shuffle(o)),a=0;a<t.questions.length;a++){var s=t.questions[o[a]],u=o[a],l=["jspsych-survey-multi-choice-question"];s.horizontal&&l.push("jspsych-survey-multi-choice-horizontal"),n+='<div id="jspsych-survey-multi-choice-'+u+'" class="'+l.join(" ")+'" data-name="'+s.name+'">',n+='<p class="jspsych-survey-multi-choice-text survey-multi-choice">'+s.prompt,s.required&&(n+="<span class='required'>*</span>"),n+="</p>";for(var c=0;c<s.options.length;c++){var y="jspsych-survey-multi-choice-option-"+u+"-"+c,p="jspsych-survey-multi-choice-response-"+u,m="jspsych-survey-multi-choice-response-"+u+"-"+c,h=s.required?"required":"";n+='<div id="'+y+'" class="jspsych-survey-multi-choice-option">',n+='<label class="jspsych-survey-multi-choice-text" for="'+m+'">',n+='<input type="radio" name="'+p+'" id="'+m+'" value="'+s.options[c]+'" '+h+"></input>",n+=s.options[c]+"</label>",n+="</div>"}n+="</div>"}n+='<input type="submit" id="'+i+'-next" class="'+i+' jspsych-btn"'+(t.button_label?' value="'+t.button_label+'"':"")+"></input>",n+="</form>",e.innerHTML=n,document.querySelector("form").addEventListener("submit",(function(i){i.preventDefault();for(var n=performance.now(),a=Math.round(n-f),s={},u=0;u<t.questions.length;u++){var l,c=e.querySelector("#jspsych-survey-multi-choice-"+u),y="Q"+u;l=null!==c.querySelector("input[type=radio]:checked")?c.querySelector("input[type=radio]:checked").value:"";var p={},m=y;""!==c.attributes["data-name"].value&&(m=c.attributes["data-name"].value),p[m]=l,Object.assign(s,p)}var h={rt:a,response:s,question_order:o};e.innerHTML="",r.jsPsych.finishTrial(h)}));var f=performance.now()}},{key:"simulate",value:function(e,t,r,i){"data-only"==t&&(i(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,i)}},{key:"create_simulation_data",value:function(e,t){var n,o={},a=1e3,s=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=i(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){u=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw a}}}}(e.questions);try{for(s.s();!(n=s.n()).done;){var u=n.value;o[u.name?u.name:"Q".concat(e.questions.indexOf(u))]=this.jsPsych.randomization.sampleWithoutReplacement(u.options,1)[0],a+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){s.e(e)}finally{s.f()}var l={response:o,rt:a,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},c=this.jsPsych.pluginAPI.mergeSimulationData(l,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,c),c}},{key:"simulate_data_only",value:function(e,t){var r=this.create_simulation_data(e,t);this.jsPsych.finishTrial(r)}},{key:"simulate_visual",value:function(e,t,r){var i=this.create_simulation_data(e,t),n=this.jsPsych.getDisplayElement();this.trial(n,e),r();for(var o=Object.entries(i.response),a=0;a<o.length;a++)this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-response-".concat(a,"-").concat(e.questions[a].options.indexOf(o[a][1]))),(i.rt-1e3)/o.length*(a+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-multi-choice-next"),i.rt)}}])&&t(n.prototype,o),a&&t(n,a),Object.defineProperty(n,"prototype",{writable:!1}),e}();return a.info=o,a}(jsPsychModule);
2
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-multi-choice@1.1.3/dist/index.browser.min.js.map