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