@jspsych/plugin-survey-likert 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,251 +1,251 @@
1
1
  var jsPsychSurveyLikert = (function (jspsych) {
2
2
  'use strict';
3
3
 
4
- const info = {
5
- name: "survey-likert",
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 likert labels to display for this question. */
20
- labels: {
21
- type: jspsych.ParameterType.STRING,
22
- array: true,
23
- pretty_name: "Labels",
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
- /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
33
- name: {
34
- type: jspsych.ParameterType.STRING,
35
- pretty_name: "Question Name",
36
- default: "",
37
- },
38
- },
39
- },
40
- /** If true, the order of the questions in the 'questions' array will be randomized. */
41
- randomize_question_order: {
42
- type: jspsych.ParameterType.BOOL,
43
- pretty_name: "Randomize Question Order",
44
- default: false,
45
- },
46
- /** HTML-formatted string to display at top of the page above all of the questions. */
47
- preamble: {
48
- type: jspsych.ParameterType.HTML_STRING,
49
- pretty_name: "Preamble",
50
- default: null,
51
- },
52
- /** Width of the likert scales in pixels. */
53
- scale_width: {
54
- type: jspsych.ParameterType.INT,
55
- pretty_name: "Scale width",
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-likert**
74
- *
75
- * jsPsych plugin for gathering responses to questions on a likert scale
76
- *
77
- * @author Josh de Leeuw
78
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}
79
- */
80
- class SurveyLikertPlugin {
81
- constructor(jsPsych) {
82
- this.jsPsych = jsPsych;
83
- }
84
- trial(display_element, trial) {
85
- if (trial.scale_width !== null) {
86
- var w = trial.scale_width + "px";
87
- }
88
- else {
89
- var w = "100%";
90
- }
91
- var html = "";
92
- // inject CSS for trial
93
- html += '<style id="jspsych-survey-likert-css">';
94
- html +=
95
- ".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }" +
96
- ".jspsych-survey-likert-opts { list-style:none; width:" +
97
- w +
98
- "; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }" +
99
- ".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }" +
100
- ".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }" +
101
- ".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }" +
102
- ".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }" +
103
- ".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }";
104
- html += "</style>";
105
- // show preamble text
106
- if (trial.preamble !== null) {
107
- html +=
108
- '<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">' +
109
- trial.preamble +
110
- "</div>";
111
- }
112
- if (trial.autocomplete) {
113
- html += '<form id="jspsych-survey-likert-form">';
114
- }
115
- else {
116
- html += '<form id="jspsych-survey-likert-form" autocomplete="off">';
117
- }
118
- // add likert scale questions ///
119
- // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
120
- // so that the data are always associated with the same question regardless of order
121
- var question_order = [];
122
- for (var i = 0; i < trial.questions.length; i++) {
123
- question_order.push(i);
124
- }
125
- if (trial.randomize_question_order) {
126
- question_order = this.jsPsych.randomization.shuffle(question_order);
127
- }
128
- for (var i = 0; i < trial.questions.length; i++) {
129
- var question = trial.questions[question_order[i]];
130
- // add question
131
- html += '<label class="jspsych-survey-likert-statement">' + question.prompt + "</label>";
132
- // add options
133
- var width = 100 / question.labels.length;
134
- var options_string = '<ul class="jspsych-survey-likert-opts" data-name="' +
135
- question.name +
136
- '" data-radio-group="Q' +
137
- question_order[i] +
138
- '">';
139
- for (var j = 0; j < question.labels.length; j++) {
140
- options_string +=
141
- '<li style="width:' +
142
- width +
143
- '%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q' +
144
- question_order[i] +
145
- '" value="' +
146
- j +
147
- '"';
148
- if (question.required) {
149
- options_string += " required";
150
- }
151
- options_string += ">" + question.labels[j] + "</label></li>";
152
- }
153
- options_string += "</ul>";
154
- html += options_string;
155
- }
156
- // add submit button
157
- html +=
158
- '<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="' +
159
- trial.button_label +
160
- '"></input>';
161
- html += "</form>";
162
- display_element.innerHTML = html;
163
- display_element.querySelector("#jspsych-survey-likert-form").addEventListener("submit", (e) => {
164
- e.preventDefault();
165
- // measure response time
166
- var endTime = performance.now();
167
- var response_time = Math.round(endTime - startTime);
168
- // create object to hold responses
169
- var question_data = {};
170
- var matches = display_element.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts");
171
- for (var index = 0; index < matches.length; index++) {
172
- var id = matches[index].dataset["radioGroup"];
173
- var el = display_element.querySelector('input[name="' + id + '"]:checked');
174
- if (el === null) {
175
- var response = "";
176
- }
177
- else {
178
- var response = parseInt(el.value);
179
- }
180
- var obje = {};
181
- if (matches[index].attributes["data-name"].value !== "") {
182
- var name = matches[index].attributes["data-name"].value;
183
- }
184
- else {
185
- var name = id;
186
- }
187
- obje[name] = response;
188
- Object.assign(question_data, obje);
189
- }
190
- // save data
191
- var trial_data = {
192
- rt: response_time,
193
- response: question_data,
194
- question_order: question_order,
195
- };
196
- display_element.innerHTML = "";
197
- // next trial
198
- this.jsPsych.finishTrial(trial_data);
199
- });
200
- var startTime = performance.now();
201
- }
202
- simulate(trial, simulation_mode, simulation_options, load_callback) {
203
- if (simulation_mode == "data-only") {
204
- load_callback();
205
- this.simulate_data_only(trial, simulation_options);
206
- }
207
- if (simulation_mode == "visual") {
208
- this.simulate_visual(trial, simulation_options, load_callback);
209
- }
210
- }
211
- create_simulation_data(trial, simulation_options) {
212
- const question_data = {};
213
- let rt = 1000;
214
- for (const q of trial.questions) {
215
- const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
216
- question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);
217
- rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
218
- }
219
- const default_data = {
220
- response: question_data,
221
- rt: rt,
222
- question_order: trial.randomize_question_order
223
- ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
224
- : [...Array(trial.questions.length).keys()],
225
- };
226
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
227
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
228
- return data;
229
- }
230
- simulate_data_only(trial, simulation_options) {
231
- const data = this.create_simulation_data(trial, simulation_options);
232
- this.jsPsych.finishTrial(data);
233
- }
234
- simulate_visual(trial, simulation_options, load_callback) {
235
- const data = this.create_simulation_data(trial, simulation_options);
236
- const display_element = this.jsPsych.getDisplayElement();
237
- this.trial(display_element, trial);
238
- load_callback();
239
- const answers = Object.entries(data.response);
240
- for (let i = 0; i < answers.length; i++) {
241
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`input[type="radio"][name="${answers[i][0]}"][value="${answers[i][1]}"]`), ((data.rt - 1000) / answers.length) * (i + 1));
242
- }
243
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-likert-next"), data.rt);
244
- }
245
- }
4
+ const info = {
5
+ name: "survey-likert",
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 likert labels to display for this question. */
20
+ labels: {
21
+ type: jspsych.ParameterType.STRING,
22
+ array: true,
23
+ pretty_name: "Labels",
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
+ /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
33
+ name: {
34
+ type: jspsych.ParameterType.STRING,
35
+ pretty_name: "Question Name",
36
+ default: "",
37
+ },
38
+ },
39
+ },
40
+ /** If true, the order of the questions in the 'questions' array will be randomized. */
41
+ randomize_question_order: {
42
+ type: jspsych.ParameterType.BOOL,
43
+ pretty_name: "Randomize Question Order",
44
+ default: false,
45
+ },
46
+ /** HTML-formatted string to display at top of the page above all of the questions. */
47
+ preamble: {
48
+ type: jspsych.ParameterType.HTML_STRING,
49
+ pretty_name: "Preamble",
50
+ default: null,
51
+ },
52
+ /** Width of the likert scales in pixels. */
53
+ scale_width: {
54
+ type: jspsych.ParameterType.INT,
55
+ pretty_name: "Scale width",
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-likert**
74
+ *
75
+ * jsPsych plugin for gathering responses to questions on a likert scale
76
+ *
77
+ * @author Josh de Leeuw
78
+ * @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}
79
+ */
80
+ class SurveyLikertPlugin {
81
+ constructor(jsPsych) {
82
+ this.jsPsych = jsPsych;
83
+ }
84
+ trial(display_element, trial) {
85
+ if (trial.scale_width !== null) {
86
+ var w = trial.scale_width + "px";
87
+ }
88
+ else {
89
+ var w = "100%";
90
+ }
91
+ var html = "";
92
+ // inject CSS for trial
93
+ html += '<style id="jspsych-survey-likert-css">';
94
+ html +=
95
+ ".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }" +
96
+ ".jspsych-survey-likert-opts { list-style:none; width:" +
97
+ w +
98
+ "; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }" +
99
+ ".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }" +
100
+ ".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }" +
101
+ ".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }" +
102
+ ".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }" +
103
+ ".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }";
104
+ html += "</style>";
105
+ // show preamble text
106
+ if (trial.preamble !== null) {
107
+ html +=
108
+ '<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">' +
109
+ trial.preamble +
110
+ "</div>";
111
+ }
112
+ if (trial.autocomplete) {
113
+ html += '<form id="jspsych-survey-likert-form">';
114
+ }
115
+ else {
116
+ html += '<form id="jspsych-survey-likert-form" autocomplete="off">';
117
+ }
118
+ // add likert scale questions ///
119
+ // generate question order. this is randomized here as opposed to randomizing the order of trial.questions
120
+ // so that the data are always associated with the same question regardless of order
121
+ var question_order = [];
122
+ for (var i = 0; i < trial.questions.length; i++) {
123
+ question_order.push(i);
124
+ }
125
+ if (trial.randomize_question_order) {
126
+ question_order = this.jsPsych.randomization.shuffle(question_order);
127
+ }
128
+ for (var i = 0; i < trial.questions.length; i++) {
129
+ var question = trial.questions[question_order[i]];
130
+ // add question
131
+ html += '<label class="jspsych-survey-likert-statement">' + question.prompt + "</label>";
132
+ // add options
133
+ var width = 100 / question.labels.length;
134
+ var options_string = '<ul class="jspsych-survey-likert-opts" data-name="' +
135
+ question.name +
136
+ '" data-radio-group="Q' +
137
+ question_order[i] +
138
+ '">';
139
+ for (var j = 0; j < question.labels.length; j++) {
140
+ options_string +=
141
+ '<li style="width:' +
142
+ width +
143
+ '%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q' +
144
+ question_order[i] +
145
+ '" value="' +
146
+ j +
147
+ '"';
148
+ if (question.required) {
149
+ options_string += " required";
150
+ }
151
+ options_string += ">" + question.labels[j] + "</label></li>";
152
+ }
153
+ options_string += "</ul>";
154
+ html += options_string;
155
+ }
156
+ // add submit button
157
+ html +=
158
+ '<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="' +
159
+ trial.button_label +
160
+ '"></input>';
161
+ html += "</form>";
162
+ display_element.innerHTML = html;
163
+ display_element.querySelector("#jspsych-survey-likert-form").addEventListener("submit", (e) => {
164
+ e.preventDefault();
165
+ // measure response time
166
+ var endTime = performance.now();
167
+ var response_time = Math.round(endTime - startTime);
168
+ // create object to hold responses
169
+ var question_data = {};
170
+ var matches = display_element.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts");
171
+ for (var index = 0; index < matches.length; index++) {
172
+ var id = matches[index].dataset["radioGroup"];
173
+ var el = display_element.querySelector('input[name="' + id + '"]:checked');
174
+ if (el === null) {
175
+ var response = "";
176
+ }
177
+ else {
178
+ var response = parseInt(el.value);
179
+ }
180
+ var obje = {};
181
+ if (matches[index].attributes["data-name"].value !== "") {
182
+ var name = matches[index].attributes["data-name"].value;
183
+ }
184
+ else {
185
+ var name = id;
186
+ }
187
+ obje[name] = response;
188
+ Object.assign(question_data, obje);
189
+ }
190
+ // save data
191
+ var trial_data = {
192
+ rt: response_time,
193
+ response: question_data,
194
+ question_order: question_order,
195
+ };
196
+ display_element.innerHTML = "";
197
+ // next trial
198
+ this.jsPsych.finishTrial(trial_data);
199
+ });
200
+ var startTime = performance.now();
201
+ }
202
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
203
+ if (simulation_mode == "data-only") {
204
+ load_callback();
205
+ this.simulate_data_only(trial, simulation_options);
206
+ }
207
+ if (simulation_mode == "visual") {
208
+ this.simulate_visual(trial, simulation_options, load_callback);
209
+ }
210
+ }
211
+ create_simulation_data(trial, simulation_options) {
212
+ const question_data = {};
213
+ let rt = 1000;
214
+ for (const q of trial.questions) {
215
+ const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;
216
+ question_data[name] = this.jsPsych.randomization.randomInt(0, q.labels.length - 1);
217
+ rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);
218
+ }
219
+ const default_data = {
220
+ response: question_data,
221
+ rt: rt,
222
+ question_order: trial.randomize_question_order
223
+ ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])
224
+ : [...Array(trial.questions.length).keys()],
225
+ };
226
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
227
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
228
+ return data;
229
+ }
230
+ simulate_data_only(trial, simulation_options) {
231
+ const data = this.create_simulation_data(trial, simulation_options);
232
+ this.jsPsych.finishTrial(data);
233
+ }
234
+ simulate_visual(trial, simulation_options, load_callback) {
235
+ const data = this.create_simulation_data(trial, simulation_options);
236
+ const display_element = this.jsPsych.getDisplayElement();
237
+ this.trial(display_element, trial);
238
+ load_callback();
239
+ const answers = Object.entries(data.response);
240
+ for (let i = 0; i < answers.length; i++) {
241
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(`input[type="radio"][name="${answers[i][0]}"][value="${answers[i][1]}"]`), ((data.rt - 1000) / answers.length) * (i + 1));
242
+ }
243
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("#jspsych-survey-likert-next"), data.rt);
244
+ }
245
+ }
246
246
  SurveyLikertPlugin.info = info;
