mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00

variables (in the form of functions) can be passed in to the text plug in and their contents (return values) are substituted into the string when the text plugin is displayed. (also fixed bug in xab where correct/incorrect were backwards -- as of jul 17 commit)
51 lines
1.2 KiB
JavaScript
Executable File
51 lines
1.2 KiB
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;
|
|
if(params.variables != undefined)
|
|
{
|
|
trials[i]["variables"] = params.variables[i];
|
|
}
|
|
}
|
|
return trials;
|
|
}
|
|
|
|
plugin.trial = function($this, block, trial, part) {
|
|
var replaced_text = trial.text;
|
|
|
|
if(trial.variables != undefined)
|
|
{
|
|
for(var i = 0; i < trial.variables.length; i++)
|
|
{
|
|
var variable_text = trial.variables[i](); // variables are defined as functions
|
|
replaced_text = replaced_text.replace("%v", variable_text);
|
|
}
|
|
}
|
|
|
|
$this.html(replaced_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); |