Skip to content

Commit d13767c

Browse files
committed
fix video-*-response plugins to have properly typed default values
1 parent 7003c67 commit d13767c

File tree

9 files changed

+47
-41
lines changed

9 files changed

+47
-41
lines changed

.changeset/blue-carrots-relate.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@jspsych/plugin-video-keyboard-response": patch
3+
"@jspsych/plugin-video-button-response": patch
4+
"@jspsych/plugin-video-slider-response": patch
5+
---
6+
7+
`width` and `height` default parameters are set to `null` as opposed to an empty string to properly reflect their types

docs/plugins/video-button-response.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Parameter | Type | Default Value | Description
1515
stimulus | array | *undefined* | An array of file paths to the video. You can specify multiple formats of the same video (e.g., .mp4, .ogg, .webm) to maximize the [cross-browser compatibility](https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats). Usually .mp4 is a safe cross-browser option. The plugin does not reliably support .mov files. The player will use the first source file in the array that is compatible with the browser, so specify the files in order of preference.
1616
choices | array of strings | *undefined* | Labels for the buttons. Each different string in the array will generate a different button.
1717
button_html | function | ``(choice: string, choice_index: number)=>`<button class="jspsych-btn">${choice}</button>``; | A function that generates the HTML for each button in the `choices` array. The function gets the string and index of the item in the `choices` array and should return valid HTML. If you want to use different markup for each button, you can do that by using a conditional on either parameter. The default parameter returns a button element with the text label of the choice.
18-
button_layout | string | 'grid' | Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
18+
button_layout | string | `'grid'` | Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
1919
grid_rows | number | 1 | The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the number of rows will be determined automatically based on the number of buttons and the number of columns.
2020
grid_columns | number | null | The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the number of columns will be determined automatically based on the number of buttons and the number of rows.
2121
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
22-
width | numeric | width of the video file | The width of the video display in pixels.
23-
height | numeric | heigh of the video file | The height of the video display in pixels.
22+
width | numeric | width of the video file | The width of the video display in pixels. If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the height is also specified.
23+
height | numeric | heigh of the video file | The height of the video display in pixels. If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the width is also specified.
2424
autoplay | boolean | true | If true, the video will begin playing as soon as it has loaded.
2525
controls | boolean | false | If true, controls for the video player will be available to the participant. They will be able to pause the video or move the playback to any point in the video.
2626
start | numeric | null | If given a value, the video will start at this time point in seconds.

docs/plugins/video-keyboard-response.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
1414
| ------------------------------ | ---------------- | ----------------------- | ---------------------------------------- |
1515
| stimulus | array | *undefined* | An array of file paths to the video. You can specify multiple formats of the same video (e.g., .mp4, .ogg, .webm) to maximize the [cross-browser compatibility](https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats). Usually .mp4 is a safe cross-browser option. The plugin does not reliably support .mov files. The player will use the first source file in the array that is compatible with the browser, so specify the files in order of preference. |
1616
| prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). |
17-
| width | numeric | width of the video file | The width of the video display in pixels. |
18-
| height | numeric | heigh of the video file | The height of the video display in pixels. |
17+
| width | numeric | width of the video file | The width of the video display in pixels. If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the height is also specified. |
18+
| height | numeric | heigh of the video file | The height of the video display in pixels.If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the width is also specified. |
1919
| autoplay | boolean | true | If true, the video will begin playing as soon as it has loaded. |
2020
| controls | boolean | false | If true, controls for the video player will be available to the participant. They will be able to pause the video or move the playback to any point in the video. |
2121
| start | numeric | null | If given a value, the video will start at this time point in seconds. |

docs/plugins/video-slider-response.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Parameter | Type | Default Value | Description
1414
----------|------|---------------|------------
1515
stimulus | array | *undefined* | An array of file paths to the video. You can specify multiple formats of the same video (e.g., .mp4, .ogg, .webm) to maximize the [cross-browser compatibility](https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats). Usually .mp4 is a safe cross-browser option. The plugin does not reliably support .mov files. The player will use the first source file in the array that is compatible with the browser, so specify the files in order of preference.
1616
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
17-
width | numeric | width of the video file | The width of the video display in pixels.
18-
height | numeric | heigh of the video file | The height of the video display in pixels.
17+
width | numeric | width of the video file | The width of the video display in pixels. If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the height is also specified.
18+
height | numeric | height of the video file | The height of the video display in pixels. If `null`, the video will take the original video's dimensions, or properly scaled with the aspect ratio if the width is also specified.
1919
autoplay | boolean | true | If true, the video will begin playing as soon as it has loaded.
2020
controls | boolean | false | If true, controls for the video player will be available to the participant. They will be able to pause the video or move the playback to any point in the video.
2121
start | numeric | null | If given a value, the video will start at this time point in seconds.
22-
stop| numeric | null | If given a value, the video will stop at this time point in seconds.
22+
stop | numeric | null | If given a value, the video will stop at this time point in seconds.
2323
rate | numeric | null | The playback rate of the video. 1 is normal, <1 is slower, >1 is faster.
2424
min | integer | 0 | Sets the minimum value of the slider.
2525
max | integer | 100 | Sets the maximum value of the slider.
26-
slider_start | integer | 50 | Sets the starting value of the slider
26+
slider_start | integer | 50 | Sets the starting value of the slider.
2727
step | integer | 1 | Sets the step of the slider. This is the smallest amount by which the slider can change.
2828
labels | array of strings | [] | Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the other two will be at 33% and 67% of the slider width.
2929
slider_width | integer | null | Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display.

examples/jspsych-video-button-response.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
var trial_1 = {
3434
type: jsPsychVideoButtonResponse,
3535
stimulus: ['video/sample_video.mp4'],
36-
choices: ['Y','N'],
36+
choices: ['Y', 'N'],
3737
margin_vertical: '10px',
3838
margin_horizontal: '8px',
3939
prompt: 'Press Y or N',
@@ -51,7 +51,7 @@
5151
var trial_2 = {
5252
type: jsPsychVideoButtonResponse,
5353
stimulus: ['video/sample_video.mp4'],
54-
choices: ['😄','😁','🥱','😣','🤯'],
54+
choices: ['😄', '😁', '🥱', '😣', '🤯'],
5555
button_html: function (choice) {
5656
return '<span style="font-size:40px;">' + choice + '</span>';
5757
},
@@ -68,7 +68,9 @@
6868
type: jsPsychVideoButtonResponse,
6969
stimulus: ['video/sample_video.mp4'],
7070
choices: ['😄','😁','🥱','😣','🤯'],
71-
button_html: '<div style="font-size:40px;">%choice%</div>',
71+
button_html: function (choice) {
72+
return '<span style="font-size:40px;">' + choice + '</span>';
73+
},
7274
margin_vertical: '10px',
7375
margin_horizontal: '8px',
7476
prompt: '<p>Click the emoji that best represents your reaction to the video</p><p>Click a button to end the trial.</p><p>Response buttons are disabled for the first 2 seconds of playing.</p>',

examples/jspsych-video-keyboard-response.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
var trial_1 = {
3434
type: jsPsychVideoKeyboardResponse,
3535
stimulus: ['video/sample_video.mp4'],
36-
choices: ['y','n'],
36+
choices: ['y', 'n'],
3737
prompt: 'Press y or n.',
3838
width: 600,
3939
//height: 600,

packages/plugin-video-button-response/src/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ const info = <const>{
4545
type: ParameterType.HTML_STRING,
4646
default: null,
4747
},
48-
/** The width of the video display in pixels. */
48+
/** The width of the video display in pixels. If `null`, the video will take the original video's dimensions,
49+
* or properly scaled with the aspect ratio if the height is also specified.
50+
*/
4951
width: {
5052
type: ParameterType.INT,
51-
default: "",
53+
default: null,
5254
},
53-
/** The height of the video display in pixels. */
55+
/** The height of the video display in pixels. If `null`, the video will take the original video's dimensions,
56+
* or properly scaled with the aspect ratio if the width is also specified.
57+
*/
5458
height: {
5559
type: ParameterType.INT,
56-
default: "",
60+
default: null,
5761
},
5862
/** If true, the video will begin playing as soon as it has loaded. */
5963
autoplay: {
@@ -68,12 +72,12 @@ const info = <const>{
6872
type: ParameterType.BOOL,
6973
default: false,
7074
},
71-
/** Time to start the clip. If null (default), video will start at the beginning of the file. */
75+
/** Time to start the clip. If `null` (default), video will start at the beginning of the file. */
7276
start: {
7377
type: ParameterType.FLOAT,
7478
default: null,
7579
},
76-
/** Time to stop the clip. If null (default), video will stop at the end of the file. */
80+
/** Time to stop the clip. If `null` (default), video will stop at the end of the file. */
7781
stop: {
7882
type: ParameterType.FLOAT,
7983
default: null,

packages/plugin-video-keyboard-response/src/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ const info = <const>{
2525
pretty_name: "Prompt",
2626
default: null,
2727
},
28-
/** The width of the video in pixels. */
28+
/** The width of the video display in pixels. If `null`, the video will take the original video's dimensions,
29+
* or properly scaled with the aspect ratio if the height is also specified.
30+
*/
2931
width: {
3032
type: ParameterType.INT,
3133
pretty_name: "Width",
3234
default: "",
3335
},
34-
/** The height of the video display in pixels. */
36+
/** The height of the video display in pixels. If `null`, the video will take the original video's dimensions,
37+
* or properly scaled with the aspect ratio if the width is also specified.
38+
*/
3539
height: {
3640
type: ParameterType.INT,
3741
pretty_name: "Height",
@@ -99,7 +103,7 @@ const info = <const>{
99103
},
100104
/** The response time in milliseconds for the participant to make a response. The time is measured from when the
101105
* stimulus first appears on the screen until the participant's response.
102-
* */
106+
*/
103107
rt: {
104108
type: ParameterType.INT,
105109
},
@@ -137,14 +141,6 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
137141
constructor(private jsPsych: JsPsych) {}
138142

139143
trial(display_element: HTMLElement, trial: TrialType<Info>) {
140-
// catch mistake where stimuli are not an array
141-
if (!Array.isArray(trial.stimulus)) {
142-
throw new Error(`
143-
The stimulus property for the video-keyboard-response plugin must be an array
144-
of files. See https://www.jspsych.org/latest/plugins/video-keyboard-response/#parameters
145-
`);
146-
}
147-
148144
// setup stimulus
149145
var video_html = "<div>";
150146
video_html += '<video id="jspsych-video-keyboard-response-stimulus"';

packages/plugin-video-slider-response/src/index.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ const info = <const>{
2323
type: ParameterType.HTML_STRING,
2424
default: null,
2525
},
26-
/** The width of the video in pixels. */
26+
/** The width of the video display in pixels. If `null`, the video will take the original video's dimensions,
27+
* or properly scaled with the aspect ratio if the height is also specified.
28+
*/
2729
width: {
2830
type: ParameterType.INT,
29-
default: "",
31+
default: null,
3032
},
31-
/** The height of the video display in pixels. */
33+
/** The height of the video display in pixels. If `null`, the video will take the original video's dimensions,
34+
* or properly scaled with the aspect ratio if the width is also specified.
35+
*/
3236
height: {
3337
type: ParameterType.INT,
34-
default: "",
38+
default: null,
3539
},
3640
/** If true, the video will begin playing as soon as it has loaded. */
3741
autoplay: {
@@ -191,13 +195,6 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
191195
constructor(private jsPsych: JsPsych) {}
192196

193197
trial(display_element: HTMLElement, trial: TrialType<Info>) {
194-
if (!Array.isArray(trial.stimulus)) {
195-
throw new Error(`
196-
The stimulus property for the video-slider-response plugin must be an array
197-
of files. See https://www.jspsych.org/latest/plugins/video-slider-response/#parameters
198-
`);
199-
}
200-
201198
// half of the thumb width value from jspsych.css, used to adjust the label positions
202199
var half_thumb_width = 7.5;
203200

0 commit comments

Comments
 (0)