mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
added options to categorize-animation
can now set the number of repetitions of the animation, and choose to allow user input before the animation is complete.
This commit is contained in:
parent
871ba7a897
commit
caaab0b84f
@ -21,6 +21,8 @@
|
|||||||
trials[i]["choices"] = params["choices"];
|
trials[i]["choices"] = params["choices"];
|
||||||
trials[i]["correct_text"] = params["correct_text"];
|
trials[i]["correct_text"] = params["correct_text"];
|
||||||
trials[i]["incorrect_text"] = params["incorrect_text"];
|
trials[i]["incorrect_text"] = params["incorrect_text"];
|
||||||
|
trials[i]["allow_response_before_complete"] = params["allow_response_before_complete"] || false;
|
||||||
|
trials[i]["reps"] = params["reps"] || -1; // default of -1, which allows indefinitely
|
||||||
if(params["prompt"] != undefined){
|
if(params["prompt"] != undefined){
|
||||||
trials[i]["prompt"] = params["prompt"];
|
trials[i]["prompt"] = params["prompt"];
|
||||||
}
|
}
|
||||||
@ -35,8 +37,12 @@
|
|||||||
{
|
{
|
||||||
var animate_frame = -1;
|
var animate_frame = -1;
|
||||||
var reps = 0;
|
var reps = 0;
|
||||||
|
|
||||||
|
var showAnimation = true;
|
||||||
|
|
||||||
var responded = false;
|
var responded = false;
|
||||||
var timeoutSet = false;
|
var timeoutSet = false;
|
||||||
|
|
||||||
switch(part)
|
switch(part)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@ -50,24 +56,44 @@
|
|||||||
{
|
{
|
||||||
animate_frame = 0;
|
animate_frame = 0;
|
||||||
reps++;
|
reps++;
|
||||||
|
// check if reps complete //
|
||||||
|
if(trial.reps != -1 && reps >= trial.reps) {
|
||||||
|
// done with animation
|
||||||
|
showAnimation = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( showAnimation ) {
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": trial.stims[animate_frame],
|
"src": trial.stims[animate_frame],
|
||||||
"class": 'animate'
|
"class": 'animate'
|
||||||
}));
|
}));
|
||||||
if(!responded) {
|
}
|
||||||
|
|
||||||
|
if(!responded && trial.allow_response_before_complete) {
|
||||||
|
// in here if the user can respond before the animation is done
|
||||||
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
||||||
|
} else if(!responded) {
|
||||||
|
// in here if the user has to wait to respond until animation is done.
|
||||||
|
// if this is the case, don't show the prompt until the animation is over.
|
||||||
|
if( !showAnimation )
|
||||||
|
{
|
||||||
|
if(trial.prompt != undefined) { $this.append(trial.prompt); }
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// user has responded if we get here.
|
||||||
|
|
||||||
// show feedback
|
// show feedback
|
||||||
var atext = "";
|
var feedback_text = "";
|
||||||
if(block.data[block.trial_idx]["correct"])
|
if(block.data[block.trial_idx]["correct"])
|
||||||
{
|
{
|
||||||
atext = trial.correct_text.replace("&ANS&", trial.text_answer);
|
feedback_text = trial.correct_text.replace("&ANS&", trial.text_answer);
|
||||||
} else {
|
} else {
|
||||||
atext = trial.incorrect_text.replace("&ANS&", trial.text_answer);
|
feedback_text = trial.incorrect_text.replace("&ANS&", trial.text_answer);
|
||||||
}
|
}
|
||||||
$this.append(atext);
|
$this.append(feedback_text);
|
||||||
|
|
||||||
|
// set timeout to clear feedback
|
||||||
if(!timeoutSet)
|
if(!timeoutSet)
|
||||||
{
|
{
|
||||||
timeoutSet = true;
|
timeoutSet = true;
|
||||||
@ -82,6 +108,11 @@
|
|||||||
|
|
||||||
var resp_func = function(e) {
|
var resp_func = function(e) {
|
||||||
|
|
||||||
|
if(!trial.allow_response_before_complete && showAnimation)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var flag = false; // valid keystroke?
|
var flag = false; // valid keystroke?
|
||||||
var correct = false; // correct answer?
|
var correct = false; // correct answer?
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user