diff --git a/plugins/jspsych-singleimage-keyresponse.js b/plugins/jspsych-singleimage-keyresponse.js
index 9abb74f5..8039865a 100644
--- a/plugins/jspsych-singleimage-keyresponse.js
+++ b/plugins/jspsych-singleimage-keyresponse.js
@@ -18,8 +18,11 @@
trials[i]["type"] = "singleimage_keyresponse";
trials[i]["a_path"] = stims[i];
trials[i]["choices"] = params["choices"];
+ // option to show image for fixed time interval, ignoring key responses
+ trials[i]["continue_afer_response"] = params["continue_after_response"] || true;
// timing parameters
- trials[i]["timing_stim"] = params["timing_stim"]; // if undefined, then show indefinitely
+ trials[i]["timing_stim"] = params["timing_stim"] || -1; // if -1, then show indefinitely
+ trials[i]["timing_response"] = params["timing_response"] || -1; // if -1, then wait for response forever
trials[i]["timing_post_trial"] = params["timing_post_trial"] || 1000;
// optional parameters
if(params["prompt"] != undefined){
@@ -33,25 +36,34 @@
}
var sikr_trial_complete = false;
- plugin.trial = function($this, block, trial, part)
+
+ plugin.trial = function(display_element, block, trial, part)
{
switch(part){
case 1:
+ key_press = -1;
sikr_trial_complete = false;
startTime = (new Date()).getTime();
- $this.append($('
', {
+ display_element.append($('
', {
"src": trial.a_path,
"id": 'sikr_img'
}));
//show prompt here
if(trial.prompt != undefined){
- $this.append(trial.prompt);
+ display_element.append(trial.prompt);
+ }
+
+ var cont_function = function(){
+ endTime = (new Date()).getTime();
+ rt = (endTime-startTime);
+ sikr_trial_complete = true;
+ plugin.trial(display_element, block, trial, part+1);
}
// hide image if timing is set
- if(trial.timing_stim != undefined){
+ if(trial.timing_stim > 0){
setTimeout(function(){
if(!sikr_trial_complete){
$('#sikr_img').css('visibility','hidden');
@@ -71,18 +83,40 @@
}
if(flag)
{
- endTime = (new Date()).getTime();
- rt = (endTime-startTime);
-
- var trial_data = {"rt": rt, "a_path": trial.a_path, "key_press": e.which}
- block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
- $(document).unbind('keyup',resp_func);
- $this.html('');
- sikr_trial_complete = true;
- setTimeout(function(){block.next();}, trial.timing_post_trial);
+ key_press = e.which;
+
+ // after a valid response, the image will have the CSS class 'responded'
+ // which can be used to provide visual feedback that a response was recorded
+ $("#sikr_img").addClass('responded');
+
+ if(trial.continue_after_response){
+ // response triggers the next trial in this case.
+ // if hide_image_after_response is true, then next
+ // trial should be triggered by timeout function below.
+ cont_function();
+ }
}
}
+
$(document).keyup(resp_func);
+
+ // end trial if time limit is set
+ if(trial.timing_response > 0)
+ {
+ setTimeout(function(){
+ if(!sikr_trial_complete){
+ cont_function();
+ }
+ }, trial.timing_response);
+ }
+
+ break;
+ case 2:
+ var trial_data = {"trial_type": "singleimage_keyresponse", "rt": rt, "a_path": trial.a_path, "key_press": key_press}
+ block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
+ $(document).unbind('keyup',resp_func);
+ display_element.html('');
+ setTimeout(function(){block.next();}, trial.timing_post_trial);
break;
}
}