jspsych 7.3.0 → 7.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspsych",
3
- "version": "7.3.0",
3
+ "version": "7.3.1",
4
4
  "description": "Behavioral experiments in a browser",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -102,15 +102,15 @@ export class MediaAPI {
102
102
  }
103
103
  );
104
104
  };
105
- request.onerror = function (e) {
105
+ request.onerror = (e) => {
106
106
  let err: ProgressEvent | string = e;
107
- if (this.status == 404) {
107
+ if (request.status == 404) {
108
108
  err = "404";
109
109
  }
110
110
  callback_error({ source: source, error: err });
111
111
  };
112
- request.onloadend = function (e) {
113
- if (this.status == 404) {
112
+ request.onloadend = (e) => {
113
+ if (request.status == 404) {
114
114
  callback_error({ source: source, error: "404" });
115
115
  }
116
116
  };
@@ -176,24 +176,24 @@ export class MediaAPI {
176
176
  return;
177
177
  }
178
178
 
179
- for (var i = 0; i < images.length; i++) {
180
- var img = new Image();
181
-
182
- img.onload = function () {
179
+ for (let i = 0; i < images.length; i++) {
180
+ const img = new Image();
181
+ const src = images[i];
182
+ img.onload = () => {
183
183
  n_loaded++;
184
- callback_load(img.src);
184
+ callback_load(src);
185
185
  if (n_loaded === images.length) {
186
186
  callback_complete();
187
187
  }
188
188
  };
189
189
 
190
- img.onerror = function (e) {
191
- callback_error({ source: img.src, error: e });
190
+ img.onerror = (e) => {
191
+ callback_error({ source: src, error: e });
192
192
  };
193
193
 
194
- img.src = images[i];
194
+ img.src = src;
195
195
 
196
- this.img_cache[images[i]] = img;
196
+ this.img_cache[src] = img;
197
197
  this.preload_requests.push(img);
198
198
  }
199
199
  }
@@ -221,9 +221,9 @@ export class MediaAPI {
221
221
  const request = new XMLHttpRequest();
222
222
  request.open("GET", video, true);
223
223
  request.responseType = "blob";
224
- request.onload = function () {
225
- if (this.status === 200 || this.status === 0) {
226
- const videoBlob = this.response;
224
+ request.onload = () => {
225
+ if (request.status === 200 || request.status === 0) {
226
+ const videoBlob = request.response;
227
227
  video_buffers[video] = URL.createObjectURL(videoBlob); // IE10+
228
228
  n_loaded++;
229
229
  callback_load(video);
@@ -232,15 +232,15 @@ export class MediaAPI {
232
232
  }
233
233
  }
234
234
  };
235
- request.onerror = function (e) {
235
+ request.onerror = (e) => {
236
236
  let err: ProgressEvent | string = e;
237
- if (this.status == 404) {
237
+ if (request.status == 404) {
238
238
  err = "404";
239
239
  }
240
240
  callback_error({ source: video, error: err });
241
241
  };
242
- request.onloadend = function (e) {
243
- if (this.status == 404) {
242
+ request.onloadend = (e) => {
243
+ if (request.status == 404) {
244
244
  callback_error({ source: video, error: "404" });
245
245
  }
246
246
  };
@@ -120,6 +120,7 @@ export function shuffleNoRepeats(arr: Array<any>, equalityTest: (a: any, b: any)
120
120
  }
121
121
 
122
122
  const random_shuffle = shuffle(arr);
123
+
123
124
  for (let i = 0; i < random_shuffle.length - 1; i++) {
124
125
  if (equalityTest(random_shuffle[i], random_shuffle[i + 1])) {
125
126
  // neighbors are equal, pick a new random neighbor to swap (not the first or last element, to avoid edge cases)
@@ -128,7 +129,8 @@ export function shuffleNoRepeats(arr: Array<any>, equalityTest: (a: any, b: any)
128
129
  while (
129
130
  equalityTest(random_shuffle[i + 1], random_shuffle[random_pick]) ||
130
131
  equalityTest(random_shuffle[i + 1], random_shuffle[random_pick + 1]) ||
131
- equalityTest(random_shuffle[i + 1], random_shuffle[random_pick - 1])
132
+ equalityTest(random_shuffle[i + 1], random_shuffle[random_pick - 1]) ||
133
+ equalityTest(random_shuffle[i], random_shuffle[random_pick])
132
134
  ) {
133
135
  random_pick = Math.floor(Math.random() * (random_shuffle.length - 2)) + 1;
134
136
  }