diff --git a/jspsych-categorize-feedback.js b/jspsych-categorize-feedback.js index 8ad7f336..5490b716 100644 --- a/jspsych-categorize-feedback.js +++ b/jspsych-categorize-feedback.js @@ -5,113 +5,121 @@ // option to keep stim on screen during feedback // way to provide corrective feedback -function cf_create(params) -{ - cf_stims = params["stimuli"]; - trials = new Array(cf_stims.length); - for(var i = 0; i < trials.length; i++) - { - trials[i] = {}; - trials[i]["type"] = "cf"; - trials[i]["a_path"] = cf_stims[i]; - trials[i]["timing"] = params["timing"]; - trials[i]["key_answer"] = params["key_answer"][i]; - trials[i]["text_answer"] = params["text_answer"][i]; - trials[i]["choices"] = params["choices"]; - trials[i]["correct_text"] = params["correct_text"]; - trials[i]["incorrect_text"] = params["incorrect_text"]; - trials[i]["show_stim_feedback"] = params["show_stim_feedback"]; - if(params["prompt"] != undefined){ - trials[i]["prompt"] = params["prompt"]; +(function( $ ) { + $.fn.jsPsych.categorize-feedback = (function(){ + + var plugin = {}; + + plugin.create = function(params) { + cf_stims = params["stimuli"]; + trials = new Array(cf_stims.length); + for(var i = 0; i < trials.length; i++) + { + trials[i] = {}; + trials[i]["type"] = "cf"; + trials[i]["a_path"] = cf_stims[i]; + trials[i]["timing"] = params["timing"]; + trials[i]["key_answer"] = params["key_answer"][i]; + trials[i]["text_answer"] = params["text_answer"][i]; + trials[i]["choices"] = params["choices"]; + trials[i]["correct_text"] = params["correct_text"]; + trials[i]["incorrect_text"] = params["incorrect_text"]; + trials[i]["show_stim_feedback"] = params["show_stim_feedback"]; + if(params["prompt"] != undefined){ + trials[i]["prompt"] = params["prompt"]; + } + if(params["data"]!=undefined){ + trials[i]["data"] = params["data"][i]; + } + } + return trials; } - if(params["data"]!=undefined){ - trials[i]["data"] = params["data"][i]; - } - } - return trials; -} -function cf_trial($this, block, trial, part) -{ - switch(part){ - case 1: - p1_time = (new Date()).getTime(); - $this.append($('', { - "src": trial.a_path, - "class": 'cf' - })); - if(trial.timing[2]!=undefined){ - setTimeout(function(){cf_trial($this, block, trial, part + 1);}, trial.timing[2]); - } else { - //show prompt here - $this.append(trial.prompt); - cf_trial($this, block, trial, part + 1); - } - break; - case 2: - p2_time = (new Date()).getTime(); - if(trial.timing[2]!=undefined){ - $('.cf').remove(); - $this.append(trial.prompt); - } - startTime = (new Date()).getTime(); - var resp_func = function(e) { - var flag = false; - var correct = false; - if(e.which==trial.key_answer) // correct category - { - flag = true; - correct = true; - } - else - { - // check if the key is any of the options, or if it is an accidental keystroke - for(var i=0;i', { + "src": trial.a_path, + "class": 'cf' + })); + if(trial.timing[2]!=undefined){ + setTimeout(function(){cf_trial($this, block, trial, part + 1);}, trial.timing[2]); + } else { + //show prompt here + $this.append(trial.prompt); + cf_trial($this, block, trial, part + 1); + } + break; + case 2: + p2_time = (new Date()).getTime(); + if(trial.timing[2]!=undefined){ + $('.cf').remove(); + $this.append(trial.prompt); + } + startTime = (new Date()).getTime(); + var resp_func = function(e) { + var flag = false; + var correct = false; + if(e.which==trial.key_answer) // correct category + { flag = true; - correct = false; + correct = true; + } + else + { + // check if the key is any of the options, or if it is an accidental keystroke + for(var i=0;i', { + "src": trial.a_path, + "class": 'cf' + })); + } + // give feedback + var atext = ""; + if(block.data[block.trial_idx]["correct"]) + { + atext = trial.correct_text.replace("&ANS&", trial.text_answer); + } else { + atext = trial.incorrect_text.replace("&ANS&", trial.text_answer); + } + $this.append(atext); + setTimeout(function(){cf_trial($this, block, trial, part + 1);}, trial.timing[0]); + break; + case 4: + $this.html(""); + setTimeout(function(){block.next();}, trial.timing[1]); + break; } - $(document).keyup(resp_func); - break; - case 3: - if(trial.show_stim_feedback) - { - $this.append($('', { - "src": trial.a_path, - "class": 'cf' - })); - } - // give feedback - var atext = ""; - if(block.data[block.trial_idx]["correct"]) - { - atext = trial.correct_text.replace("&ANS&", trial.text_answer); - } else { - atext = trial.incorrect_text.replace("&ANS&", trial.text_answer); - } - $this.append(atext); - setTimeout(function(){cf_trial($this, block, trial, part + 1);}, trial.timing[0]); - break; - case 4: - $this.html(""); - setTimeout(function(){block.next();}, trial.timing[1]); - break; - } -} + } + + return plugin; + })(); +})(jQuery); \ No newline at end of file diff --git a/jspsych-categorize-unknown.js b/jspsych-categorize-unknown.js index ed68e8f1..ad45b72a 100644 --- a/jspsych-categorize-unknown.js +++ b/jspsych-categorize-unknown.js @@ -1,75 +1,83 @@ // timing parameters: [intertrial gap, optional length to display target] // if optional length to display target is missing, then target is displayed until subject responds. -function cu_create(params) -{ - cu_stims = params["stimuli"]; - trials = new Array(cu_stims.length); - for(var i = 0; i < trials.length; i++) - { - trials[i] = {}; - trials[i]["type"] = "cu"; - trials[i]["a_path"] = cu_stims[i]; - trials[i]["timing"] = params["timing"]; - trials[i]["choices"] = params["choices"]; - if(params["prompt"] != undefined){ - trials[i]["prompt"] = params["prompt"]; +(function( $ ) { + $.fn.jsPsych.categorize-unknown = (function(){ + + var plugin = {}; + + plugin.create = function(params) { + cu_stims = params["stimuli"]; + trials = new Array(cu_stims.length); + for(var i = 0; i < trials.length; i++) + { + trials[i] = {}; + trials[i]["type"] = "cu"; + trials[i]["a_path"] = cu_stims[i]; + trials[i]["timing"] = params["timing"]; + trials[i]["choices"] = params["choices"]; + if(params["prompt"] != undefined){ + trials[i]["prompt"] = params["prompt"]; + } + if(params["data"]!=undefined){ + trials[i]["data"] = params["data"][i]; + } + } + return trials; } - if(params["data"]!=undefined){ - trials[i]["data"] = params["data"][i]; - } - } - return trials; -} -function cu_trial($this, block, trial, part) -{ - switch(part){ - case 1: - p1_time = (new Date()).getTime(); - $this.append($('', { - "src": trial.a_path, - "class": 'cu' - })); - if(trial.timing[1]!=undefined){ - setTimeout(function(){cu_trial($this, block, trial, part + 1);}, trial.timing[1]); - } else { - //show prompt here - $this.append(trial.prompt); - cu_trial($this, block, trial, part + 1); - } - break; - case 2: - p2_time = (new Date()).getTime(); - if(trial.timing[1]!=undefined){ - $('.cu').remove(); - $this.append(trial.prompt); - } - startTime = (new Date()).getTime(); - var resp_func = function(e) { - var flag = false; - // check if the key is any of the options, or if it is an accidental keystroke - for(var i=0;i', { + "src": trial.a_path, + "class": 'cu' + })); + if(trial.timing[1]!=undefined){ + setTimeout(function(){cu_trial($this, block, trial, part + 1);}, trial.timing[1]); + } else { + //show prompt here + $this.append(trial.prompt); + cu_trial($this, block, trial, part + 1); } - } - if(flag) - { - endTime = (new Date()).getTime(); - rt = (endTime-startTime); - stim1_time = (p2_time-p1_time); - var trial_data = {"rt": rt, "a_path": trial.a_path, "key_press": e.which, "stim1_time": stim1_time} - block.data[block.trial_idx] = $.extend({},trial_data,trial.data); - $(document).unbind('keyup',resp_func); - $this.html(''); - setTimeout(function(){block.next();}, trial.timing[0]); - } + break; + case 2: + p2_time = (new Date()).getTime(); + if(trial.timing[1]!=undefined){ + $('.cu').remove(); + $this.append(trial.prompt); + } + startTime = (new Date()).getTime(); + var resp_func = function(e) { + var flag = false; + // check if the key is any of the options, or if it is an accidental keystroke + for(var i=0;i', { - "src": trial.a_path, - "class": 'sd' - })); - setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[0]); - break; - case 2: - p2_time = (new Date()).getTime(); - $('.sd').remove(); - setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[1]); - break; - case 3: - p3_time = (new Date()).getTime(); - $this.append($('', { - "src": trial.b_path, - "class": 'sd' - })); - if(trial.timing[3]!=undefined){ - setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[3]); - } else { - sd_trial($this, block, trial, part + 1); - } - break; - case 4: - p4_time = (new Date()).getTime(); - 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 -- same - { - flag = true; - if(trial.answer == "same") { correct = true; } - } else if(e.which=='81') // 'q' key -- different - { - flag = true; - if(trial.answer == "different"){ correct = true; } + var plugin = {}; + + plugin.create = function(params) { + sd_stims = params["stimuli"]; + trials = new Array(sd_stims.length); + for(var i = 0; i < trials.length; i++) + { + trials[i] = {}; + trials[i]["type"] = "sd"; + 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"][i]; + if(params["prompt"] != undefined){ + trials[i]["prompt"] = params["prompt"]; } - if(flag) - { - endTime = (new Date()).getTime(); - rt = (endTime-startTime); - stim1_time = (p2_time-p1_time); - isi_time = (p3_time-p2_time); - stim2_time = (p4_time-p3_time); - var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "stim2_time":stim2_time, "isi_time":isi_time} - block.data[block.trial_idx] = $.extend({},trial_data,trial.data); - $(document).unbind('keyup',resp_func); + if(params["data"]!=undefined){ + trials[i]["data"] = params["data"][i]; + } + } + return trials; + } + + plugin.trial = function($this, block, trial, part) + { + switch(part){ + case 1: + p1_time = (new Date()).getTime(); + $this.append($('', { + "src": trial.a_path, + "class": 'sd' + })); + setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[0]); + break; + case 2: + p2_time = (new Date()).getTime(); $('.sd').remove(); - $this.html(''); - setTimeout(function(){block.next();}, trial.timing[2]); - } + setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[1]); + break; + case 3: + p3_time = (new Date()).getTime(); + $this.append($('', { + "src": trial.b_path, + "class": 'sd' + })); + if(trial.timing[3]!=undefined){ + setTimeout(function(){sd_trial($this, block, trial, part + 1);}, trial.timing[3]); + } else { + sd_trial($this, block, trial, part + 1); + } + break; + case 4: + p4_time = (new Date()).getTime(); + 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 -- same + { + flag = true; + if(trial.answer == "same") { correct = true; } + } else if(e.which=='81') // 'q' key -- different + { + flag = true; + if(trial.answer == "different"){ correct = true; } + } + if(flag) + { + endTime = (new Date()).getTime(); + rt = (endTime-startTime); + stim1_time = (p2_time-p1_time); + isi_time = (p3_time-p2_time); + stim2_time = (p4_time-p3_time); + var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "stim2_time":stim2_time, "isi_time":isi_time} + block.data[block.trial_idx] = $.extend({},trial_data,trial.data); + $(document).unbind('keyup',resp_func); + $('.sd').remove(); + $this.html(''); + setTimeout(function(){block.next();}, trial.timing[2]); + } + } + $(document).keyup(resp_func); + break; } - $(document).keyup(resp_func); - break; - } -} + } + + return plugin; + })(); +}) (jQuery); \ No newline at end of file diff --git a/jspsych-similarity.js b/jspsych-similarity.js index 33bbf3b0..ea533a28 100755 --- a/jspsych-similarity.js +++ b/jspsych-similarity.js @@ -1,60 +1,68 @@ -function similarity_create(params) -{ - sim_stims = params["stimuli"]; - trials = new Array(sim_stims.length); - for(var i = 0; i < trials.length; i++) - { - trials[i] = {}; - trials[i]["type"] = "sim"; - trials[i]["a_path"] = sim_stims[i][0]; - trials[i]["b_path"] = sim_stims[i][1]; - trials[i]["timing"] = params["timing"]; - } - return trials; -} - -function similarity_trial($this, block, trial, part) -{ - switch(part){ - case 1: - images = [trial.a_path, trial.b_path]; - if(Math.floor(Math.random()*2)==0){ - images = [trial.b_path, trial.a_path]; +(function( $ ) { + $.fn.jsPsych.text = (function(){ + + var plugin = {}; + + plugin.create = function(params) { + sim_stims = params["stimuli"]; + trials = new Array(sim_stims.length); + for(var i = 0; i < trials.length; i++) + { + trials[i] = {}; + trials[i]["type"] = "sim"; + trials[i]["a_path"] = sim_stims[i][0]; + trials[i]["b_path"] = sim_stims[i][1]; + trials[i]["timing"] = params["timing"]; } - // show the images - $this.append($('', { - "src": images[0], - "class": 'sim' - })); - $this.append($('', { - "src": images[1], - "class": 'sim' - })); + return trials; + } - // create slider - $this.append($('
', { "id": 'slider', "class": 'sim' })); - $("#slider").slider( - { - value:50, - min:0, - max:100, - step:1, - }); - - // create button - $this.append($('