// jspsych.js
//
// Josh de Leeuw
// Percepts and Concepts Lab, Indiana University
//
//
(function( $ ) {
jsPsych = (function() {
//
// public object
//
var core = {};
//
// private class variables
//
// options
var opts = {};
// exp structure
var exp_blocks = [];
// flow control
var curr_block = 0;
// everything loaded?
var initialized = false;
// target DOM element
var DOM_target;
// time that the experiment began
var exp_start_time;
//
// public methods
//
// core.init creates the experiment and starts running it
// $this is an HTML element (usually a
) that will display jsPsych content
// options is an object: {
// "experiment_structure": an array of blocks specifying the experiment
// "finish": function to execute when the experiment ends
// }
//
core.init = function($this, options){
// reset the key variables
// TODO: properly define this as a class with instance variables?
exp_blocks = [];
opts = {};
initialized = false;
curr_block = 0;
var defaults = {
'on_trial_start': function(){ return undefined; },
'on_trial_finish': function() { return undefined; }
}
// import options
opts = $.extend({}, defaults, options);
// set target
DOM_target = $this;
run();
}
// core.data returns all of the data objects for each block as an array
// where core.data[0] = data object from block 0, etc...
core.data = function(){
var all_data = [];
for(var i=0;i -1)) { opts.on_trial_finish() };
this.trial_idx = this.trial_idx+1;
var curr_trial = this.trials[this.trial_idx];
if ( typeof curr_trial == "undefined"){
return this.done();
}
// call on_trial_start()
opts.on_trial_start();
do_trial(this, curr_trial);
},
done: nextBlock,
num_trials: trial_list.length
}
return block;
}
function finishExperiment()
{
opts["finish"].apply((new Object()), [core.data()]);
}
function do_trial(block, trial)
{
// execute trial method
jsPsych[trial.type]["trial"].call(this, DOM_target, block, trial, 1);
}
return core;
})();
}) (jQuery);