jspsych 7.3.0 → 7.3.2

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
@@ -71,7 +71,7 @@ var autoBind = (self, {include, exclude} = {}) => {
71
71
  return self;
72
72
  };
73
73
 
74
- var version = "7.3.0";
74
+ var version = "7.3.2";
75
75
 
76
76
  class MigrationError extends Error {
77
77
  constructor(message = "The global `jsPsych` variable is no longer available in jsPsych v7.") {
@@ -904,15 +904,15 @@ class MediaAPI {
904
904
  callback_error({ source: source, error: e });
905
905
  });
906
906
  };
907
- request.onerror = function (e) {
907
+ request.onerror = (e) => {
908
908
  let err = e;
909
- if (this.status == 404) {
909
+ if (request.status == 404) {
910
910
  err = "404";
911
911
  }
912
912
  callback_error({ source: source, error: err });
913
913
  };
914
- request.onloadend = function (e) {
915
- if (this.status == 404) {
914
+ request.onloadend = (e) => {
915
+ if (request.status == 404) {
916
916
  callback_error({ source: source, error: "404" });
917
917
  }
918
918
  };
@@ -969,20 +969,21 @@ class MediaAPI {
969
969
  callback_complete();
970
970
  return;
971
971
  }
972
- for (var i = 0; i < images.length; i++) {
973
- var img = new Image();
974
- img.onload = function () {
972
+ for (let i = 0; i < images.length; i++) {
973
+ const img = new Image();
974
+ const src = images[i];
975
+ img.onload = () => {
975
976
  n_loaded++;
976
- callback_load(img.src);
977
+ callback_load(src);
977
978
  if (n_loaded === images.length) {
978
979
  callback_complete();
979
980
  }
980
981
  };
981
- img.onerror = function (e) {
982
- callback_error({ source: img.src, error: e });
982
+ img.onerror = (e) => {
983
+ callback_error({ source: src, error: e });
983
984
  };
984
- img.src = images[i];
985
- this.img_cache[images[i]] = img;
985
+ img.src = src;
986
+ this.img_cache[src] = img;
986
987
  this.preload_requests.push(img);
987
988
  }
988
989
  }
@@ -1000,9 +1001,9 @@ class MediaAPI {
1000
1001
  const request = new XMLHttpRequest();
1001
1002
  request.open("GET", video, true);
1002
1003
  request.responseType = "blob";
1003
- request.onload = function () {
1004
- if (this.status === 200 || this.status === 0) {
1005
- const videoBlob = this.response;
1004
+ request.onload = () => {
1005
+ if (request.status === 200 || request.status === 0) {
1006
+ const videoBlob = request.response;
1006
1007
  video_buffers[video] = URL.createObjectURL(videoBlob); // IE10+
1007
1008
  n_loaded++;
1008
1009
  callback_load(video);
@@ -1011,15 +1012,15 @@ class MediaAPI {
1011
1012
  }
1012
1013
  }
1013
1014
  };
1014
- request.onerror = function (e) {
1015
+ request.onerror = (e) => {
1015
1016
  let err = e;
1016
- if (this.status == 404) {
1017
+ if (request.status == 404) {
1017
1018
  err = "404";
1018
1019
  }
1019
1020
  callback_error({ source: video, error: err });
1020
1021
  };
1021
- request.onloadend = function (e) {
1022
- if (this.status == 404) {
1022
+ request.onloadend = (e) => {
1023
+ if (request.status == 404) {
1023
1024
  callback_error({ source: video, error: "404" });
1024
1025
  }
1025
1026
  };
@@ -1876,7 +1877,8 @@ function shuffleNoRepeats(arr, equalityTest) {
1876
1877
  // test to make sure the new neighbor isn't equal to the old one
1877
1878
  while (equalityTest(random_shuffle[i + 1], random_shuffle[random_pick]) ||
1878
1879
  equalityTest(random_shuffle[i + 1], random_shuffle[random_pick + 1]) ||
1879
- equalityTest(random_shuffle[i + 1], random_shuffle[random_pick - 1])) {
1880
+ equalityTest(random_shuffle[i + 1], random_shuffle[random_pick - 1]) ||
1881
+ equalityTest(random_shuffle[i], random_shuffle[random_pick])) {
1880
1882
  random_pick = Math.floor(Math.random() * (random_shuffle.length - 2)) + 1;
1881
1883
  }
1882
1884
  const new_neighbor = random_shuffle[random_pick];
@@ -3187,20 +3189,21 @@ class JsPsych {
3187
3189
  for (const param in trial.type.info.parameters) {
3188
3190
  // check if parameter is complex with nested defaults
3189
3191
  if (trial.type.info.parameters[param].type === exports.ParameterType.COMPLEX) {
3190
- if (trial.type.info.parameters[param].array === true) {
3192
+ // check if parameter is undefined and has a default value
3193
+ if (typeof trial[param] === "undefined" && trial.type.info.parameters[param].default) {
3194
+ trial[param] = trial.type.info.parameters[param].default;
3195
+ }
3196
+ // if parameter is an array, iterate over each entry after confirming that there are
3197
+ // entries to iterate over. this is common when some parameters in a COMPLEX type have
3198
+ // default values and others do not.
3199
+ if (trial.type.info.parameters[param].array === true && Array.isArray(trial[param])) {
3191
3200
  // iterate over each entry in the array
3192
3201
  trial[param].forEach(function (ip, i) {
3193
3202
  // check each parameter in the plugin description
3194
3203
  for (const p in trial.type.info.parameters[param].nested) {
3195
3204
  if (typeof trial[param][i][p] === "undefined" || trial[param][i][p] === null) {
3196
3205
  if (typeof trial.type.info.parameters[param].nested[p].default === "undefined") {
3197
- console.error("You must specify a value for the " +
3198
- p +
3199
- " parameter (nested in the " +
3200
- param +
3201
- " parameter) in the " +
3202
- trial.type +
3203
- " plugin.");
3206
+ console.error(`You must specify a value for the ${p} parameter (nested in the ${param} parameter) in the ${trial.type.info.name} plugin.`);
3204
3207
  }
3205
3208
  else {
3206
3209
  trial[param][i][p] = trial.type.info.parameters[param].nested[p].default;
@@ -3213,11 +3216,7 @@ class JsPsych {
3213
3216
  // if it's not nested, checking is much easier and do that here:
3214
3217
  else if (typeof trial[param] === "undefined" || trial[param] === null) {
3215
3218
  if (typeof trial.type.info.parameters[param].default === "undefined") {
3216
- console.error("You must specify a value for the " +
3217
- param +
3218
- " parameter in the " +
3219
- trial.type.info.name +
3220
- " plugin.");
3219
+ console.error(`You must specify a value for the ${param} parameter in the ${trial.type.info.name} plugin.`);
3221
3220
  }
3222
3221
  else {
3223
3222
  trial[param] = trial.type.info.parameters[param].default;