@jspsych/plugin-audio-slider-response 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/dist/index.cjs CHANGED
@@ -2,353 +2,353 @@
2
2
 
3
3
  var jspsych = require('jspsych');
4
4
 
5
- const info = {
6
- name: "audio-slider-response",
7
- parameters: {
8
- /** The audio file to be played. */
9
- stimulus: {
10
- type: jspsych.ParameterType.AUDIO,
11
- pretty_name: "Stimulus",
12
- default: undefined,
13
- },
14
- /** Sets the minimum value of the slider. */
15
- min: {
16
- type: jspsych.ParameterType.INT,
17
- pretty_name: "Min slider",
18
- default: 0,
19
- },
20
- /** Sets the maximum value of the slider */
21
- max: {
22
- type: jspsych.ParameterType.INT,
23
- pretty_name: "Max slider",
24
- default: 100,
25
- },
26
- /** Sets the starting value of the slider */
27
- slider_start: {
28
- type: jspsych.ParameterType.INT,
29
- pretty_name: "Slider starting value",
30
- default: 50,
31
- },
32
- /** Sets the step of the slider */
33
- step: {
34
- type: jspsych.ParameterType.INT,
35
- pretty_name: "Step",
36
- default: 1,
37
- },
38
- /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
39
- labels: {
40
- type: jspsych.ParameterType.HTML_STRING,
41
- pretty_name: "Labels",
42
- default: [],
43
- array: true,
44
- },
45
- /** Width of the slider in pixels. */
46
- slider_width: {
47
- type: jspsych.ParameterType.INT,
48
- pretty_name: "Slider width",
49
- default: null,
50
- },
51
- /** Label of the button to advance. */
52
- button_label: {
53
- type: jspsych.ParameterType.STRING,
54
- pretty_name: "Button label",
55
- default: "Continue",
56
- array: false,
57
- },
58
- /** If true, the participant will have to move the slider before continuing. */
59
- require_movement: {
60
- type: jspsych.ParameterType.BOOL,
61
- pretty_name: "Require movement",
62
- default: false,
63
- },
64
- /** Any content here will be displayed below the slider. */
65
- prompt: {
66
- type: jspsych.ParameterType.HTML_STRING,
67
- pretty_name: "Prompt",
68
- default: null,
69
- },
70
- /** How long to show the trial. */
71
- trial_duration: {
72
- type: jspsych.ParameterType.INT,
73
- pretty_name: "Trial duration",
74
- default: null,
75
- },
76
- /** If true, trial will end when user makes a response. */
77
- response_ends_trial: {
78
- type: jspsych.ParameterType.BOOL,
79
- pretty_name: "Response ends trial",
80
- default: true,
81
- },
82
- /** If true, then the trial will end as soon as the audio file finishes playing. */
83
- trial_ends_after_audio: {
84
- type: jspsych.ParameterType.BOOL,
85
- pretty_name: "Trial ends after audio",
86
- default: false,
87
- },
88
- /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
89
- response_allowed_while_playing: {
90
- type: jspsych.ParameterType.BOOL,
91
- pretty_name: "Response allowed while playing",
92
- default: true,
93
- },
94
- },
95
- };
96
- /**
97
- * **audio-slider-response**
98
- *
99
- * jsPsych plugin for playing audio and getting a slider response
100
- *
101
- * @author Josh de Leeuw
102
- * @see {@link https://www.jspsych.org/plugins/jspsych-audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
103
- */
104
- class AudioSliderResponsePlugin {
105
- constructor(jsPsych) {
106
- this.jsPsych = jsPsych;
107
- }
108
- trial(display_element, trial, on_load) {
109
- // hold the .resolve() function from the Promise that ends the trial
110
- let trial_complete;
111
- // half of the thumb width value from jspsych.css, used to adjust the label positions
112
- var half_thumb_width = 7.5;
113
- // setup stimulus
114
- var context = this.jsPsych.pluginAPI.audioContext();
115
- // record webaudio context start time
116
- var startTime;
117
- // for storing data related to response
118
- var response;
119
- // load audio file
120
- this.jsPsych.pluginAPI
121
- .getAudioBuffer(trial.stimulus)
122
- .then((buffer) => {
123
- if (context !== null) {
124
- this.audio = context.createBufferSource();
125
- this.audio.buffer = buffer;
126
- this.audio.connect(context.destination);
127
- }
128
- else {
129
- this.audio = buffer;
130
- this.audio.currentTime = 0;
131
- }
132
- setupTrial();
133
- })
134
- .catch((err) => {
135
- console.error(`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`);
136
- console.error(err);
137
- });
138
- const setupTrial = () => {
139
- // set up end event if trial needs it
140
- if (trial.trial_ends_after_audio) {
141
- this.audio.addEventListener("ended", end_trial);
142
- }
143
- // enable slider after audio ends if necessary
144
- if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {
145
- this.audio.addEventListener("ended", enable_slider);
146
- }
147
- var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
148
- html +=
149
- '<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
150
- if (trial.slider_width !== null) {
151
- html += trial.slider_width + "px;";
152
- }
153
- else {
154
- html += "auto;";
155
- }
156
- html += '">';
157
- html +=
158
- '<input type="range" class="jspsych-slider" value="' +
159
- trial.slider_start +
160
- '" min="' +
161
- trial.min +
162
- '" max="' +
163
- trial.max +
164
- '" step="' +
165
- trial.step +
166
- '" id="jspsych-audio-slider-response-response"';
167
- if (!trial.response_allowed_while_playing) {
168
- html += " disabled";
169
- }
170
- html += "></input><div>";
171
- for (var j = 0; j < trial.labels.length; j++) {
172
- var label_width_perc = 100 / (trial.labels.length - 1);
173
- var percent_of_range = j * (100 / (trial.labels.length - 1));
174
- var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
175
- var offset = (percent_dist_from_center * half_thumb_width) / 100;
176
- html +=
177
- '<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
178
- "left:calc(" +
179
- percent_of_range +
180
- "% - (" +
181
- label_width_perc +
182
- "% / 2) - " +
183
- offset +
184
- "px); text-align: center; width: " +
185
- label_width_perc +
186
- '%;">';
187
- html += '<span style="text-align: center; font-size: 80%;">' + trial.labels[j] + "</span>";
188
- html += "</div>";
189
- }
190
- html += "</div>";
191
- html += "</div>";
192
- html += "</div>";
193
- if (trial.prompt !== null) {
194
- html += trial.prompt;
195
- }
196
- // add submit button
197
- var next_disabled_attribute = "";
198
- if (trial.require_movement || !trial.response_allowed_while_playing) {
199
- next_disabled_attribute = "disabled";
200
- }
201
- html +=
202
- '<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' +
203
- next_disabled_attribute +
204
- ">" +
205
- trial.button_label +
206
- "</button>";
207
- display_element.innerHTML = html;
208
- response = {
209
- rt: null,
210
- response: null,
211
- };
212
- if (!trial.response_allowed_while_playing) {
213
- display_element.querySelector("#jspsych-audio-slider-response-response").disabled = true;
214
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
215
- }
216
- if (trial.require_movement) {
217
- const enable_button = () => {
218
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = false;
219
- };
220
- display_element
221
- .querySelector("#jspsych-audio-slider-response-response")
222
- .addEventListener("mousedown", enable_button);
223
- display_element
224
- .querySelector("#jspsych-audio-slider-response-response")
225
- .addEventListener("touchstart", enable_button);
226
- display_element
227
- .querySelector("#jspsych-audio-slider-response-response")
228
- .addEventListener("change", enable_button);
229
- }
230
- display_element
231
- .querySelector("#jspsych-audio-slider-response-next")
232
- .addEventListener("click", () => {
233
- // measure response time
234
- var endTime = performance.now();
235
- var rt = Math.round(endTime - startTime);
236
- if (context !== null) {
237
- endTime = context.currentTime;
238
- rt = Math.round((endTime - startTime) * 1000);
239
- }
240
- response.rt = rt;
241
- response.response = display_element.querySelector("#jspsych-audio-slider-response-response").valueAsNumber;
242
- if (trial.response_ends_trial) {
243
- end_trial();
244
- }
245
- else {
246
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
247
- }
248
- });
249
- startTime = performance.now();
250
- // start audio
251
- if (context !== null) {
252
- startTime = context.currentTime;
253
- this.audio.start(startTime);
254
- }
255
- else {
256
- this.audio.play();
257
- }
258
- // end trial if trial_duration is set
259
- if (trial.trial_duration !== null) {
260
- this.jsPsych.pluginAPI.setTimeout(() => {
261
- end_trial();
262
- }, trial.trial_duration);
263
- }
264
- on_load();
265
- };
266
- // function to enable slider after audio ends
267
- function enable_slider() {
268
- document.querySelector("#jspsych-audio-slider-response-response").disabled =
269
- false;
270
- if (!trial.require_movement) {
271
- document.querySelector("#jspsych-audio-slider-response-next").disabled =
272
- false;
273
- }
274
- }
275
- const end_trial = () => {
276
- // kill any remaining setTimeout handlers
277
- this.jsPsych.pluginAPI.clearAllTimeouts();
278
- // stop the audio file if it is playing
279
- // remove end event listeners if they exist
280
- if (context !== null) {
281
- this.audio.stop();
282
- }
283
- else {
284
- this.audio.pause();
285
- }
286
- this.audio.removeEventListener("ended", end_trial);
287
- this.audio.removeEventListener("ended", enable_slider);
288
- // save data
289
- var trialdata = {
290
- rt: response.rt,
291
- stimulus: trial.stimulus,
292
- slider_start: trial.slider_start,
293
- response: response.response,
294
- };
295
- display_element.innerHTML = "";
296
- // next trial
297
- this.jsPsych.finishTrial(trialdata);
298
- trial_complete();
299
- };
300
- return new Promise((resolve) => {
301
- trial_complete = resolve;
302
- });
303
- }
304
- simulate(trial, simulation_mode, simulation_options, load_callback) {
305
- if (simulation_mode == "data-only") {
306
- load_callback();
307
- this.simulate_data_only(trial, simulation_options);
308
- }
309
- if (simulation_mode == "visual") {
310
- this.simulate_visual(trial, simulation_options, load_callback);
311
- }
312
- }
313
- create_simulation_data(trial, simulation_options) {
314
- const default_data = {
315
- stimulus: trial.stimulus,
316
- slider_start: trial.slider_start,
317
- response: this.jsPsych.randomization.randomInt(trial.min, trial.max),
318
- rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
319
- };
320
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
321
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
322
- return data;
323
- }
324
- simulate_data_only(trial, simulation_options) {
325
- const data = this.create_simulation_data(trial, simulation_options);
326
- this.jsPsych.finishTrial(data);
327
- }
328
- simulate_visual(trial, simulation_options, load_callback) {
329
- const data = this.create_simulation_data(trial, simulation_options);
330
- const display_element = this.jsPsych.getDisplayElement();
331
- const respond = () => {
332
- if (data.rt !== null) {
333
- const el = display_element.querySelector("input[type='range']");
334
- setTimeout(() => {
335
- this.jsPsych.pluginAPI.clickTarget(el);
336
- el.valueAsNumber = data.response;
337
- }, data.rt / 2);
338
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("button"), data.rt);
339
- }
340
- };
341
- this.trial(display_element, trial, () => {
342
- load_callback();
343
- if (!trial.response_allowed_while_playing) {
344
- this.audio.addEventListener("ended", respond);
345
- }
346
- else {
347
- respond();
348
- }
349
- });
350
- }
351
- }
5
+ const info = {
6
+ name: "audio-slider-response",
7
+ parameters: {
8
+ /** The audio file to be played. */
9
+ stimulus: {
10
+ type: jspsych.ParameterType.AUDIO,
11
+ pretty_name: "Stimulus",
12
+ default: undefined,
13
+ },
14
+ /** Sets the minimum value of the slider. */
15
+ min: {
16
+ type: jspsych.ParameterType.INT,
17
+ pretty_name: "Min slider",
18
+ default: 0,
19
+ },
20
+ /** Sets the maximum value of the slider */
21
+ max: {
22
+ type: jspsych.ParameterType.INT,
23
+ pretty_name: "Max slider",
24
+ default: 100,
25
+ },
26
+ /** Sets the starting value of the slider */
27
+ slider_start: {
28
+ type: jspsych.ParameterType.INT,
29
+ pretty_name: "Slider starting value",
30
+ default: 50,
31
+ },
32
+ /** Sets the step of the slider */
33
+ step: {
34
+ type: jspsych.ParameterType.INT,
35
+ pretty_name: "Step",
36
+ default: 1,
37
+ },
38
+ /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
39
+ labels: {
40
+ type: jspsych.ParameterType.HTML_STRING,
41
+ pretty_name: "Labels",
42
+ default: [],
43
+ array: true,
44
+ },
45
+ /** Width of the slider in pixels. */
46
+ slider_width: {
47
+ type: jspsych.ParameterType.INT,
48
+ pretty_name: "Slider width",
49
+ default: null,
50
+ },
51
+ /** Label of the button to advance. */
52
+ button_label: {
53
+ type: jspsych.ParameterType.STRING,
54
+ pretty_name: "Button label",
55
+ default: "Continue",
56
+ array: false,
57
+ },
58
+ /** If true, the participant will have to move the slider before continuing. */
59
+ require_movement: {
60
+ type: jspsych.ParameterType.BOOL,
61
+ pretty_name: "Require movement",
62
+ default: false,
63
+ },
64
+ /** Any content here will be displayed below the slider. */
65
+ prompt: {
66
+ type: jspsych.ParameterType.HTML_STRING,
67
+ pretty_name: "Prompt",
68
+ default: null,
69
+ },
70
+ /** How long to show the trial. */
71
+ trial_duration: {
72
+ type: jspsych.ParameterType.INT,
73
+ pretty_name: "Trial duration",
74
+ default: null,
75
+ },
76
+ /** If true, trial will end when user makes a response. */
77
+ response_ends_trial: {
78
+ type: jspsych.ParameterType.BOOL,
79
+ pretty_name: "Response ends trial",
80
+ default: true,
81
+ },
82
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
83
+ trial_ends_after_audio: {
84
+ type: jspsych.ParameterType.BOOL,
85
+ pretty_name: "Trial ends after audio",
86
+ default: false,
87
+ },
88
+ /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
89
+ response_allowed_while_playing: {
90
+ type: jspsych.ParameterType.BOOL,
91
+ pretty_name: "Response allowed while playing",
92
+ default: true,
93
+ },
94
+ },
95
+ };
96
+ /**
97
+ * **audio-slider-response**
98
+ *
99
+ * jsPsych plugin for playing audio and getting a slider response
100
+ *
101
+ * @author Josh de Leeuw
102
+ * @see {@link https://www.jspsych.org/plugins/jspsych-audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
103
+ */
104
+ class AudioSliderResponsePlugin {
105
+ constructor(jsPsych) {
106
+ this.jsPsych = jsPsych;
107
+ }
108
+ trial(display_element, trial, on_load) {
109
+ // hold the .resolve() function from the Promise that ends the trial
110
+ let trial_complete;
111
+ // half of the thumb width value from jspsych.css, used to adjust the label positions
112
+ var half_thumb_width = 7.5;
113
+ // setup stimulus
114
+ var context = this.jsPsych.pluginAPI.audioContext();
115
+ // record webaudio context start time
116
+ var startTime;
117
+ // for storing data related to response
118
+ var response;
119
+ // load audio file
120
+ this.jsPsych.pluginAPI
121
+ .getAudioBuffer(trial.stimulus)
122
+ .then((buffer) => {
123
+ if (context !== null) {
124
+ this.audio = context.createBufferSource();
125
+ this.audio.buffer = buffer;
126
+ this.audio.connect(context.destination);
127
+ }
128
+ else {
129
+ this.audio = buffer;
130
+ this.audio.currentTime = 0;
131
+ }
132
+ setupTrial();
133
+ })
134
+ .catch((err) => {
135
+ console.error(`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`);
136
+ console.error(err);
137
+ });
138
+ const setupTrial = () => {
139
+ // set up end event if trial needs it
140
+ if (trial.trial_ends_after_audio) {
141
+ this.audio.addEventListener("ended", end_trial);
142
+ }
143
+ // enable slider after audio ends if necessary
144
+ if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {
145
+ this.audio.addEventListener("ended", enable_slider);
146
+ }
147
+ var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
148
+ html +=
149
+ '<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
150
+ if (trial.slider_width !== null) {
151
+ html += trial.slider_width + "px;";
152
+ }
153
+ else {
154
+ html += "auto;";
155
+ }
156
+ html += '">';
157
+ html +=
158
+ '<input type="range" class="jspsych-slider" value="' +
159
+ trial.slider_start +
160
+ '" min="' +
161
+ trial.min +
162
+ '" max="' +
163
+ trial.max +
164
+ '" step="' +
165
+ trial.step +
166
+ '" id="jspsych-audio-slider-response-response"';
167
+ if (!trial.response_allowed_while_playing) {
168
+ html += " disabled";
169
+ }
170
+ html += "></input><div>";
171
+ for (var j = 0; j < trial.labels.length; j++) {
172
+ var label_width_perc = 100 / (trial.labels.length - 1);
173
+ var percent_of_range = j * (100 / (trial.labels.length - 1));
174
+ var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
175
+ var offset = (percent_dist_from_center * half_thumb_width) / 100;
176
+ html +=
177
+ '<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
178
+ "left:calc(" +
179
+ percent_of_range +
180
+ "% - (" +
181
+ label_width_perc +
182
+ "% / 2) - " +
183
+ offset +
184
+ "px); text-align: center; width: " +
185
+ label_width_perc +
186
+ '%;">';
187
+ html += '<span style="text-align: center; font-size: 80%;">' + trial.labels[j] + "</span>";
188
+ html += "</div>";
189
+ }
190
+ html += "</div>";
191
+ html += "</div>";
192
+ html += "</div>";
193
+ if (trial.prompt !== null) {
194
+ html += trial.prompt;
195
+ }
196
+ // add submit button
197
+ var next_disabled_attribute = "";
198
+ if (trial.require_movement || !trial.response_allowed_while_playing) {
199
+ next_disabled_attribute = "disabled";
200
+ }
201
+ html +=
202
+ '<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' +
203
+ next_disabled_attribute +
204
+ ">" +
205
+ trial.button_label +
206
+ "</button>";
207
+ display_element.innerHTML = html;
208
+ response = {
209
+ rt: null,
210
+ response: null,
211
+ };
212
+ if (!trial.response_allowed_while_playing) {
213
+ display_element.querySelector("#jspsych-audio-slider-response-response").disabled = true;
214
+ display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
215
+ }
216
+ if (trial.require_movement) {
217
+ const enable_button = () => {
218
+ display_element.querySelector("#jspsych-audio-slider-response-next").disabled = false;
219
+ };
220
+ display_element
221
+ .querySelector("#jspsych-audio-slider-response-response")
222
+ .addEventListener("mousedown", enable_button);
223
+ display_element
224
+ .querySelector("#jspsych-audio-slider-response-response")
225
+ .addEventListener("touchstart", enable_button);
226
+ display_element
227
+ .querySelector("#jspsych-audio-slider-response-response")
228
+ .addEventListener("change", enable_button);
229
+ }
230
+ display_element
231
+ .querySelector("#jspsych-audio-slider-response-next")
232
+ .addEventListener("click", () => {
233
+ // measure response time
234
+ var endTime = performance.now();
235
+ var rt = Math.round(endTime - startTime);
236
+ if (context !== null) {
237
+ endTime = context.currentTime;
238
+ rt = Math.round((endTime - startTime) * 1000);
239
+ }
240
+ response.rt = rt;
241
+ response.response = display_element.querySelector("#jspsych-audio-slider-response-response").valueAsNumber;
242
+ if (trial.response_ends_trial) {
243
+ end_trial();
244
+ }
245
+ else {
246
+ display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
247
+ }
248
+ });
249
+ startTime = performance.now();
250
+ // start audio
251
+ if (context !== null) {
252
+ startTime = context.currentTime;
253
+ this.audio.start(startTime);
254
+ }
255
+ else {
256
+ this.audio.play();
257
+ }
258
+ // end trial if trial_duration is set
259
+ if (trial.trial_duration !== null) {
260
+ this.jsPsych.pluginAPI.setTimeout(() => {
261
+ end_trial();
262
+ }, trial.trial_duration);
263
+ }
264
+ on_load();
265
+ };
266
+ // function to enable slider after audio ends
267
+ function enable_slider() {
268
+ document.querySelector("#jspsych-audio-slider-response-response").disabled =
269
+ false;
270
+ if (!trial.require_movement) {
271
+ document.querySelector("#jspsych-audio-slider-response-next").disabled =
272
+ false;
273
+ }
274
+ }
275
+ const end_trial = () => {
276
+ // kill any remaining setTimeout handlers
277
+ this.jsPsych.pluginAPI.clearAllTimeouts();
278
+ // stop the audio file if it is playing
279
+ // remove end event listeners if they exist
280
+ if (context !== null) {
281
+ this.audio.stop();
282
+ }
283
+ else {
284
+ this.audio.pause();
285
+ }
286
+ this.audio.removeEventListener("ended", end_trial);
287
+ this.audio.removeEventListener("ended", enable_slider);
288
+ // save data
289
+ var trialdata = {
290
+ rt: response.rt,
291
+ stimulus: trial.stimulus,
292
+ slider_start: trial.slider_start,
293
+ response: response.response,
294
+ };
295
+ display_element.innerHTML = "";
296
+ // next trial
297
+ this.jsPsych.finishTrial(trialdata);
298
+ trial_complete();
299
+ };
300
+ return new Promise((resolve) => {
301
+ trial_complete = resolve;
302
+ });
303
+ }
304
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
305
+ if (simulation_mode == "data-only") {
306
+ load_callback();
307
+ this.simulate_data_only(trial, simulation_options);
308
+ }
309
+ if (simulation_mode == "visual") {
310
+ this.simulate_visual(trial, simulation_options, load_callback);
311
+ }
312
+ }
313
+ create_simulation_data(trial, simulation_options) {
314
+ const default_data = {
315
+ stimulus: trial.stimulus,
316
+ slider_start: trial.slider_start,
317
+ response: this.jsPsych.randomization.randomInt(trial.min, trial.max),
318
+ rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
319
+ };
320
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
321
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
322
+ return data;
323
+ }
324
+ simulate_data_only(trial, simulation_options) {
325
+ const data = this.create_simulation_data(trial, simulation_options);
326
+ this.jsPsych.finishTrial(data);
327
+ }
328
+ simulate_visual(trial, simulation_options, load_callback) {
329
+ const data = this.create_simulation_data(trial, simulation_options);
330
+ const display_element = this.jsPsych.getDisplayElement();
331
+ const respond = () => {
332
+ if (data.rt !== null) {
333
+ const el = display_element.querySelector("input[type='range']");
334
+ setTimeout(() => {
335
+ this.jsPsych.pluginAPI.clickTarget(el);
336
+ el.valueAsNumber = data.response;
337
+ }, data.rt / 2);
338
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("button"), data.rt);
339
+ }
340
+ };
341
+ this.trial(display_element, trial, () => {
342
+ load_callback();
343
+ if (!trial.response_allowed_while_playing) {
344
+ this.audio.addEventListener("ended", respond);
345
+ }
346
+ else {
347
+ respond();
348
+ }
349
+ });
350
+ }
351
+ }
352
352
  AudioSliderResponsePlugin.info = info;
353
353
 
354
354
  module.exports = AudioSliderResponsePlugin;