From caaab0b84fea4003eef6b2e67d24eaef8cb32f79 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Fri, 20 Jul 2012 12:02:42 -0400 Subject: [PATCH] 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. --- jspsych-categorize-animation.js | 49 +++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/jspsych-categorize-animation.js b/jspsych-categorize-animation.js index 00f32c75..0fcf70c6 100644 --- a/jspsych-categorize-animation.js +++ b/jspsych-categorize-animation.js @@ -21,6 +21,8 @@ trials[i]["choices"] = params["choices"]; trials[i]["correct_text"] = params["correct_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){ trials[i]["prompt"] = params["prompt"]; } @@ -35,8 +37,12 @@ { var animate_frame = -1; var reps = 0; + + var showAnimation = true; + var responded = false; var timeoutSet = false; + switch(part) { case 1: @@ -50,24 +56,44 @@ { animate_frame = 0; reps++; + // check if reps complete // + if(trial.reps != -1 && reps >= trial.reps) { + // done with animation + showAnimation = false; + } } - $this.append($('', { - "src": trial.stims[animate_frame], - "class": 'animate' - })); - if(!responded) { + if( showAnimation ) { + $this.append($('', { + "src": trial.stims[animate_frame], + "class": 'animate' + })); + } + + 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); } + } 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 { + // user has responded if we get here. + // show feedback - var atext = ""; + var feedback_text = ""; 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 { - 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) { timeoutSet = true; @@ -82,6 +108,11 @@ var resp_func = function(e) { + if(!trial.allow_response_before_complete && showAnimation) + { + return false; + } + var flag = false; // valid keystroke? var correct = false; // correct answer?