jsPsych/jspsych-text.js
Josh de Leeuw 9c94b4d0b6 Reworking the plugin structure to use the Module javascript design pattern.
Plugins now have a consistent internal structure, with better variable scoping.

This version breaks backward compatibility due to a change in the syntax of how experiment objects are declared.
2012-05-15 16:03:26 -04:00

36 lines
847 B
JavaScript
Executable File

(function( $ ) {
$.fn.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);