jsPsych/jspsych-text.js
Josh de Leeuw befdcfc1cd Rescoped everything so that jsPsych is not a jQuery plugin.
The top level object is jsPsych, and plugins are defined as jsPsych.PLUGIN.

The library also loads everything dynamically now, so the user only needs to load the main jsPsych script (and specify the src for any plugins).

This also changes how the library is loaded initially, since it is not based on the jQuery method anymore. See wiki.
2012-05-17 09:19:04 -04:00

36 lines
842 B
JavaScript
Executable File

(function( $ ) {
jsPsych.text = (function(){
var plugin = {};
plugin.create = function(params) {
var trials = new Array(params.text.length);
for(var i = 0; i < trials.length; i++)
{
trials[i] = {};
trials[i]["type"] = "text";
trials[i]["text"] = params.text[i];
trials[i]["cont_key"] = params.cont_key;
trials[i]["timing"] = params.timing;
}
return trials;
}
plugin.trial = function($this, block, trial, part) {
$this.html(trial.text);
var key_listener = function(e) {
if(e.which==trial.cont_key)
{
flag = true;
$(document).unbind('keyup',key_listener);
$this.html('');
setTimeout(function(){block.next();}, trial.timing[0]);
}
}
$(document).keyup(key_listener);
}
return plugin;
})();
}) (jQuery);