Skip to content

Commit f87d104

Browse files
authored
Merge pull request #3440 from jspsych/update-docs
v8 doc revision + expanding tutorials and `ParameterType` docs
2 parents 9e60268 + a738531 commit f87d104

20 files changed

+231
-208
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can learn more about setting up a project by following the [hello world tuto
2525

2626
Once you've got a project set up, the [reaction time task tutorial](https://www.jspsych.org/latest/tutorials/rt-task/) is a great next step, since it covers many core topics and features.
2727

28-
There are also a number of [video tutorials](https://www.jspsych.org/latest/tutorials/video-tutorials) available on the website.
28+
There are also a number of [community tutorials](https://www.jspsych.org/latest/tutorials/community-tutorials) available on the website.
2929

3030
## Examples
3131

contributors.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ The following people have contributed to the development of jsPsych by writing c
33
* Antonia - https://github.com/Ahoidal
44
* aucuparia - https://github.com/aucuparia
55
* Xiaolu Bai - https://github.com/lbai001
6+
* Niranjan Baskaran - https://github.com/Bankminer78
7+
* brchristian - https://github.com/brchristian
68
* bjoluc - https://github.com/bjoluc
79
* Christian Brickhouse - https://github.com/chrisbrickhouse
810
* Teon L Brooks - https://github.com/teonbrooks
11+
* Susan Buck - https://github.com/susanBuck
912
* Eamon Caddigan - https://github.com/eamoncaddigan
1013
* Jason Carpenter
14+
* Cherrie Chang - https://github.com/cherriechang
1115
* Steve Chao - https://github.com/stchao
1216
* Zhanwen "Phil" Chen - https://github.com/zhanwenchen
1317
* cthorey - https://github.com/cthorey
@@ -20,15 +24,17 @@ The following people have contributed to the development of jsPsych by writing c
2024
* Becky Gilbert - https://github.com/becky-gilbert
2125
* Mark Gorenstein - https://github.com/mgorenstein
2226
* Rui Han - https://github.com/hrcn
27+
* Eitan Hemed - https://github.com/EitanHemed
2328
* Andy Heusser - https://github.com/andrewheusser
2429
* Angus Hughes - https://github.com/awhug
25-
* jadeddelta - https://github.com/jadeddelta
30+
* jade - https://github.com/jadeddelta
2631
* Gustavo Juantorena - https://github.com/GEJ1
2732
* Chris Jungerius - https://github.com/cjungerius
2833
* George Kachergis - https://github.com/kachergis
2934
* Yul Kang - https://github.com/yulkang
3035
* Spencer King - https://github.com/spencerking
3136
* Jana Klaus - https://github.com/janakl4us
37+
* Ethan Knights - https://github.com/ethanknights
3238
* Arnold Kochari - https://github.com/akochari
3339
* Peter Jes Kohler - https://github.com/pjkohler
3440
* kupiqu - https://github.com/kupiqu
@@ -38,6 +44,7 @@ The following people have contributed to the development of jsPsych by writing c
3844
* madebyafox - https://github.com/madebyafox
3945
* Shane Martin - https://github.com/shamrt
4046
* Vijay Marupudi - https://github.com/vijaymarupudi
47+
* Cian Monnin - https://github.com/CMonnin
4148
* Adrian Oesch - https://github.com/adrianoesch
4249
* Benjamin Ooghe-Tabanou - https://github.com/boogheta
4350
* Nikolay B Petrov - https://github.com/nikbpetrov
@@ -64,4 +71,5 @@ The following people have contributed to the development of jsPsych by writing c
6471
* Reto Wyss - https://github.com/retowyss
6572
* Shaobin Jiang - https://github.com/Shaobin-Jiang
6673
* Haotian Tu - https://github.com/thtTNT
67-
* Joshua Unrau - https://github.com/joshunrau
74+
* Joshua Unrau - https://github.com/joshunrau
75+
* Victor Zhang - https://github.com/vzhang03

docs/developers/extension-development.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let trial = {
6666
extensions: [
6767
{type: myAwesomeExtension, params: {demo: 'value'}}
6868
]
69-
});
69+
};
7070

7171
//... extension code ...//
7272
class MyAwesomeExtension {
@@ -91,7 +91,7 @@ let trial = {
9191
extensions: [
9292
{type: myAwesomeExtension, params: {demo: 'value'}}
9393
]
94-
});
94+
};
9595

9696
//... extension code ...//
9797
class MyAwesomeExtension {
@@ -122,7 +122,7 @@ let trial = {
122122
on_finish: (data) => {
123123
console.log(data.awesome); // will output 'value'.
124124
}
125-
});
125+
};
126126

