diff --git a/jspsych-animation.js b/jspsych-animation.js index 84f4b2c4..d8dbae15 100644 --- a/jspsych-animation.js +++ b/jspsych-animation.js @@ -1,7 +1,5 @@ // jsPsych plugin for showing animations // Josh de Leeuw -// -// dependency: jquery.canimate.js function animation_create(params) { @@ -11,17 +9,9 @@ function animation_create(params) { trials[i] = {}; trials[i]["type"] = "animate"; - //img_path needs to be of the form: - // "path/PREFIX####.EXT - //substituting whatever values you want for PREFIX and EXT - //and putting the correct path information - //PREFIX needs to match the img_prefix param. - trials[i]["img_path"] = stims[i]; - trials[i]["img_prefix"] = params["prefix"]; - trials[i]["fps"] = params["fps"]; - // frames is how many images are in the animation - trials[i]["frames"] = params["frames"]; - trials[i]["loop"] = params["loop"]; + trials[i]["stims"] = stims[i]; + trials[i]["frame_time"] = params["frame_time"]; + trials[i]["repetitions"] = params["repetitions"]; trials[i]["timing"] = params["timing"]; } return trials; @@ -29,19 +19,33 @@ function animation_create(params) function animation_trial($this, block, trial, part) { - var base_img = document.createElement('img'); - base_img.setAttribute('src',trial.img_path); - base_img.setAttribute('id','animate'); - $this.append(base_img); - // using the cAnimate jQuery plugin - $('#animate').canimate({ - totalFrames: trial.frames, - imagePrefix: trial.img_prefix, - fps: trial.fps, - preload:true, - loop: trials.loop - }); - - setTimeout(function(b){$('#animate').remove(); b.next();}, trial.timing[0], block); - + animate_frame = -1; + reps = 0; + switch(part) + { + case 1: + animate_interval = setInterval(function(){ + showImage = true; + $('.animate').remove(); + animate_frame++; + if(animate_frame == trial.stims.length) + { + animate_frame = 0; + reps++; + if(reps >= trial.repetitions) + { + animation_trial($this, block, trial, part + 1); + clearInterval(animate_interval); + showImage = false; + } + } + if(showImage){ + $.fn.jsPsych.showImage($this, trial.stims[animate_frame], 'animate'); + } + }, trial.frame_time); + break; + case 2: + setTimeout(function(b){ b.next(); }, trial.timing[0], block); + break; + } } \ No newline at end of file diff --git a/jspsych-samedifferent.js b/jspsych-samedifferent.js index 63e30410..1b7f4add 100755 --- a/jspsych-samedifferent.js +++ b/jspsych-samedifferent.js @@ -9,6 +9,13 @@ function sd_create(params) trials[i]["a_path"] = sd_stims[i][0]; trials[i]["b_path"] = sd_stims[i][1]; trials[i]["timing"] = params["timing"]; + trials[i]["answer"] = params["answer"]; + if(params["prompt"] != undefined){ + trials[i]["prompt"] = params["prompt"]; + } + if(params["data"]!=undefined){ + trials[i]["data"] = params["data"][i]; + } } return trials; } @@ -25,27 +32,40 @@ function sd_trial($this, block, trial, part) setTimeout(sd_trial, trial.timing[1], $this, block, trial, part + 1); break; case 3: - startTime = (new Date()).getTime(); $.fn.jsPsych.showImage($this, trial.b_path, 'sd'); + if(trial.timing[3]!=undefined){ + setTimeout(sd_trial, trial.timing[3], $this, block, trial, part + 1); + } else { + sd_trial($this, block, trial, part + 1); + } + break; + case 4: + if(trial.timing[3]!=undefined){ + $('.sd').remove(); + $this.html(trial.prompt); + } + startTime = (new Date()).getTime(); var resp_func = function(e) { var flag = false; var correct = false; if(e.which=='80') // 'p' key -- different { flag = true; - if(trial.a_path!=trial.b_path) { correct = true; } + if(trial.answer == "different") { correct = true; } } else if(e.which=='81') // 'q' key -- same { flag = true; - if(trial.a_path==trial.b_path){ correct = true; } + if(trial.answer == "same"){ correct = true; } } if(flag) { endTime = (new Date()).getTime(); rt = (endTime-startTime); - block.data[block.trial_idx] = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path} + var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key": e.which} + block.data[block.trial_idx] = $.extend({},trial_data,trial.data); $(document).unbind('keyup',resp_func); $('.sd').remove(); + $this.html(''); setTimeout(function(b){b.next();}, trial.timing[2], block); } } diff --git a/jspsych-text.js b/jspsych-text.js index 8c984a18..f27e9e7b 100755 --- a/jspsych-text.js +++ b/jspsych-text.js @@ -6,6 +6,7 @@ function text_create(params) trials[i] = {}; trials[i]["type"] = "text"; trials[i]["text"] = params.text[i]; + trials[i]["cont_key"] = params.cont_key; trials[i]["timing"] = params.timing; } return trials; @@ -15,7 +16,7 @@ function text_trial($this, block, trial, part) { $this.html(trial.text); var key_listener = function(e) { - if(e.which=="80") // 'spacebar' + if(e.which==trial.cont_key) { flag = true; $(document).unbind('keyup',key_listener); diff --git a/jspsych.js b/jspsych.js index 25765d5f..c1d3f5da 100755 --- a/jspsych.js +++ b/jspsych.js @@ -105,11 +105,7 @@ $.fn.jsPsych.defaults = { // overall experiment parameters experiment_structure: [], - plugins: [ - {"type": "sim", "createFunc": similarity_create, "trialFunc": similarity_trial}, - {"type": "sd", "createFunc": sd_create, "trialFunc": sd_trial}, - {"type": "text", "createFunc": text_create, "trialFunc": text_trial}, - {"type": "xab", "createFunc": xab_create, "trialFunc": xab_trial}] + plugins: [] }; // // useful helper functions for multiple plugins //