@jspsych/plugin-image-keyboard-response 1.1.3 → 2.0.0

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/src/index.spec.ts CHANGED
@@ -18,7 +18,7 @@ describe("image-keyboard-response", () => {
18
18
  '<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus"'
19
19
  );
20
20
 
21
- pressKey("a");
21
+ await pressKey("a");
22
22
  await expectFinished();
23
23
  });
24
24
 
@@ -36,7 +36,7 @@ describe("image-keyboard-response", () => {
36
36
  '<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus"'
37
37
  );
38
38
 
39
- pressKey("f");
39
+ await pressKey("f");
40
40
  await expectFinished();
41
41
  });
42
42
 
@@ -52,7 +52,7 @@ describe("image-keyboard-response", () => {
52
52
  ]);
53
53
 
54
54
  expect(getHTML()).toContain('<div id="foo">this is a prompt</div>');
55
- pressKey("f");
55
+ await pressKey("f");
56
56
  await expectFinished();
57
57
  });
58
58
 
@@ -76,7 +76,7 @@ describe("image-keyboard-response", () => {
76
76
  jest.advanceTimersByTime(500);
77
77
  expect(stimulusElement.style.visibility).toContain("hidden");
78
78
 
79
- pressKey("f");
79
+ await pressKey("f");
80
80
  await expectFinished();
81
81
  });
82
82
 
@@ -113,7 +113,7 @@ describe("image-keyboard-response", () => {
113
113
  '<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus"'
114
114
  );
115
115
 
116
- pressKey("f");
116
+ await pressKey("f");
117
117
  await expectFinished();
118
118
  });
119
119
 
package/src/index.ts CHANGED
@@ -1,83 +1,108 @@
1
1
  import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
2
 
3
+ import { version } from "../package.json";
4
+
3
5
  const info = <const>{
4
6
  name: "image-keyboard-response",
7
+ version: version,
5
8
  parameters: {
6
- /** The image to be displayed */
9
+ /** The path of the image file to be displayed. */
7
10
  stimulus: {
8
11
  type: ParameterType.IMAGE,
9
- pretty_name: "Stimulus",
10
12
  default: undefined,
11
13
  },
12
- /** Set the image height in pixels */
14
+ /** Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. */
13
15
  stimulus_height: {
14
16
  type: ParameterType.INT,
15
- pretty_name: "Image height",
16
17
  default: null,
17
18
  },
18
- /** Set the image width in pixels */
19
+ /** Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. */
19
20
  stimulus_width: {
20
21
  type: ParameterType.INT,
21
- pretty_name: "Image width",
22
22
  default: null,
23
23
  },
24
- /** Maintain the aspect ratio after setting width or height */
24
+ /** If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled
25
+ * to maintain the image's aspect ratio. */
25
26
  maintain_aspect_ratio: {
26
27
  type: ParameterType.BOOL,
27
- pretty_name: "Maintain aspect ratio",
28
28
  default: true,
29
29
  },
30
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
30
+ /**his array contains the key(s) that the participant is allowed to press in order to respond to the stimulus. Keys should
31
+ * be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
32
+ * [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) and
33
+ * [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
34
+ * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `"ALL_KEYS"`
35
+ * means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean that no responses are allowed. */
31
36
  choices: {
32
37
  type: ParameterType.KEYS,
33
- pretty_name: "Choices",
34
38
  default: "ALL_KEYS",
35
39
  },
36
- /** Any content here will be displayed below the stimulus. */
40
+ /**This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can
41
+ * be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). */
37
42
  prompt: {
38
43
  type: ParameterType.HTML_STRING,
39
- pretty_name: "Prompt",
40
44
  default: null,
41
45
  },
42
- /** How long to show the stimulus. */
46
+ /** How long to show the stimulus for in milliseconds. If the value is `null`, then the stimulus will be shown until the
47
+ * participant makes a response. */
43
48
  stimulus_duration: {
44
49
  type: ParameterType.INT,
45
- pretty_name: "Stimulus duration",
46
50
  default: null,
47
51
  },
48
- /** How long to show trial before it ends */
52
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant
53
+ * fails to make a response before this timer is reached, the participant's response will be recorded as null for the
54
+ * trial and the trial will end. If the value of this parameter is `null`, then the trial will wait for a response indefinitely. */
49
55
  trial_duration: {
50
56
  type: ParameterType.INT,
51
- pretty_name: "Trial duration",
52
57
  default: null,
53
58
  },
54
- /** If true, trial will end when subject makes a response. */
59
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response before
60
+ * the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for
61
+ * `trial_duration` is reached. You can set this parameter to `false` to force the participant to view a stimulus for a
62
+ * fixed amount of time, even if they respond before the time is complete. */
55
63
  response_ends_trial: {
56
64
  type: ParameterType.BOOL,
57
- pretty_name: "Response ends trial",
58
65
  default: true,
59
66
  },
60
67
  /**
61
- * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).
62
- * If false, the image will be shown via an img element.
68
+ * If `true`, the image will be drawn onto a canvas element. This prevents a blank screen (white flash) between consecutive image trials in some browsers, like Firefox and Edge.
69
+ * If `false`, the image will be shown via an img element, as in previous versions of jsPsych. If the stimulus is an **animated gif**, you must set this parameter to false, because the canvas rendering method will only present static images.
63
70
  */
64
71
  render_on_canvas: {
65
72
  type: ParameterType.BOOL,
66
- pretty_name: "Render on canvas",
67
73
  default: true,
68
74
  },
69
75
  },
76
+ data: {
77
+ /** The path of the image that was displayed. */
78
+ stimulus: {
79
+ type: ParameterType.STRING,
80
+ },
81
+ /** Indicates which key the participant pressed. */
82
+ response: {
83
+ type: ParameterType.STRING,
84
+ },
85
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus
86
+ * first appears on the screen until the participant's response. */
87
+ rt: {
88
+ type: ParameterType.INT,
89
+ },
90
+ },
70
91
  };
71
92
 
72
93
  type Info = typeof info;
73
94
 
74
95
  /**
75
- * **image-keyboard-response**
96
+ * This plugin displays an image and records responses generated with the keyboard. The stimulus can be displayed until a
97
+ * response is given, or for a pre-determined amount of time. The trial can be ended automatically if the participant has
98
+ * failed to respond within a fixed length of time.
76
99
  *
77
- * jsPsych plugin for displaying an image stimulus and getting a keyboard response
100
+ * Image files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using
101
+ * timeline variables or another dynamic method to specify the image stimulus, you will need to
102
+ * [manually preload](../overview/media-preloading.md#manual-preloading) the images.
78
103
  *
79
104
  * @author Josh de Leeuw
80
- * @see {@link https://www.jspsych.org/plugins/jspsych-image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}
105
+ * @see {@link https://www.jspsych.org/latest/plugins/image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}
81
106
  */
82
107
  class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
83
108
  static info = info;
@@ -190,9 +215,6 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
190
215
 
191
216
  // function to end trial when it is time
192
217
  const end_trial = () => {
193
- // kill any remaining setTimeout handlers
194
- this.jsPsych.pluginAPI.clearAllTimeouts();
195
-
196
218
  // kill keyboard listeners
197
219
  if (typeof keyboardListener !== "undefined") {
198
220
  this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
@@ -205,9 +227,6 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
205
227
  response: response.key,
206
228
  };
207
229
 
208
- // clear the display
209
- display_element.innerHTML = "";
210
-
211
230
  // move on to the next trial
212
231
  this.jsPsych.finishTrial(trial_data);
213
232
  };