From 19983090a8e3cd6a5dd67a10c131964c94dac821 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Tue, 17 Jul 2012 18:05:09 -0400 Subject: [PATCH] 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. --- jspsych.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/jspsych.js b/jspsych.js index 838451b7..b987e97f 100755 --- a/jspsych.js +++ b/jspsych.js @@ -25,14 +25,22 @@ var initialized = false; // target DOM element var DOM_target; + // trial start callback method + var on_trial_start; + // trial finish callback method + var on_trial_finish; // // public methods // core.init = function($this, options){ + var defaults = { + 'on_trial_start': function(){ return undefined; } + 'on_trial_finish': function() { return undefined; } + } // import options - opts = $.extend({}, jsPsych.defaults, options); + opts = $.extend({}, defaults, options); // set target DOM_target = $this; @@ -147,7 +155,14 @@ 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); + + // call on_trial_finish() + on_trial_finish(); } return core;