mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Consistently use arrow functions in plugins
to avoid masking of `this`
This commit is contained in:
parent
c671ad717a
commit
85a69d28bc
42
.changeset/hip-planets-cough.md
Normal file
42
.changeset/hip-planets-cough.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
"@jspsych/plugin-animation": patch
|
||||||
|
"@jspsych/plugin-audio-button-response": patch
|
||||||
|
"@jspsych/plugin-audio-keyboard-response": patch
|
||||||
|
"@jspsych/plugin-audio-slider-response": patch
|
||||||
|
"@jspsych/plugin-call-function": patch
|
||||||
|
"@jspsych/plugin-canvas-button-response": patch
|
||||||
|
"@jspsych/plugin-canvas-keyboard-response": patch
|
||||||
|
"@jspsych/plugin-canvas-slider-response": patch
|
||||||
|
"@jspsych/plugin-categorize-html": patch
|
||||||
|
"@jspsych/plugin-categorize-image": patch
|
||||||
|
"@jspsych/plugin-cloze": patch
|
||||||
|
"@jspsych/plugin-external-html": patch
|
||||||
|
"@jspsych/plugin-free-sort": patch
|
||||||
|
"@jspsych/plugin-fullscreen": patch
|
||||||
|
"@jspsych/plugin-html-button-response": patch
|
||||||
|
"@jspsych/plugin-html-keyboard-response": patch
|
||||||
|
"@jspsych/plugin-html-slider-response": patch
|
||||||
|
"@jspsych/plugin-iat-html": patch
|
||||||
|
"@jspsych/plugin-iat-image": patch
|
||||||
|
"@jspsych/plugin-image-button-response": patch
|
||||||
|
"@jspsych/plugin-image-keyboard-response": patch
|
||||||
|
"@jspsych/plugin-image-slider-response": patch
|
||||||
|
"@jspsych/plugin-maxdiff": patch
|
||||||
|
"@jspsych/plugin-preload": patch
|
||||||
|
"@jspsych/plugin-resize": patch
|
||||||
|
"@jspsych/plugin-same-different-html": patch
|
||||||
|
"@jspsych/plugin-same-different-image": patch
|
||||||
|
"@jspsych/plugin-serial-reaction-time": patch
|
||||||
|
"@jspsych/plugin-serial-reaction-time-mouse": patch
|
||||||
|
"@jspsych/plugin-survey-multi-select": patch
|
||||||
|
"@jspsych/plugin-video-button-response": patch
|
||||||
|
"@jspsych/plugin-video-keyboard-response": patch
|
||||||
|
"@jspsych/plugin-video-slider-response": patch
|
||||||
|
"@jspsych/plugin-virtual-chinrest": patch
|
||||||
|
"@jspsych/plugin-visual-search-circle": patch
|
||||||
|
"@jspsych/plugin-webgazer-calibrate": patch
|
||||||
|
"@jspsych/plugin-webgazer-init-camera": patch
|
||||||
|
"@jspsych/plugin-webgazer-validate": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Replace plain functions with arrow functions to avoid masking of `this`
|
@ -103,7 +103,7 @@ class AnimationPlugin implements JsPsychPlugin<Info> {
|
|||||||
this.jsPsych.finishTrial(trial_data);
|
this.jsPsych.finishTrial(trial_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
var animate_interval = setInterval(function () {
|
var animate_interval = setInterval(() => {
|
||||||
var showImage = true;
|
var showImage = true;
|
||||||
if (!trial.render_on_canvas) {
|
if (!trial.render_on_canvas) {
|
||||||
display_element.innerHTML = ""; // clear everything
|
display_element.innerHTML = ""; // clear everything
|
||||||
@ -155,7 +155,7 @@ class AnimationPlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.frame_isi > 0) {
|
if (trial.frame_isi > 0) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>("#jspsych-animation-image").style.visibility =
|
display_element.querySelector<HTMLElement>("#jspsych-animation-image").style.visibility =
|
||||||
"hidden";
|
"hidden";
|
||||||
current_stim = "blank";
|
current_stim = "blank";
|
||||||
@ -168,7 +168,7 @@ class AnimationPlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var after_response = function (info) {
|
var after_response = (info) => {
|
||||||
responses.push({
|
responses.push({
|
||||||
key_press: info.key,
|
key_press: info.key,
|
||||||
rt: info.rt,
|
rt: info.rt,
|
||||||
|
@ -106,7 +106,7 @@ class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// load audio file
|
// load audio file
|
||||||
this.jsPsych.pluginAPI
|
this.jsPsych.pluginAPI
|
||||||
.getAudioBuffer(trial.stimulus)
|
.getAudioBuffer(trial.stimulus)
|
||||||
.then(function (buffer) {
|
.then((buffer) => {
|
||||||
if (context !== null) {
|
if (context !== null) {
|
||||||
audio = context.createBufferSource();
|
audio = context.createBufferSource();
|
||||||
audio.buffer = buffer;
|
audio.buffer = buffer;
|
||||||
@ -117,7 +117,7 @@ class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
setupTrial();
|
setupTrial();
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
||||||
);
|
);
|
||||||
@ -195,7 +195,7 @@ class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ class AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// load audio file
|
// load audio file
|
||||||
this.jsPsych.pluginAPI
|
this.jsPsych.pluginAPI
|
||||||
.getAudioBuffer(trial.stimulus)
|
.getAudioBuffer(trial.stimulus)
|
||||||
.then(function (buffer) {
|
.then((buffer) => {
|
||||||
if (context !== null) {
|
if (context !== null) {
|
||||||
audio = context.createBufferSource();
|
audio = context.createBufferSource();
|
||||||
audio.buffer = buffer;
|
audio.buffer = buffer;
|
||||||
@ -94,7 +94,7 @@ class AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
setupTrial();
|
setupTrial();
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
||||||
);
|
);
|
||||||
@ -129,7 +129,7 @@ class AudioKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// load audio file
|
// load audio file
|
||||||
this.jsPsych.pluginAPI
|
this.jsPsych.pluginAPI
|
||||||
.getAudioBuffer(trial.stimulus)
|
.getAudioBuffer(trial.stimulus)
|
||||||
.then(function (buffer) {
|
.then((buffer) => {
|
||||||
if (context !== null) {
|
if (context !== null) {
|
||||||
audio = context.createBufferSource();
|
audio = context.createBufferSource();
|
||||||
audio.buffer = buffer;
|
audio.buffer = buffer;
|
||||||
@ -138,7 +138,7 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
setupTrial();
|
setupTrial();
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch((err) => {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`
|
||||||
);
|
);
|
||||||
@ -252,7 +252,7 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-audio-slider-response-next")
|
.querySelector("#jspsych-audio-slider-response-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
// measure response time
|
// measure response time
|
||||||
var endTime = performance.now();
|
var endTime = performance.now();
|
||||||
var rt = Math.round(endTime - startTime);
|
var rt = Math.round(endTime - startTime);
|
||||||
@ -285,7 +285,7 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class CallFunctionPlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (trial.async) {
|
if (trial.async) {
|
||||||
var done = function (data) {
|
var done = (data) => {
|
||||||
return_val = data;
|
return_val = data;
|
||||||
end_trial();
|
end_trial();
|
||||||
};
|
};
|
||||||
|
@ -145,7 +145,7 @@ class CanvasButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
for (var i = 0; i < trial.choices.length; i++) {
|
for (var i = 0; i < trial.choices.length; i++) {
|
||||||
display_element
|
display_element
|
||||||
.querySelector<HTMLButtonElement>("#jspsych-canvas-button-response-button-" + i)
|
.querySelector<HTMLButtonElement>("#jspsych-canvas-button-response-button-" + i)
|
||||||
.addEventListener("click", function (e: MouseEvent) {
|
.addEventListener("click", (e: MouseEvent) => {
|
||||||
var choice = e.currentTarget as Element;
|
var choice = e.currentTarget as Element;
|
||||||
choice.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
choice.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
||||||
after_response(choice);
|
after_response(choice);
|
||||||
@ -203,7 +203,7 @@ class CanvasButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide image if timing is set
|
// hide image if timing is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-canvas-button-response-stimulus"
|
"#jspsych-canvas-button-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -212,7 +212,7 @@ class CanvasButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// function to handle responses by the subject
|
// function to handle responses by the subject
|
||||||
var after_response = function (info) {
|
var after_response = (info) => {
|
||||||
// after a valid response, the stimulus will have the CSS class 'responded'
|
// after a valid response, the stimulus will have the CSS class 'responded'
|
||||||
// which can be used to provide visual feedback that a response was recorded
|
// which can be used to provide visual feedback that a response was recorded
|
||||||
display_element.querySelector("#jspsych-canvas-keyboard-response-stimulus").className +=
|
display_element.querySelector("#jspsych-canvas-keyboard-response-stimulus").className +=
|
||||||
@ -141,7 +141,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide stimulus if stimulus_duration is set
|
// hide stimulus if stimulus_duration is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-canvas-keyboard-response-stimulus"
|
"#jspsych-canvas-keyboard-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -150,7 +150,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ class CanvasSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-canvas-slider-response-next")
|
.querySelector("#jspsych-canvas-slider-response-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
// measure response time
|
// measure response time
|
||||||
var endTime = performance.now();
|
var endTime = performance.now();
|
||||||
response.rt = Math.round(endTime - startTime);
|
response.rt = Math.round(endTime - startTime);
|
||||||
@ -228,7 +228,7 @@ class CanvasSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-canvas-slider-response-stimulus"
|
"#jspsych-canvas-slider-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -237,9 +237,7 @@ class CanvasSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var startTime = performance.now();
|
var startTime = performance.now();
|
||||||
|
@ -113,7 +113,7 @@ class CategorizeHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide image after time if the timing parameter is set
|
// hide image after time if the timing parameter is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-categorize-html-stimulus"
|
"#jspsych-categorize-html-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -163,7 +163,7 @@ class CategorizeHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
after_response({
|
after_response({
|
||||||
key: null,
|
key: null,
|
||||||
rt: null,
|
rt: null,
|
||||||
@ -205,7 +205,7 @@ class CategorizeHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
correct === false &&
|
correct === false &&
|
||||||
((timeout && trial.show_feedback_on_timeout) || !timeout)
|
((timeout && trial.show_feedback_on_timeout) || !timeout)
|
||||||
) {
|
) {
|
||||||
var after_forced_response = function (info) {
|
var after_forced_response = (info) => {
|
||||||
endTrial();
|
endTrial();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -217,9 +217,7 @@ class CategorizeHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
allow_held_key: false,
|
allow_held_key: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(endTrial, trial.feedback_duration);
|
||||||
endTrial();
|
|
||||||
}, trial.feedback_duration);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class CategorizeImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide image after time if the timing parameter is set
|
// hide image after time if the timing parameter is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-categorize-image-stimulus"
|
"#jspsych-categorize-image-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -162,7 +162,7 @@ class CategorizeImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
after_response({
|
after_response({
|
||||||
key: null,
|
key: null,
|
||||||
rt: null,
|
rt: null,
|
||||||
@ -204,7 +204,7 @@ class CategorizeImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
correct === false &&
|
correct === false &&
|
||||||
((timeout && trial.show_feedback_on_timeout) || !timeout)
|
((timeout && trial.show_feedback_on_timeout) || !timeout)
|
||||||
) {
|
) {
|
||||||
var after_forced_response = function (info) {
|
var after_forced_response = (info) => {
|
||||||
endTrial();
|
endTrial();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,9 +216,7 @@ class CategorizeImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
allow_held_key: false,
|
allow_held_key: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(endTrial, trial.feedback_duration);
|
||||||
endTrial();
|
|
||||||
}, trial.feedback_duration);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ const info = <const>{
|
|||||||
mistake_fn: {
|
mistake_fn: {
|
||||||
type: ParameterType.FUNCTION,
|
type: ParameterType.FUNCTION,
|
||||||
pretty_name: "Mistake function",
|
pretty_name: "Mistake function",
|
||||||
default: function () {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -25,9 +25,7 @@ const info = <const>{
|
|||||||
check_fn: {
|
check_fn: {
|
||||||
type: ParameterType.FUNCTION,
|
type: ParameterType.FUNCTION,
|
||||||
pretty_name: "Check function",
|
pretty_name: "Check function",
|
||||||
default: function () {
|
default: () => true,
|
||||||
return true;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
/** Whether or not to force a page refresh. */
|
/** Whether or not to force a page refresh. */
|
||||||
force_refresh: {
|
force_refresh: {
|
||||||
@ -74,7 +72,7 @@ class ExternalHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
const load = (element, file, callback) => {
|
const load = (element, file, callback) => {
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.open("GET", file, true);
|
xmlhttp.open("GET", file, true);
|
||||||
xmlhttp.onload = function () {
|
xmlhttp.onload = () => {
|
||||||
if (xmlhttp.status == 200 || xmlhttp.status == 0) {
|
if (xmlhttp.status == 200 || xmlhttp.status == 0) {
|
||||||
//Check if loaded
|
//Check if loaded
|
||||||
element.innerHTML = xmlhttp.responseText;
|
element.innerHTML = xmlhttp.responseText;
|
||||||
|
@ -356,7 +356,7 @@ class FreeSortPlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < draggables.length; i++) {
|
for (let i = 0; i < draggables.length; i++) {
|
||||||
draggables[i].addEventListener(start_event_name, function (event: MouseEvent | TouchEvent) {
|
draggables[i].addEventListener(start_event_name, (event: MouseEvent | TouchEvent) => {
|
||||||
let pageX: number;
|
let pageX: number;
|
||||||
let pageY: number;
|
let pageY: number;
|
||||||
if (event instanceof MouseEvent) {
|
if (event instanceof MouseEvent) {
|
||||||
@ -377,7 +377,7 @@ class FreeSortPlugin implements JsPsychPlugin<Info> {
|
|||||||
let y = pageY - elem.offsetTop - window.scrollY;
|
let y = pageY - elem.offsetTop - window.scrollY;
|
||||||
elem.style.transform = "scale(" + trial.scale_factor + "," + trial.scale_factor + ")";
|
elem.style.transform = "scale(" + trial.scale_factor + "," + trial.scale_factor + ")";
|
||||||
|
|
||||||
let move_event = function (e) {
|
let move_event = (e) => {
|
||||||
let clientX = e.clientX;
|
let clientX = e.clientX;
|
||||||
let clientY = e.clientY;
|
let clientY = e.clientY;
|
||||||
if (typeof document.ontouchend !== "undefined") {
|
if (typeof document.ontouchend !== "undefined") {
|
||||||
@ -439,7 +439,7 @@ class FreeSortPlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
document.addEventListener(move_event_name, move_event);
|
document.addEventListener(move_event_name, move_event);
|
||||||
|
|
||||||
var end_event = function (e) {
|
var end_event = (e) => {
|
||||||
document.removeEventListener(move_event_name, move_event);
|
document.removeEventListener(move_event_name, move_event);
|
||||||
elem.style.transform = "scale(1, 1)";
|
elem.style.transform = "scale(1, 1)";
|
||||||
if (trial.change_border_background_color) {
|
if (trial.change_border_background_color) {
|
||||||
|
@ -54,7 +54,7 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
|
|||||||
const endTrial = () => {
|
const endTrial = () => {
|
||||||
display_element.innerHTML = "";
|
display_element.innerHTML = "";
|
||||||
|
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
var trial_data = {
|
var trial_data = {
|
||||||
success: !keyboardNotAllowed,
|
success: !keyboardNotAllowed,
|
||||||
};
|
};
|
||||||
@ -78,7 +78,7 @@ class FullscreenPlugin implements JsPsychPlugin<Info> {
|
|||||||
"</button>";
|
"</button>";
|
||||||
var listener = display_element
|
var listener = display_element
|
||||||
.querySelector("#jspsych-fullscreen-btn")
|
.querySelector("#jspsych-fullscreen-btn")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
var element = document.documentElement;
|
var element = document.documentElement;
|
||||||
if (element.requestFullscreen) {
|
if (element.requestFullscreen) {
|
||||||
element.requestFullscreen();
|
element.requestFullscreen();
|
||||||
|
@ -125,7 +125,7 @@ class HtmlButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
for (var i = 0; i < trial.choices.length; i++) {
|
for (var i = 0; i < trial.choices.length; i++) {
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-html-button-response-button-" + i)
|
.querySelector("#jspsych-html-button-response-button-" + i)
|
||||||
.addEventListener("click", function (e) {
|
.addEventListener("click", (e) => {
|
||||||
var btn_el = e.currentTarget as HTMLButtonElement;
|
var btn_el = e.currentTarget as HTMLButtonElement;
|
||||||
var choice = btn_el.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
var choice = btn_el.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
||||||
after_response(choice);
|
after_response(choice);
|
||||||
@ -184,7 +184,7 @@ class HtmlButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide image if timing is set
|
// hide image if timing is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-html-button-response-stimulus"
|
"#jspsych-html-button-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -193,9 +193,7 @@ class HtmlButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// function to handle responses by the subject
|
// function to handle responses by the subject
|
||||||
var after_response = function (info) {
|
var after_response = (info) => {
|
||||||
// after a valid response, the stimulus will have the CSS class 'responded'
|
// after a valid response, the stimulus will have the CSS class 'responded'
|
||||||
// which can be used to provide visual feedback that a response was recorded
|
// which can be used to provide visual feedback that a response was recorded
|
||||||
display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className +=
|
display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className +=
|
||||||
@ -140,7 +140,7 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide stimulus if stimulus_duration is set
|
// hide stimulus if stimulus_duration is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-html-keyboard-response-stimulus"
|
"#jspsych-html-keyboard-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -149,9 +149,7 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ class HtmlSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-html-slider-response-next")
|
.querySelector("#jspsych-html-slider-response-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
// measure response time
|
// measure response time
|
||||||
var endTime = performance.now();
|
var endTime = performance.now();
|
||||||
response.rt = Math.round(endTime - startTime);
|
response.rt = Math.round(endTime - startTime);
|
||||||
@ -221,7 +221,7 @@ class HtmlSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-html-slider-response-stimulus"
|
"#jspsych-html-slider-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -230,9 +230,7 @@ class HtmlSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var startTime = performance.now();
|
var startTime = performance.now();
|
||||||
|
@ -294,7 +294,7 @@ class IatHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null && trial.response_ends_trial != true) {
|
if (trial.trial_duration !== null && trial.response_ends_trial != true) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ class IatImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null && trial.response_ends_trial != true) {
|
if (trial.trial_duration !== null && trial.response_ends_trial != true) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class ImageButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
canvas.style.padding = "0";
|
canvas.style.padding = "0";
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function () {
|
img.onload = () => {
|
||||||
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
||||||
if (!image_drawn) {
|
if (!image_drawn) {
|
||||||
getHeightWidth(); // only possible to get width/height after image loads
|
getHeightWidth(); // only possible to get width/height after image loads
|
||||||
@ -278,7 +278,7 @@ class ImageButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
for (var i = 0; i < trial.choices.length; i++) {
|
for (var i = 0; i < trial.choices.length; i++) {
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-image-button-response-button-" + i)
|
.querySelector("#jspsych-image-button-response-button-" + i)
|
||||||
.addEventListener("click", function (e) {
|
.addEventListener("click", (e) => {
|
||||||
var btn_el = e.currentTarget as HTMLButtonElement;
|
var btn_el = e.currentTarget as HTMLButtonElement;
|
||||||
var choice = btn_el.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
var choice = btn_el.getAttribute("data-choice"); // don't use dataset for jsdom compatibility
|
||||||
after_response(choice);
|
after_response(choice);
|
||||||
@ -337,7 +337,7 @@ class ImageButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide image if timing is set
|
// hide image if timing is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-image-button-response-stimulus"
|
"#jspsych-image-button-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -346,7 +346,7 @@ class ImageButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
} else if (trial.response_ends_trial === false) {
|
} else if (trial.response_ends_trial === false) {
|
||||||
|
@ -102,7 +102,7 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
canvas.style.padding = "0";
|
canvas.style.padding = "0";
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function () {
|
img.onload = () => {
|
||||||
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
||||||
if (!image_drawn) {
|
if (!image_drawn) {
|
||||||
getHeightWidth(); // only possible to get width/height after image loads
|
getHeightWidth(); // only possible to get width/height after image loads
|
||||||
@ -213,7 +213,7 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// function to handle responses by the subject
|
// function to handle responses by the subject
|
||||||
var after_response = function (info) {
|
var after_response = (info) => {
|
||||||
// after a valid response, the stimulus will have the CSS class 'responded'
|
// after a valid response, the stimulus will have the CSS class 'responded'
|
||||||
// which can be used to provide visual feedback that a response was recorded
|
// which can be used to provide visual feedback that a response was recorded
|
||||||
display_element.querySelector("#jspsych-image-keyboard-response-stimulus").className +=
|
display_element.querySelector("#jspsych-image-keyboard-response-stimulus").className +=
|
||||||
@ -242,7 +242,7 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// hide stimulus if stimulus_duration is set
|
// hide stimulus if stimulus_duration is set
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-image-keyboard-response-stimulus"
|
"#jspsych-image-keyboard-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -251,7 +251,7 @@ class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
} else if (trial.response_ends_trial === false) {
|
} else if (trial.response_ends_trial === false) {
|
||||||
|
@ -153,7 +153,7 @@ class ImageSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
canvas.style.padding = "0";
|
canvas.style.padding = "0";
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext("2d");
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = function () {
|
img.onload = () => {
|
||||||
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
// if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
|
||||||
if (!image_drawn) {
|
if (!image_drawn) {
|
||||||
getHeightWidth(); // only possible to get width/height after image loads
|
getHeightWidth(); // only possible to get width/height after image loads
|
||||||
@ -386,7 +386,7 @@ class ImageSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-image-slider-response-next")
|
.querySelector("#jspsych-image-slider-response-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
// measure response time
|
// measure response time
|
||||||
var endTime = performance.now();
|
var endTime = performance.now();
|
||||||
response.rt = Math.round(endTime - startTime);
|
response.rt = Math.round(endTime - startTime);
|
||||||
@ -404,7 +404,7 @@ class ImageSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.stimulus_duration !== null) {
|
if (trial.stimulus_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
"#jspsych-image-slider-response-stimulus"
|
"#jspsych-image-slider-response-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
@ -413,7 +413,7 @@ class ImageSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if trial_duration is set
|
// end trial if trial_duration is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
end_trial();
|
end_trial();
|
||||||
}, trial.trial_duration);
|
}, trial.trial_duration);
|
||||||
}
|
}
|
||||||
|
@ -136,10 +136,10 @@ class MaxdiffPlugin implements JsPsychPlugin<Info> {
|
|||||||
// first checks that the same alternative cannot be endorsed in the left and right columns simultaneously.
|
// first checks that the same alternative cannot be endorsed in the left and right columns simultaneously.
|
||||||
// then enables the submit button if the trial is required.
|
// then enables the submit button if the trial is required.
|
||||||
const left_right = ["left", "right"];
|
const left_right = ["left", "right"];
|
||||||
left_right.forEach(function (p) {
|
left_right.forEach((p) => {
|
||||||
// Get all elements either 'left' or 'right'
|
// Get all elements either 'left' or 'right'
|
||||||
document.getElementsByName(p).forEach(function (alt) {
|
document.getElementsByName(p).forEach((alt) => {
|
||||||
alt.addEventListener("click", function () {
|
alt.addEventListener("click", () => {
|
||||||
// Find the opposite (if left, then right & vice versa) identified by the class (jspsych-maxdiff-alt-1, 2, etc)
|
// Find the opposite (if left, then right & vice versa) identified by the class (jspsych-maxdiff-alt-1, 2, etc)
|
||||||
var op = alt["name"] == "left" ? "right" : "left";
|
var op = alt["name"] == "left" ? "right" : "left";
|
||||||
var n = document.getElementsByClassName(alt.className).namedItem(op);
|
var n = document.getElementsByClassName(alt.className).namedItem(op);
|
||||||
|
@ -240,7 +240,7 @@ class PreloadPlugin implements JsPsychPlugin<Info> {
|
|||||||
// show detailed errors, if necessary
|
// show detailed errors, if necessary
|
||||||
if (trial.show_detailed_errors) {
|
if (trial.show_detailed_errors) {
|
||||||
display_element.innerHTML += "<p><strong>Error details:</strong></p>";
|
display_element.innerHTML += "<p><strong>Error details:</strong></p>";
|
||||||
detailed_errors.forEach(function (e) {
|
detailed_errors.forEach((e) => {
|
||||||
display_element.innerHTML += e;
|
display_element.innerHTML += e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -284,13 +284,13 @@ class PreloadPlugin implements JsPsychPlugin<Info> {
|
|||||||
this.jsPsych.pluginAPI.preloadImages(images, cb, file_loading_success, file_loading_error);
|
this.jsPsych.pluginAPI.preloadImages(images, cb, file_loading_success, file_loading_error);
|
||||||
};
|
};
|
||||||
if (video.length > 0) {
|
if (video.length > 0) {
|
||||||
load_video(function () {});
|
load_video(() => {});
|
||||||
}
|
}
|
||||||
if (audio.length > 0) {
|
if (audio.length > 0) {
|
||||||
load_audio(function () {});
|
load_audio(() => {});
|
||||||
}
|
}
|
||||||
if (images.length > 0) {
|
if (images.length > 0) {
|
||||||
load_images(function () {});
|
load_images(() => {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class ResizePlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// listens for the click
|
// listens for the click
|
||||||
document.getElementById("jspsych-resize-btn").addEventListener("click", function () {
|
document.getElementById("jspsych-resize-btn").addEventListener("click", () => {
|
||||||
scale();
|
scale();
|
||||||
end_trial();
|
end_trial();
|
||||||
});
|
});
|
||||||
@ -117,7 +117,7 @@ class ResizePlugin implements JsPsychPlugin<Info> {
|
|||||||
var origin_x, origin_y;
|
var origin_x, origin_y;
|
||||||
var cx, cy;
|
var cx, cy;
|
||||||
|
|
||||||
var mousedownevent = function (e) {
|
var mousedownevent = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dragging = true;
|
dragging = true;
|
||||||
origin_x = e.pageX;
|
origin_x = e.pageX;
|
||||||
@ -130,7 +130,7 @@ class ResizePlugin implements JsPsychPlugin<Info> {
|
|||||||
.querySelector("#jspsych-resize-handle")
|
.querySelector("#jspsych-resize-handle")
|
||||||
.addEventListener("mousedown", mousedownevent);
|
.addEventListener("mousedown", mousedownevent);
|
||||||
|
|
||||||
var mouseupevent = function (e) {
|
var mouseupevent = (e) => {
|
||||||
dragging = false;
|
dragging = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ class ResizePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
var scale_div: HTMLDivElement = display_element.querySelector("#jspsych-resize-div");
|
var scale_div: HTMLDivElement = display_element.querySelector("#jspsych-resize-div");
|
||||||
|
|
||||||
var resizeevent = function (e) {
|
var resizeevent = (e) => {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
var dx = e.pageX - origin_x;
|
var dx = e.pageX - origin_x;
|
||||||
var dy = e.pageY - origin_y;
|
var dy = e.pageY - origin_y;
|
||||||
|
@ -77,7 +77,7 @@ class SameDifferentHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
var first_stim_info: { key: string; rt: number };
|
var first_stim_info: { key: string; rt: number };
|
||||||
if (trial.first_stim_duration > 0) {
|
if (trial.first_stim_duration > 0) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
showBlankScreen();
|
showBlankScreen();
|
||||||
}, trial.first_stim_duration);
|
}, trial.first_stim_duration);
|
||||||
} else {
|
} else {
|
||||||
@ -97,9 +97,7 @@ class SameDifferentHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
const showBlankScreen = () => {
|
const showBlankScreen = () => {
|
||||||
display_element.innerHTML = "";
|
display_element.innerHTML = "";
|
||||||
|
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(showSecondStim, trial.gap_duration);
|
||||||
showSecondStim();
|
|
||||||
}, trial.gap_duration);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const showSecondStim = () => {
|
const showSecondStim = () => {
|
||||||
@ -111,7 +109,7 @@ class SameDifferentHtmlPlugin implements JsPsychPlugin<Info> {
|
|||||||
display_element.innerHTML = html;
|
display_element.innerHTML = html;
|
||||||
|
|
||||||
if (trial.second_stim_duration > 0) {
|
if (trial.second_stim_duration > 0) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
".jspsych-same-different-stimulus"
|
".jspsych-same-different-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
|
@ -72,14 +72,18 @@ class SameDifferentImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
constructor(private jsPsych: JsPsych) {}
|
constructor(private jsPsych: JsPsych) {}
|
||||||
|
|
||||||
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
||||||
|
const showBlankScreen = () => {
|
||||||
|
display_element.innerHTML = "";
|
||||||
|
|
||||||
|
this.jsPsych.pluginAPI.setTimeout(showSecondStim(), trial.gap_duration);
|
||||||
|
};
|
||||||
|
|
||||||
display_element.innerHTML =
|
display_element.innerHTML =
|
||||||
'<img class="jspsych-same-different-stimulus" src="' + trial.stimuli[0] + '"></img>';
|
'<img class="jspsych-same-different-stimulus" src="' + trial.stimuli[0] + '"></img>';
|
||||||
|
|
||||||
var first_stim_info: { key: string; rt: number };
|
var first_stim_info: { key: string; rt: number };
|
||||||
if (trial.first_stim_duration > 0) {
|
if (trial.first_stim_duration > 0) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(showBlankScreen, trial.first_stim_duration);
|
||||||
showBlankScreen();
|
|
||||||
}, trial.first_stim_duration);
|
|
||||||
} else {
|
} else {
|
||||||
const afterKeyboardResponse = (info: { key: string; rt: number }) => {
|
const afterKeyboardResponse = (info: { key: string; rt: number }) => {
|
||||||
first_stim_info = info;
|
first_stim_info = info;
|
||||||
@ -94,14 +98,6 @@ class SameDifferentImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const showBlankScreen = () => {
|
|
||||||
display_element.innerHTML = "";
|
|
||||||
|
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
|
||||||
showSecondStim();
|
|
||||||
}, trial.gap_duration);
|
|
||||||
};
|
|
||||||
|
|
||||||
const showSecondStim = () => {
|
const showSecondStim = () => {
|
||||||
var html =
|
var html =
|
||||||
'<img class="jspsych-same-different-stimulus" src="' + trial.stimuli[1] + '"></img>';
|
'<img class="jspsych-same-different-stimulus" src="' + trial.stimuli[1] + '"></img>';
|
||||||
@ -113,7 +109,7 @@ class SameDifferentImagePlugin implements JsPsychPlugin<Info> {
|
|||||||
display_element.innerHTML = html;
|
display_element.innerHTML = html;
|
||||||
|
|
||||||
if (trial.second_stim_duration > 0) {
|
if (trial.second_stim_duration > 0) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
display_element.querySelector<HTMLElement>(
|
display_element.querySelector<HTMLElement>(
|
||||||
".jspsych-same-different-stimulus"
|
".jspsych-same-different-stimulus"
|
||||||
).style.visibility = "hidden";
|
).style.visibility = "hidden";
|
||||||
|
@ -105,7 +105,7 @@ class SerialReactionTimeMousePlugin implements JsPsychPlugin<Info> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < resp_targets.length; i++) {
|
for (var i = 0; i < resp_targets.length; i++) {
|
||||||
resp_targets[i].addEventListener("mousedown", function (e) {
|
resp_targets[i].addEventListener("mousedown", (e) => {
|
||||||
if (startTime == -1) {
|
if (startTime == -1) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -145,9 +145,7 @@ class SerialReactionTimeMousePlugin implements JsPsychPlugin<Info> {
|
|||||||
if (trial.pre_target_duration <= 0) {
|
if (trial.pre_target_duration <= 0) {
|
||||||
showTarget();
|
showTarget();
|
||||||
} else {
|
} else {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(showTarget, trial.pre_target_duration);
|
||||||
showTarget();
|
|
||||||
}, trial.pre_target_duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//show prompt if there is one
|
//show prompt if there is one
|
||||||
|
@ -216,9 +216,7 @@ class SerialReactionTimePlugin implements JsPsychPlugin<Info> {
|
|||||||
if (trial.pre_target_duration <= 0) {
|
if (trial.pre_target_duration <= 0) {
|
||||||
showTarget();
|
showTarget();
|
||||||
} else {
|
} else {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(showTarget(), trial.pre_target_duration);
|
||||||
showTarget();
|
|
||||||
}, trial.pre_target_duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//show prompt if there is one
|
//show prompt if there is one
|
||||||
|
@ -92,9 +92,7 @@ class SurveyMultiSelectPlugin implements JsPsychPlugin<Info> {
|
|||||||
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
||||||
var plugin_id_name = "jspsych-survey-multi-select";
|
var plugin_id_name = "jspsych-survey-multi-select";
|
||||||
var plugin_id_selector = "#" + plugin_id_name;
|
var plugin_id_selector = "#" + plugin_id_name;
|
||||||
const _join = function (...args: Array<string | number>) {
|
const _join = (...args: Array<string | number>) => args.join("-");
|
||||||
return args.join("-");
|
|
||||||
};
|
|
||||||
|
|
||||||
// inject CSS for trial
|
// inject CSS for trial
|
||||||
var cssstr =
|
var cssstr =
|
||||||
@ -206,7 +204,7 @@ class SurveyMultiSelectPlugin implements JsPsychPlugin<Info> {
|
|||||||
// then submit the form
|
// then submit the form
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-survey-multi-select-next")
|
.querySelector("#jspsych-survey-multi-select-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
for (var i = 0; i < trial.questions.length; i++) {
|
for (var i = 0; i < trial.questions.length; i++) {
|
||||||
if (trial.questions[i].required) {
|
if (trial.questions[i].required) {
|
||||||
if (
|
if (
|
||||||
|
@ -222,7 +222,7 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
video_element.src = video_preload_blob;
|
video_element.src = video_preload_blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
video_element.onended = function () {
|
video_element.onended = () => {
|
||||||
if (trial.trial_ends_after_video) {
|
if (trial.trial_ends_after_video) {
|
||||||
end_trial();
|
end_trial();
|
||||||
} else if (!trial.response_allowed_while_playing) {
|
} else if (!trial.response_allowed_while_playing) {
|
||||||
@ -236,7 +236,7 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// before showing and playing, so that the video doesn't automatically show the first frame
|
// before showing and playing, so that the video doesn't automatically show the first frame
|
||||||
if (trial.start !== null) {
|
if (trial.start !== null) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
video_element.onseeked = function () {
|
video_element.onseeked = () => {
|
||||||
video_element.style.visibility = "visible";
|
video_element.style.visibility = "visible";
|
||||||
video_element.muted = false;
|
video_element.muted = false;
|
||||||
if (trial.autoplay) {
|
if (trial.autoplay) {
|
||||||
@ -244,11 +244,11 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
} else {
|
} else {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
}
|
}
|
||||||
video_element.onseeked = function () {};
|
video_element.onseeked = () => {};
|
||||||
};
|
};
|
||||||
video_element.onplaying = function () {
|
video_element.onplaying = () => {
|
||||||
video_element.currentTime = trial.start;
|
video_element.currentTime = trial.start;
|
||||||
video_element.onplaying = function () {};
|
video_element.onplaying = () => {};
|
||||||
};
|
};
|
||||||
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
||||||
// change current time, then show/unmute
|
// change current time, then show/unmute
|
||||||
@ -258,7 +258,7 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
if (trial.stop !== null) {
|
if (trial.stop !== null) {
|
||||||
video_element.addEventListener("timeupdate", function (e) {
|
video_element.addEventListener("timeupdate", (e) => {
|
||||||
var currenttime = video_element.currentTime;
|
var currenttime = video_element.currentTime;
|
||||||
if (currenttime >= trial.stop) {
|
if (currenttime >= trial.stop) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
@ -296,7 +296,7 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
.pause();
|
.pause();
|
||||||
display_element.querySelector<HTMLVideoElement>(
|
display_element.querySelector<HTMLVideoElement>(
|
||||||
"#jspsych-video-button-response-stimulus"
|
"#jspsych-video-button-response-stimulus"
|
||||||
).onended = function () {};
|
).onended = () => {};
|
||||||
|
|
||||||
// gather the data to store for the trial
|
// gather the data to store for the trial
|
||||||
var trial_data = {
|
var trial_data = {
|
||||||
@ -361,9 +361,7 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// before showing and playing, so that the video doesn't automatically show the first frame
|
// before showing and playing, so that the video doesn't automatically show the first frame
|
||||||
if (trial.start !== null) {
|
if (trial.start !== null) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
video_element.onseeked = function () {
|
video_element.onseeked = () => {
|
||||||
video_element.style.visibility = "visible";
|
video_element.style.visibility = "visible";
|
||||||
video_element.muted = false;
|
video_element.muted = false;
|
||||||
if (trial.autoplay) {
|
if (trial.autoplay) {
|
||||||
@ -197,11 +197,11 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
} else {
|
} else {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
}
|
}
|
||||||
video_element.onseeked = function () {};
|
video_element.onseeked = () => {};
|
||||||
};
|
};
|
||||||
video_element.onplaying = function () {
|
video_element.onplaying = () => {
|
||||||
video_element.currentTime = trial.start;
|
video_element.currentTime = trial.start;
|
||||||
video_element.onplaying = function () {};
|
video_element.onplaying = () => {};
|
||||||
};
|
};
|
||||||
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
||||||
// change current time, then show/unmute
|
// change current time, then show/unmute
|
||||||
@ -211,7 +211,7 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
if (trial.stop !== null) {
|
if (trial.stop !== null) {
|
||||||
video_element.addEventListener("timeupdate", function (e) {
|
video_element.addEventListener("timeupdate", (e) => {
|
||||||
var currenttime = video_element.currentTime;
|
var currenttime = video_element.currentTime;
|
||||||
if (currenttime >= trial.stop) {
|
if (currenttime >= trial.stop) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
@ -246,7 +246,7 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
.pause();
|
.pause();
|
||||||
display_element.querySelector<HTMLVideoElement>(
|
display_element.querySelector<HTMLVideoElement>(
|
||||||
"#jspsych-video-keyboard-response-stimulus"
|
"#jspsych-video-keyboard-response-stimulus"
|
||||||
).onended = function () {};
|
).onended = () => {};
|
||||||
|
|
||||||
// gather the data to store for the trial
|
// gather the data to store for the trial
|
||||||
var trial_data = {
|
var trial_data = {
|
||||||
@ -263,7 +263,7 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// function to handle responses by the subject
|
// function to handle responses by the subject
|
||||||
var after_response = function (info) {
|
var after_response = (info) => {
|
||||||
// after a valid response, the stimulus will have the CSS class 'responded'
|
// after a valid response, the stimulus will have the CSS class 'responded'
|
||||||
// which can be used to provide visual feedback that a response was recorded
|
// which can be used to provide visual feedback that a response was recorded
|
||||||
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className +=
|
display_element.querySelector("#jspsych-video-keyboard-response-stimulus").className +=
|
||||||
@ -292,9 +292,7 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
video_element.src = video_preload_blob;
|
video_element.src = video_preload_blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
video_element.onended = function () {
|
video_element.onended = () => {
|
||||||
if (trial.trial_ends_after_video) {
|
if (trial.trial_ends_after_video) {
|
||||||
end_trial();
|
end_trial();
|
||||||
} else if (!trial.response_allowed_while_playing) {
|
} else if (!trial.response_allowed_while_playing) {
|
||||||
@ -284,7 +284,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
// before showing and playing, so that the video doesn't automatically show the first frame
|
// before showing and playing, so that the video doesn't automatically show the first frame
|
||||||
if (trial.start !== null) {
|
if (trial.start !== null) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
video_element.onseeked = function () {
|
video_element.onseeked = () => {
|
||||||
video_element.style.visibility = "visible";
|
video_element.style.visibility = "visible";
|
||||||
video_element.muted = false;
|
video_element.muted = false;
|
||||||
if (trial.autoplay) {
|
if (trial.autoplay) {
|
||||||
@ -292,11 +292,11 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
} else {
|
} else {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
}
|
}
|
||||||
video_element.onseeked = function () {};
|
video_element.onseeked = () => {};
|
||||||
};
|
};
|
||||||
video_element.onplaying = function () {
|
video_element.onplaying = () => {
|
||||||
video_element.currentTime = trial.start;
|
video_element.currentTime = trial.start;
|
||||||
video_element.onplaying = function () {};
|
video_element.onplaying = () => {};
|
||||||
};
|
};
|
||||||
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
|
||||||
// change current time, then show/unmute
|
// change current time, then show/unmute
|
||||||
@ -306,7 +306,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
if (trial.stop !== null) {
|
if (trial.stop !== null) {
|
||||||
video_element.addEventListener("timeupdate", function (e) {
|
video_element.addEventListener("timeupdate", (e) => {
|
||||||
var currenttime = video_element.currentTime;
|
var currenttime = video_element.currentTime;
|
||||||
if (currenttime >= trial.stop) {
|
if (currenttime >= trial.stop) {
|
||||||
video_element.pause();
|
video_element.pause();
|
||||||
@ -356,7 +356,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
.pause();
|
.pause();
|
||||||
display_element.querySelector<HTMLVideoElement>(
|
display_element.querySelector<HTMLVideoElement>(
|
||||||
"#jspsych-video-slider-response-stimulus-video"
|
"#jspsych-video-slider-response-stimulus-video"
|
||||||
).onended = function () {};
|
).onended = () => {};
|
||||||
|
|
||||||
// gather the data to store for the trial
|
// gather the data to store for the trial
|
||||||
var trial_data = {
|
var trial_data = {
|
||||||
@ -376,7 +376,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
display_element
|
display_element
|
||||||
.querySelector("#jspsych-video-slider-response-next")
|
.querySelector("#jspsych-video-slider-response-next")
|
||||||
.addEventListener("click", function () {
|
.addEventListener("click", () => {
|
||||||
// measure response time
|
// measure response time
|
||||||
var endTime = performance.now();
|
var endTime = performance.now();
|
||||||
response.rt = Math.round(endTime - startTime);
|
response.rt = Math.round(endTime - startTime);
|
||||||
@ -407,9 +407,7 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
// end trial if time limit is set
|
// end trial if time limit is set
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
||||||
end_trial();
|
|
||||||
}, trial.trial_duration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,14 +421,14 @@ class VirtualChinrestPlugin implements JsPsychPlugin<Info> {
|
|||||||
function animateBall() {
|
function animateBall() {
|
||||||
window.ball
|
window.ball
|
||||||
.animate(7000)
|
.animate(7000)
|
||||||
.during(function (pos) {
|
.during((pos) => {
|
||||||
let moveX = -pos * blindspot_config_data["ballX"];
|
let moveX = -pos * blindspot_config_data["ballX"];
|
||||||
window.moveX = moveX;
|
window.moveX = moveX;
|
||||||
let moveY = 0;
|
let moveY = 0;
|
||||||
window.ball.attr({ transform: "translate(" + moveX + "," + moveY + ")" }); //jqueryToVanilla: el.getAttribute('');
|
window.ball.attr({ transform: "translate(" + moveX + "," + moveY + ")" }); //jqueryToVanilla: el.getAttribute('');
|
||||||
})
|
})
|
||||||
.loop(true, false)
|
.loop(true, false)
|
||||||
.after(function () {
|
.after(() => {
|
||||||
animateBall();
|
animateBall();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
"px;'></img>";
|
"px;'></img>";
|
||||||
|
|
||||||
// wait
|
// wait
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
// after wait is over
|
// after wait is over
|
||||||
show_search_array();
|
show_search_array();
|
||||||
}, trial.fixation_duration);
|
}, trial.fixation_duration);
|
||||||
@ -262,7 +262,7 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (trial.trial_duration !== null) {
|
if (trial.trial_duration !== null) {
|
||||||
this.jsPsych.pluginAPI.setTimeout(function () {
|
this.jsPsych.pluginAPI.setTimeout(() => {
|
||||||
if (!trial_over) {
|
if (!trial_over) {
|
||||||
this.jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
|
this.jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ class WebgazerCalibratePlugin implements JsPsychPlugin<Info> {
|
|||||||
|
|
||||||
if (trial.calibration_mode == "click") {
|
if (trial.calibration_mode == "click") {
|
||||||
pt_dom.style.cursor = "pointer";
|
pt_dom.style.cursor = "pointer";
|
||||||
pt_dom.addEventListener("click", function () {
|
pt_dom.addEventListener("click", () => {
|
||||||
next_calibration_point();
|
next_calibration_point();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ class WebgazerInitCameraPlugin implements JsPsychPlugin<Info> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector("#jspsych-wg-cont").addEventListener("click", function () {
|
document.querySelector("#jspsych-wg-cont").addEventListener("click", () => {
|
||||||
if (observer) {
|
if (observer) {
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ class WebgazerValidatePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculateGazeCentroid(gazeData) {
|
function calculateGazeCentroid(gazeData) {
|
||||||
var x_diff_m = gazeData.reduce(function (accumulator, currentValue, index) {
|
var x_diff_m = gazeData.reduce((accumulator, currentValue, index) => {
|
||||||
accumulator += currentValue.dx;
|
accumulator += currentValue.dx;
|
||||||
if (index == gazeData.length - 1) {
|
if (index == gazeData.length - 1) {
|
||||||
return accumulator / gazeData.length;
|
return accumulator / gazeData.length;
|
||||||
@ -324,7 +324,7 @@ class WebgazerValidatePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
var y_diff_m = gazeData.reduce(function (accumulator, currentValue, index) {
|
var y_diff_m = gazeData.reduce((accumulator, currentValue, index) => {
|
||||||
accumulator += currentValue.dy;
|
accumulator += currentValue.dy;
|
||||||
if (index == gazeData.length - 1) {
|
if (index == gazeData.length - 1) {
|
||||||
return accumulator / gazeData.length;
|
return accumulator / gazeData.length;
|
||||||
@ -334,9 +334,7 @@ class WebgazerValidatePlugin implements JsPsychPlugin<Info> {
|
|||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
var median_distance = median(
|
var median_distance = median(
|
||||||
gazeData.map(function (x) {
|
gazeData.map((x) => Math.sqrt(Math.pow(x.dx - x_diff_m, 2) + Math.pow(x.dy - y_diff_m, 2)))
|
||||||
return Math.sqrt(Math.pow(x.dx - x_diff_m, 2) + Math.pow(x.dy - y_diff_m, 2));
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -347,10 +345,8 @@ class WebgazerValidatePlugin implements JsPsychPlugin<Info> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculatePercentInROI(gazeData) {
|
function calculatePercentInROI(gazeData) {
|
||||||
var distances = gazeData.map(function (p) {
|
var distances = gazeData.map((p) => Math.sqrt(Math.pow(p.dx, 2) + Math.pow(p.dy, 2)));
|
||||||
return Math.sqrt(Math.pow(p.dx, 2) + Math.pow(p.dy, 2));
|
var sum_in_roi = distances.reduce((accumulator, currentValue) => {
|
||||||
});
|
|
||||||
var sum_in_roi = distances.reduce(function (accumulator, currentValue) {
|
|
||||||
if (currentValue <= trial.roi_radius) {
|
if (currentValue <= trial.roi_radius) {
|
||||||
accumulator++;
|
accumulator++;
|
||||||
}
|
}
|
||||||
@ -371,21 +367,11 @@ class WebgazerValidatePlugin implements JsPsychPlugin<Info> {
|
|||||||
for (var j = 1; j < gazeData[i].length; j++) {
|
for (var j = 1; j < gazeData[i].length; j++) {
|
||||||
t_diff.push(gazeData[i][j].t - gazeData[i][j - 1].t);
|
t_diff.push(gazeData[i][j].t - gazeData[i][j - 1].t);
|
||||||
}
|
}
|
||||||
mean_diff.push(
|
mean_diff.push(t_diff.reduce((a, b) => a + b, 0) / t_diff.length);
|
||||||
t_diff.reduce(function (a, b) {
|
|
||||||
return a + b;
|
|
||||||
}, 0) / t_diff.length
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mean_diff.length > 0) {
|
if (mean_diff.length > 0) {
|
||||||
return (
|
return 1000 / (mean_diff.reduce((a, b) => a + b, 0) / mean_diff.length);
|
||||||
1000 /
|
|
||||||
(mean_diff.reduce(function (a, b) {
|
|
||||||
return a + b;
|
|
||||||
}, 0) /
|
|
||||||
mean_diff.length)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user