127127
//... extension code ...//
128128
class MyAwesomeExtension {
@@ -168,9 +168,11 @@ The `version` field describes the version of the extension used and then durin t
168168

169169
The `data` field is an object containing all of the `data` generated for the plugin. Each 'data' object has a `type` and `default` property. Additionally, this should be only used for data you choose to generate. Any jsdoc (comments included in the /** */ tags) you include will be scraped as metadata if you are choosing to generate metadata. This scraped metadata will also be used to create the JsPsych documentation.
170170

171+
For more information on the various types of parameters one can include in their data field, see our [documentation on `ParameterType`s](./plugin-development.md#parameter-types).
172+
171173
### Optional methods
172174

173-
The extension can also include any additional methods that are necessary for interacting with it. See the [webgazer extension](../extensions/webgazer.md) for an example.
175+
The extension can also include any additional methods that are necessary for interacting with it. See the [WebGazer extension](../extensions/webgazer.md) for an example.
174176

175177
## Advice for writing extensions
176178

docs/developers/plugin-development.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ const info = {
6363
}
6464
```
6565

66+
??? info "Automatic versioning with custom build environments"
67+
68+
If you are using a custom build environment that imports its own `tsconfig.json` file that does not extend jsPsych's, and you want to use this automatic versioning syntax, you must add `"resolveJsonModule": true` to the config's `compilerOptions` object.
69+
6670
If you are not using a build environment that supports `import` and `package.json` (such as writing a plain JS file), you can manually enter the `version` as a string.
6771

6872
```javascript
@@ -165,6 +169,89 @@ class MyAwesomePlugin {
165169
MyAwesomePlugin.info = info;
166170
```
167171
172+
#### Parameter Types
173+
174+
jsPsych currently has support for the following parameter types:
175+
176+
| Type Name | Description | Example |
177+
| --------- | ----------- | ------- |
178+
| BOOL | A simple truth value. | `true` or `false` |
179+
| STRING | A set of characters. | "Continue" |
180+
| INT | A value that supports whole numbers. | 12 |
181+
| FLOAT | A value that supports decimal numbers. | 5.55 |
182+
| FUNCTION | A Javascript function, tends to process multiple objects in an array from other parameters. | `function(tries) { return "<p>You have " + tries + " tries left." }` |
183+
| KEY | A single key, with support for function keys like arrows and spacebars. | `"j"`, `"n"`, `"ArrowLeft"` |
184+
| KEYS | Either an array of keys, or the string `"ALL_KEYS"` or `"NO_KEYS"`, indicating their respective inclusion/exclusion criterea. | `["f", "j"]` |
185+
| SELECT | A list of strings that a developer can choose between as a parameter. | `["cm", "px", "em"]` |
186+
| HTML_STRING | A string with HTML markup. | `"<p>This is the prompt.</p>"` |
187+
| IMAGE | A string that contains the path to an image file. | `"my_image.jpg"` |
188+
| AUDIO | A string that contains the path to an audio file. | `"my_sound.mp3"` |
189+
| VIDEO | A string that contains the path to a video file. | `"my_video.mp4"` |
190+
| OBJECT | A general JSON object (key-value pairs). | `{ rt: 350, response: "hello!", correct: true }` |
191+
| COMPLEX | A JSON object that one can specify nested parameters for. | `{ rt: 350, response: "hello!", correct: true }` |
192+
| TIMELINE | A jsPsych timeline object with trials. | `[{ type: jsPsychKeyboardResponse, stimulus: 'my_image.jpg }]` |
193+
194+
Within each parameter, you may also specify if it is an array of the specific type. For example, a parameter that requires a list of button labels would be described as:
195+
196+
```js
197+
const info = {
198+
// ...
199+
parameters: {
200+
/** The labels to be displayed on each button. */
201+
labels: {
202+
type: ParameterType.STRING,
203+
array: true,
204+
default: ["Pause", "Play", "Continue"]
205+
}
206+
},
207+
// ...
208+
}
209+
```
210+
211+
Specific parameter types also have their own special markup. For `ParameterType.SELECT`, you specify the options one can choose with an `options` field, and then the `default` field must be within that field.
212+
213+
```js
214+
const info = {
215+
// ...
216+
parameters: {
217+
/** The units of measure used to display the length and width of the stimulus. */
218+
units: {
219+
type: ParameterType.SELECT,
220+
options: ["em", "px", "vh", "vw"],
221+
default: "px"
222+
}
223+
},
224+
// ...
225+
}
226+
```
227+
228+
For `ParameterType.COMPLEX`, we may specify the underlying fields in the object with the `nested` field. This acts in the same way as us defining parameters regularly, only we are now just delineating the fields within the object itself.
229+
230+
```js
231+
const info = {
232+
// ...
233+
parameters: {
234+
/** Where to display the location of the stimuli. */
235+
locations: {
236+
type: ParameterType.COMPLEX,
237+
array: true,
238+
default: undefined,
239+
nested: {
240+
/** The x-coordinate of the stimulus, in the units from the `units` field. */
241+
x: {
242+
type: ParameterType.INT
243+
},
244+
/** The y-coordinate of the stimulus. */
245+
y: {
246+
type: ParameterType.INT
247+
}
248+
}
249+
}
250+
},
251+
// ...
252+
}
253+
```
254+
168255
## Plugin functionality
169256
170257
Inside the `.trial()` method you can do pretty much anything that you want, including modifying the DOM, setting up event listeners, and making asynchronous requests. In this section we'll highlight a few common things that you might want to do as examples.

docs/overview/browser-device-support.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ There are many other web browsers that are available, but that are not commonly
2222
In general, jsPsych experiments can be run on mobile devices (smartphones and tablets). However, certain plugins will not work on mobile. For instance, any plugin that requires a keyboard response without a text input box, such as the *-keyboard-response plugins, will not work. Even plugins that do work on mobile might work differently than they do on desktop and laptop computers. For instance, on mobile devices, a text input box will cause an on-screen keyboard to pop up, which affects the visible content on the screen.
2323

2424
If you plan to run an experiment that allows people to use mobile devices, we recommend doing some extra testing to make sure that everything works as expected. In particular, you may want to check that:
25-
* Font sizes are readable on smaller screens
26-
* Stimuli sizes are large enough and appropriate for the task
27-
* Page is laid out as intended (e.g. elements are centered and do not overlap)
28-
* Response options are touchscreen-friendly (e.g. buttons rather than key presses)
29-
* Response options (e.g. buttons, text boxes, radio buttons) are large enough and far enough apart to be easily selected with a finger tap
25+
26+
* Font sizes are readable on smaller screens
27+
* Stimuli sizes are large enough and appropriate for the task
28+
* Page is laid out as intended (e.g. elements are centered and do not overlap)
29+
* Response options are touchscreen-friendly (e.g. buttons rather than key presses)
30+
* Response options (e.g. buttons, text boxes, radio buttons) are large enough and far enough apart to be easily selected with a finger tap
3031

3132
It's possible to use your browser's developer tools to emulate mobile devices ([this page shows how to do it in Chrome](https://developers.google.com/web/tools/chrome-devtools/device-mode)), which is useful for getting a sense of how your experiment will look on mobile devices. Just be aware that there are limitations to emulator tools, and there are some aspects of mobile devices/browsers that a desktop browser will not be able to simulate.
3233

docs/overview/building-surveys.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Rather than repeating a question format within the same trial, perhaps you want
387387
elements: [
388388
{
389389
type: "text",
390-
title: `Enter a word related to ${jsPsych.timelineVariable('word').toUpperCase()}:`,
390+
title: `Enter a word related to ${jsPsych.evaluteTimelineVariable('word').toUpperCase()}:`,
391391
autocomplete: "off"
392392
}
393393
],
@@ -416,7 +416,7 @@ Rather than repeating a question format within the same trial, perhaps you want
416416
// Create question using timeline variables
417417
const page = survey.addNewPage('page1');
418418
const question = page.addNewQuestion('text');
419-
question.title = `Enter a word related to ${jsPsych.timelineVariable('word').toUpperCase()}`;
419+
question.title = `Enter a word related to ${jsPsych.evaluateTimelineVariable('word').toUpperCase()}`;
420420
question.autocomplete = "off";
421421
// Set survey-level parameters
422422
survey.showQuestionNumbers = false;

docs/overview/extensions.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Extensions
22

3-
Extensions are jsPsych modules that can interface with any plugin to extend the functionality of the plugin. A canonical example of an extension is eye tracking. An eye tracking extension allows a plugin to gather gaze data and add it to the plugin's data object.
3+
In jsPsych, extensions allow one to extend the functionality of various plugins, giving individual plugins the ability to collect more data, display additional stimuli, and more. A canonical example of an extension is [eye tracking](../extensions/webgazer.md), which allow plugins to gather gaze data and add it to the their respective data objects. For a full list of extensions directly included in the jsPsych release, see [here](../extensions/list-of-extensions.md).
44

55
## Using an Extension
66

@@ -16,7 +16,7 @@ To use an extension in an experiment, you'll load the extension file via a `<scr
1616
```js
1717
initJsPsych({
1818
extensions: [
19-
{type: jsPsychExtensionExample, params: {...} }
19+
{ type: jsPsychExtensionExample, params: {...} }
2020
]
2121
})
2222
```
@@ -26,17 +26,11 @@ To enable an extension during a trial, add the extension to the `extensions` lis
2626
```js
2727
var trial = {
2828
extensions: [
29-
{type: jsPsychExtensionExample, params: {...} }
29+
{ type: jsPsychExtensionExample, params: {...} }
3030
]
3131
}
3232
```
3333

34-
## List of Extensions
35-
36-
Extension | Description
37-
------ | -----------
38-
[jspsych&#8209;ext&#8209;webgazer.js](../extensions/webgazer.md) | Enables eye tracking using the [WebGazer](https://webgazer.cs.brown.edu/) library.
39-
4034
## Writing an Extension
4135

4236
See our [developer's guide for extensions](../developers/extension-development.md) for information about how to create a new extension.

docs/overview/media-preloading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
If an experiment uses image, audio, or video files as stimuli, it is a good idea to preload the files before running the experiment. You can preload files at any point in your experiment using the [jsPsych `preload` plugin](../plugins/preload.md). Preloading files means that the participant's browser will download the files and store them in local memory on the participant's computer. This is important because displaying or playing a media file is much faster if it is already in memory on the participant's computer. Without preloading, there will be noticeable delays in the display of media, which will affect any timing measurements (such as how long an image is displayed, or a participant's response time since first viewing an image). For particularly large files, like video, preloading content avoids lengthy pauses in the middle of the experiment that can be disruptive to the flow of the experiment.
44

55
!!! warning
6-
Note that video preloading will not work when you run your experiment offline (e.g., by double-clicking on the HTML file), but it will work once your experiment is running online (hosted on a server). The [Cross-origin requests (CORS) and safe mode](running-experiments.md#cross-origin-requests-cors-and-safe-mode) section on the Running Experiments page contains more information about this.
6+
Note that video preloading will not work when you run your experiment offline (e.g., by double-clicking on the HTML file), but it will work once your experiment is running online (hosted on a server). The [Cross-origin requests (CORS) and safe mode](running-experiments.md#cross-origin-requests-cors-and-safe-mode) section on the Running Experiments page contains more information about this.
77

88
## Automatic Preloading
99

docs/plugins/audio-slider-response.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
2828
| 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). |
2929
| trial_duration | numeric | null | How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant fails to make a response before this timer is reached, the participant's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial will wait for a response indefinitely. |
3030
| response_ends_trial | boolean | true | If true, then the trial will end whenever the participant makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. |
31+
| trial_ends_after_audio | boolean | false | If true, then the trial will end as soon as the audio file finishes playing. |
3132
| response_allowed_while_playing | boolean | true | If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through, the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls). |
3233

3334
## Data Generated

docs/plugins/initialize-camera.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
1818
Parameter | Type | Default Value | Description
1919
----------|------|---------------|------------
2020
device_select_message | html string | `<p>Please select the camera you would like to use.</p>` | The message to display when the user is presented with a dropdown list of available devices.
21-
button_label | sting | 'Use this camera.' | The label for the select button.
21+
button_label | string | 'Use this camera.' | The label for the select button.
2222
include_audio | bool | false | Set to `true` to include an audio track in the recordings.
2323
width | int | null | Request a specific width for the recording. This is not a guarantee that this width will be used, as it depends on the capabilities of the participant's device. Learn more about `MediaRecorder` constraints [here](https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API/Constraints#requesting_a_specific_value_for_a_setting).
2424
height | int | null | Request a specific height for the recording. This is not a guarantee that this height will be used, as it depends on the capabilities of the participant's device. Learn more about `MediaRecorder` constraints [here](https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API/Constraints#requesting_a_specific_value_for_a_setting).

docs/plugins/initialize-microphone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
1818
Parameter | Type | Default Value | Description
1919
----------|------|---------------|------------
2020
device_select_message | html string | `<p>Please select the microphone you would like to use.</p>` | The message to display when the user is presented with a dropdown list of available devices.
21-
button_label | sting | 'Use this microphone.' | The label for the select button.
21+
button_label | string | 'Use this microphone.' | The label for the select button.
2222

2323

2424
## Data Generated

0 commit comments

Comments
 (0)