Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide_slider_while_playing parameter #2360

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/plugins/audio-slider-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
| trial_duration | numeric | null | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the subject's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial will wait for a response indefinitely. |
| response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force the subject to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. |
| response_allowed_while_playing | boolean | true | If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through, the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls). |
hide_slider_while_playing | boolean | false | If true, the slider will be hidden while the audio is playing, and will appear when the audio stops.|

## Data Generated

Expand Down
1 change: 1 addition & 0 deletions docs/plugins/video-slider-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ trial_ends_after_video | bool | false | If true, then the trial will end as soon
trial_duration | numeric | null | How long to wait for the subject to make a response before ending the trial in milliseconds. If the subject fails to make a response before this timer is reached, the subject's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial will wait for a response indefinitely.
response_ends_trial | boolean | true | If true, then the trial will end whenever the subject makes a response (assuming they make their response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force the subject to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
response_allowed_while_playing | boolean | true | If true, then responses are allowed while the video is playing. If false, then the video must finish playing before the slider is enabled and the trial can end via the next button click. Once the video has played all the way through, the slider is enabled and a response is allowed (including while the video is being re-played via on-screen playback controls).
hide_slider_while_playing | boolean | false | If true, the slider will be hidden while the video is playing, and will appear when the video stops.


## Data Generated
Expand Down
25 changes: 25 additions & 0 deletions packages/plugin-audio-slider-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ const info = <const>{
pretty_name: "Response allowed while playing",
default: true,
},
hide_slider_while_playing: {
type: ParameterType.BOOL,
pretty_name: "Hide slider while playing",
default: false
},
},
};

Expand Down Expand Up @@ -156,6 +161,10 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
audio.addEventListener("ended", enable_slider);
}

if (trial.hide_slider_while_playing) {
audio.addEventListener("ended", show_slider);
}

var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
html +=
'<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
Expand Down Expand Up @@ -283,6 +292,10 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
audio.play();
}

if (trial.hide_slider_while_playing) {
hide_slider();
}

// end trial if trial_duration is set
if (trial.trial_duration !== null) {
this.jsPsych.pluginAPI.setTimeout(() => {
Expand All @@ -293,6 +306,17 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
on_load();
};


function hide_slider() {
(document.getElementsByClassName("jspsych-slider")[0] as HTMLElement).style.display = "none";
(document.getElementById("jspsych-audio-slider-response-next") as HTMLElement).style.display = "none";
}

function show_slider(){
(document.getElementsByClassName("jspsych-slider")[0] as HTMLElement).style.display = "";
(document.getElementById("jspsych-audio-slider-response-next") as HTMLElement).style.display = "";
}

// function to enable slider after audio ends
function enable_slider() {
document.querySelector<HTMLInputElement>("#jspsych-audio-slider-response-response").disabled =
Expand All @@ -317,6 +341,7 @@ class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {

audio.removeEventListener("ended", end_trial);
audio.removeEventListener("ended", enable_slider);
audio.removeEventListener("ended", show_slider)

// save data
var trialdata = {
Expand Down
29 changes: 29 additions & 0 deletions packages/plugin-video-slider-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ const info = <const>{
pretty_name: "Response allowed while playing",
default: true,
},
hide_slider_while_playing: {
type: ParameterType.BOOL,
pretty_name: "Hide slider while playing",
default: false,
description: "If true the slider will be hidden while the video plays and it will appear when the video stops"
},
},
};

Expand Down Expand Up @@ -271,6 +277,10 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
}

video_element.onended = () => {
if(trial.hide_slider_while_playing) {
show_slider();
}

if (trial.trial_ends_after_video) {
end_trial();
} else if (!trial.response_allowed_while_playing) {
Expand Down Expand Up @@ -310,6 +320,10 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
var currenttime = video_element.currentTime;
if (currenttime >= trial.stop) {
video_element.pause();
if (trial.hide_slider_while_playing){
show_slider();
}

if (trial.trial_ends_after_video && !stopped) {
// this is to prevent end_trial from being called twice, because the timeupdate event
// can fire in quick succession
Expand All @@ -336,6 +350,11 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
.addEventListener("touchstart", enable_button);
}

if (trial.hide_slider_while_playing) {
hide_slider();
}


var startTime = performance.now();

// store response
Expand Down Expand Up @@ -405,6 +424,16 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
}
}

function hide_slider() {
(document.getElementsByClassName("jspsych-video-slider-response-container")[0] as HTMLElement).style.display = "none";
(document.getElementById("jspsych-video-slider-response-next") as HTMLElement).style.display = "none";
}

function show_slider() {
(document.getElementsByClassName("jspsych-video-slider-response-container")[0] as HTMLElement).style.display = "";
(document.getElementById("jspsych-video-slider-response-next") as HTMLElement).style.display = "";
}

// end trial if time limit is set
if (trial.trial_duration !== null) {
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
Expand Down