Added optional callback methods for tiral start and trial finish events in core library.

Can now pass in functions to the core library on init() so that a
function can be called at the start or end of every trial.
This commit is contained in:
Josh de Leeuw 2012-07-17 18:05:09 -04:00
parent b33ab88b22
commit 19983090a8

View File

@ -25,14 +25,22 @@
var initialized = false; var initialized = false;
// target DOM element // target DOM element
var DOM_target; var DOM_target;
// trial start callback method
var on_trial_start;
// trial finish callback method
var on_trial_finish;
// //
// public methods // public methods
// //
core.init = function($this, options){ core.init = function($this, options){
var defaults = {
'on_trial_start': function(){ return undefined; }
'on_trial_finish': function() { return undefined; }
}
// import options // import options
opts = $.extend({}, jsPsych.defaults, options); opts = $.extend({}, defaults, options);
// set target // set target
DOM_target = $this; DOM_target = $this;
@ -147,7 +155,14 @@
function do_trial(block, trial) function do_trial(block, trial)
{ {
// call on_trial_start()
on_trial_start();
// execute trial method
jsPsych[trial.type]["trial"].call(this, DOM_target, block, trial, 1); jsPsych[trial.type]["trial"].call(this, DOM_target, block, trial, 1);
// call on_trial_finish()
on_trial_finish();
} }
return core; return core;