247
247
 
248
248
  return SurveyLikertPlugin;
249
249
 
250
250
  })(jsPsychModule);
251
- //# sourceMappingURL=index.browser.js.map
251
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@1.1.3/dist/index.browser.js.map
@@ -1,2 +1,2 @@
1
- var jsPsychSurveyLikert=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}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)||a(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 a(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,a=new Array(t);r<t;r++)a[r]=e[r];return a}var i={name:"survey-likert",parameters:{questions:{type:e.ParameterType.COMPLEX,array:!0,pretty_name:"Questions",nested:{prompt:{type:e.ParameterType.HTML_STRING,pretty_name:"Prompt",default:void 0},labels:{type:e.ParameterType.STRING,array:!0,pretty_name:"Labels",default:void 0},required:{type:e.ParameterType.BOOL,pretty_name:"Required",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},scale_width:{type:e.ParameterType.INT,pretty_name:"Scale width",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}}},s=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,i,s;return n=e,(i=[{key:"trial",value:function(e,t){var r=this;if(null!==t.scale_width)var a=t.scale_width+"px";else a="100%";var n="";n+='<style id="jspsych-survey-likert-css">',n+=".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }.jspsych-survey-likert-opts { list-style:none; width:"+a+"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }.jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }.jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }.jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }.jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }.jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }",n+="</style>",null!==t.preamble&&(n+='<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">'+t.preamble+"</div>"),t.autocomplete?n+='<form id="jspsych-survey-likert-form">':n+='<form id="jspsych-survey-likert-form" autocomplete="off">';for(var i=[],s=0;s<t.questions.length;s++)i.push(s);for(t.randomize_question_order&&(i=this.jsPsych.randomization.shuffle(i)),s=0;s<t.questions.length;s++){var l=t.questions[i[s]];n+='<label class="jspsych-survey-likert-statement">'+l.prompt+"</label>";for(var o=100/l.labels.length,u='<ul class="jspsych-survey-likert-opts" data-name="'+l.name+'" data-radio-group="Q'+i[s]+'">',y=0;y<l.labels.length;y++)u+='<li style="width:'+o+'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q'+i[s]+'" value="'+y+'"',l.required&&(u+=" required"),u+=">"+l.labels[y]+"</label></li>";n+=u+="</ul>"}n+='<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="'+t.button_label+'"></input>',n+="</form>",e.innerHTML=n,e.querySelector("#jspsych-survey-likert-form").addEventListener("submit",(function(t){t.preventDefault();for(var a=performance.now(),n=Math.round(a-p),s={},l=e.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts"),o=0;o<l.length;o++){var u=l[o].dataset.radioGroup,y=e.querySelector('input[name="'+u+'"]:checked');if(null===y)var c="";else c=parseInt(y.value);var m={};if(""!==l[o].attributes["data-name"].value)var f=l[o].attributes["data-name"].value;else f=u;m[f]=c,Object.assign(s,m)}var h={rt:n,response:s,question_order:i};e.innerHTML="",r.jsPsych.finishTrial(h)}));var p=performance.now()}},{key:"simulate",value:function(e,t,r,a){"data-only"==t&&(a(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,a)}},{key:"create_simulation_data",value:function(e,t){var n,i={},s=1e3,l=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=a(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}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 s,l=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return l=e.done,e},e:function(e){o=!0,s=e},f:function(){try{l||null==r.return||r.return()}finally{if(o)throw s}}}}(e.questions);try{for(l.s();!(n=l.n()).done;){var o=n.value;i[o.name?o.name:"Q".concat(e.questions.indexOf(o))]=this.jsPsych.randomization.randomInt(0,o.labels.length-1),s+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){l.e(e)}finally{l.f()}var u={response:i,rt:s,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},y=this.jsPsych.pluginAPI.mergeSimulationData(u,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,y),y}},{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 a=this.create_simulation_data(e,t),n=this.jsPsych.getDisplayElement();this.trial(n,e),r();for(var i=Object.entries(a.response),s=0;s<i.length;s++)this.jsPsych.pluginAPI.clickTarget(n.querySelector('input[type="radio"][name="'.concat(i[s][0],'"][value="').concat(i[s][1],'"]')),(a.rt-1e3)/i.length*(s+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-likert-next"),a.rt)}}])&&t(n.prototype,i),s&&t(n,s),Object.defineProperty(n,"prototype",{writable:!1}),e}();return s.info=i,s}(jsPsychModule);
2
- //# sourceMappingURL=index.browser.min.js.map
1
+ var jsPsychSurveyLikert=function(e){"use strict";function t(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,(n=a.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(n,"string"))?i:String(i)),a)}var n,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)||a(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 a(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,a=new Array(t);r<t;r++)a[r]=e[r];return a}var i={name:"survey-likert",parameters:{questions:{type:e.ParameterType.COMPLEX,array:!0,pretty_name:"Questions",nested:{prompt:{type:e.ParameterType.HTML_STRING,pretty_name:"Prompt",default:void 0},labels:{type:e.ParameterType.STRING,array:!0,pretty_name:"Labels",default:void 0},required:{type:e.ParameterType.BOOL,pretty_name:"Required",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},scale_width:{type:e.ParameterType.INT,pretty_name:"Scale width",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}}},s=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,i,s;return n=e,(i=[{key:"trial",value:function(e,t){var r=this;if(null!==t.scale_width)var a=t.scale_width+"px";else a="100%";var n="";n+='<style id="jspsych-survey-likert-css">',n+=".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }.jspsych-survey-likert-opts { list-style:none; width:"+a+"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }.jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }.jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }.jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }.jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }.jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }",n+="</style>",null!==t.preamble&&(n+='<div id="jspsych-survey-likert-preamble" class="jspsych-survey-likert-preamble">'+t.preamble+"</div>"),t.autocomplete?n+='<form id="jspsych-survey-likert-form">':n+='<form id="jspsych-survey-likert-form" autocomplete="off">';for(var i=[],s=0;s<t.questions.length;s++)i.push(s);for(t.randomize_question_order&&(i=this.jsPsych.randomization.shuffle(i)),s=0;s<t.questions.length;s++){var l=t.questions[i[s]];n+='<label class="jspsych-survey-likert-statement">'+l.prompt+"</label>";for(var o=100/l.labels.length,u='<ul class="jspsych-survey-likert-opts" data-name="'+l.name+'" data-radio-group="Q'+i[s]+'">',y=0;y<l.labels.length;y++)u+='<li style="width:'+o+'%"><label class="jspsych-survey-likert-opt-label"><input type="radio" name="Q'+i[s]+'" value="'+y+'"',l.required&&(u+=" required"),u+=">"+l.labels[y]+"</label></li>";n+=u+="</ul>"}n+='<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="'+t.button_label+'"></input>',n+="</form>",e.innerHTML=n,e.querySelector("#jspsych-survey-likert-form").addEventListener("submit",(function(t){t.preventDefault();for(var a=performance.now(),n=Math.round(a-p),s={},l=e.querySelectorAll("#jspsych-survey-likert-form .jspsych-survey-likert-opts"),o=0;o<l.length;o++){var u=l[o].dataset.radioGroup,y=e.querySelector('input[name="'+u+'"]:checked');if(null===y)var c="";else c=parseInt(y.value);var m={};if(""!==l[o].attributes["data-name"].value)var f=l[o].attributes["data-name"].value;else f=u;m[f]=c,Object.assign(s,m)}var d={rt:n,response:s,question_order:i};e.innerHTML="",r.jsPsych.finishTrial(d)}));var p=performance.now()}},{key:"simulate",value:function(e,t,r,a){"data-only"==t&&(a(),this.simulate_data_only(e,r)),"visual"==t&&this.simulate_visual(e,r,a)}},{key:"create_simulation_data",value:function(e,t){var n,i={},s=1e3,l=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=a(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}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 s,l=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return l=e.done,e},e:function(e){o=!0,s=e},f:function(){try{l||null==r.return||r.return()}finally{if(o)throw s}}}}(e.questions);try{for(l.s();!(n=l.n()).done;){var o=n.value;i[o.name?o.name:"Q".concat(e.questions.indexOf(o))]=this.jsPsych.randomization.randomInt(0,o.labels.length-1),s+=this.jsPsych.randomization.sampleExGaussian(1500,400,.005,!0)}}catch(e){l.e(e)}finally{l.f()}var u={response:i,rt:s,question_order:e.randomize_question_order?this.jsPsych.randomization.shuffle(r(Array(e.questions.length).keys())):r(Array(e.questions.length).keys())},y=this.jsPsych.pluginAPI.mergeSimulationData(u,t);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(e,y),y}},{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 a=this.create_simulation_data(e,t),n=this.jsPsych.getDisplayElement();this.trial(n,e),r();for(var i=Object.entries(a.response),s=0;s<i.length;s++)this.jsPsych.pluginAPI.clickTarget(n.querySelector('input[type="radio"][name="'.concat(i[s][0],'"][value="').concat(i[s][1],'"]')),(a.rt-1e3)/i.length*(s+1));this.jsPsych.pluginAPI.clickTarget(n.querySelector("#jspsych-survey-likert-next"),a.rt)}}])&&t(n.prototype,i),s&&t(n,s),Object.defineProperty(n,"prototype",{writable:!1}),e}();return s.info=i,s}(jsPsychModule);
2
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-survey-likert@1.1.3/dist/index.browser.min.js.map