mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
added variables option to jspsych-text
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)
This commit is contained in:
parent
15cc690a9f
commit
4ea424b465
@ -1,36 +1,51 @@
|
||||
|
||||
(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;
|
||||
})();
|
||||
|
||||
(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);
|
@ -72,14 +72,14 @@
|
||||
var resp_func = function(e) {
|
||||
var flag = false;
|
||||
var correct = false;
|
||||
if(e.which== trial.left_key) // 'p' key
|
||||
if(e.which== trial.left_key) // 'q' key
|
||||
{
|
||||
flag = true;
|
||||
if(!target_left) { correct = true; }
|
||||
} else if(e.which== trial.right_key) // 'q' key
|
||||
if(target_left) { correct = true; }
|
||||
} else if(e.which== trial.right_key) // 'p' key
|
||||
{
|
||||
flag = true;
|
||||
if(target_left){ correct = true; }
|
||||
if(!target_left){ correct = true; }
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
@ -87,7 +87,7 @@
|
||||
rt = (endTime-startTime);
|
||||
stim1_time = (p2_time-p1_time);
|
||||
isi_time = (p3_time-p2_time);
|
||||
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time}
|
||||
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key_press": e.which, "stim1_time": stim1_time, "isi_time":isi_time}
|
||||
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
|
||||
$(document).unbind('keyup',resp_func);
|
||||
$this.html(''); // remove all
|
||||
|
Loading…
Reference in New Issue
Block a user