fix timeout issue

issue #62
This commit is contained in:
Josh de Leeuw 2014-09-29 15:47:05 -04:00
parent 9b617435e8
commit e262c52ee9

View File

@ -46,8 +46,6 @@
return trials; return trials;
}; };
var xab_trial_complete = false;
plugin.trial = function(display_element, trial) { plugin.trial = function(display_element, trial) {
// if any trial variables are functions // if any trial variables are functions
@ -55,7 +53,9 @@
// it with the output of the function // it with the output of the function
trial = jsPsych.pluginAPI.normalizeTrialVariables(trial); trial = jsPsych.pluginAPI.normalizeTrialVariables(trial);
xab_trial_complete = false; // this array holds handlers from setTimeout calls
// that need to be cleared if the trial ends early
var setTimeoutHandlers = [];
// how we display the content depends on whether the content is // how we display the content depends on whether the content is
// HTML code or an image path. // HTML code or an image path.
@ -124,16 +124,19 @@
// if timing_ab is > 0, then we hide the stimuli after timing_ab milliseconds // if timing_ab is > 0, then we hide the stimuli after timing_ab milliseconds
if (trial.timing_ab > 0) { if (trial.timing_ab > 0) {
setTimeout(function() { setTimeoutHandlers.push(setTimeout(function() {
if (!xab_trial_complete) { $('.jspsych-xab-stimulus').css('visibility', 'hidden');
$('.jspsych-xab-stimulus').css('visibility', 'hidden'); }, trial.timing_ab));
}
}, trial.timing_ab);
} }
// create the function that triggers when a key is pressed. // create the function that triggers when a key is pressed.
var after_response = function(info) { var after_response = function(info) {
// kill any remaining setTimeout handlers
for (var i = 0; i < setTimeoutHandlers.length; i++) {
clearTimeout(setTimeoutHandlers[i]);
}
var correct = false; // true when the correct response is chosen var correct = false; // true when the correct response is chosen
if (info.key == trial.left_key) // 'q' key by default if (info.key == trial.left_key) // 'q' key by default