mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
updating plugins to match new format
This commit is contained in:
parent
0742ebc246
commit
dadede318d
@ -5,30 +5,19 @@
|
||||
* documentation: docs.jspsych.org
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
jsPsych.animation = (function() {
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
|
||||
params = jsPsych.pluginAPI.enforceArray(params, ['choices']);
|
||||
|
||||
var trials = new Array(params.stimuli.length);
|
||||
for (var i = 0; i < trials.length; i++) {
|
||||
trials[i] = {};
|
||||
trials[i].stims = params.stimuli[i];
|
||||
trials[i].frame_time = params.frame_time || 250;
|
||||
trials[i].frame_isi = params.frame_isi || 0;
|
||||
trials[i].sequence_reps = params.sequence_reps || 1;
|
||||
trials[i].choices = params.choices || [];
|
||||
trials[i].prompt = (typeof params.prompt === 'undefined') ? "" : params.prompt;
|
||||
}
|
||||
return trials;
|
||||
};
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
trials.frame_time = trial.frame_time || 250;
|
||||
trials.frame_isi = trial.frame_isi || 0;
|
||||
trials.sequence_reps = trial.sequence_reps || 1;
|
||||
trials.choices = trial.choices || [];
|
||||
trials.prompt = (typeof trial.prompt === 'undefined') ? "" : trial.prompt;
|
||||
|
||||
// if any trial variables are functions
|
||||
// this evaluates the function and replaces
|
||||
// it with the output of the function
|
||||
@ -46,7 +35,7 @@
|
||||
var showImage = true;
|
||||
display_element.html(""); // clear everything
|
||||
animate_frame++;
|
||||
if (animate_frame == trial.stims.length) {
|
||||
if (animate_frame == trial.stimuli.length) {
|
||||
animate_frame = 0;
|
||||
reps++;
|
||||
if (reps >= trial.sequence_reps) {
|
||||
@ -63,11 +52,11 @@
|
||||
function show_next_frame() {
|
||||
// show image
|
||||
display_element.append($('<img>', {
|
||||
"src": trial.stims[animate_frame],
|
||||
"src": trial.stimuli[animate_frame],
|
||||
"id": 'jspsych-animation-image'
|
||||
}));
|
||||
|
||||
current_stim = trial.stims[animate_frame];
|
||||
current_stim = trial.stimuli[animate_frame];
|
||||
|
||||
// record when image was shown
|
||||
animation_sequence.push({
|
||||
@ -120,15 +109,14 @@
|
||||
|
||||
jsPsych.pluginAPI.cancelKeyboardResponse(response_listener);
|
||||
|
||||
jsPsych.data.write({
|
||||
var trial_data = {
|
||||
"animation_sequence": JSON.stringify(animation_sequence),
|
||||
"responses": JSON.stringify(responses)
|
||||
});
|
||||
};
|
||||
|
||||
jsPsych.finishTrial();
|
||||
jsPsych.finishTrial(trial_data);
|
||||
}
|
||||
};
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -9,30 +9,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
jsPsych.instructions = (function() {
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
|
||||
params = jsPsych.pluginAPI.enforceArray(params, ['pages']);
|
||||
|
||||
var trials = new Array(1);
|
||||
|
||||
trials[0] = {};
|
||||
trials[0].pages = params.pages;
|
||||
trials[0].key_forward = params.key_forward || 'rightarrow';
|
||||
trials[0].key_backward = params.key_backward || 'leftarrow';
|
||||
trials[0].allow_backward = (typeof params.allow_backward === 'undefined') ? true : params.allow_backward;
|
||||
trials[0].allow_keys = (typeof params.allow_keys === 'undefined') ? true : params.allow_keys;
|
||||
trials[0].show_clickable_nav = (typeof params.show_clickable_nav === 'undefined') ? false : params.show_clickable_nav;
|
||||
|
||||
return trials;
|
||||
};
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
trial.key_forward = trial.key_forward || 'rightarrow';
|
||||
trial.key_backward = trial.key_backward || 'leftarrow';
|
||||
trial.allow_backward = (typeof trial.allow_backward === 'undefined') ? true : trial.allow_backward;
|
||||
trial.allow_keys = (typeof trial.allow_keys === 'undefined') ? true : trial.allow_keys;
|
||||
trial.show_clickable_nav = (typeof trial.show_clickable_nav === 'undefined') ? false : trial.show_clickable_nav;
|
||||
|
||||
// if any trial variables are functions
|
||||
// this evaluates the function and replaces
|
||||
// it with the output of the function
|
||||
@ -125,12 +113,12 @@
|
||||
|
||||
display_element.html('');
|
||||
|
||||
jsPsych.data.write({
|
||||
var trial_data = {
|
||||
"view_history": JSON.stringify(view_history),
|
||||
"rt": (new Date()).getTime() - start_time
|
||||
});
|
||||
};
|
||||
|
||||
jsPsych.finishTrial();
|
||||
jsPsych.finishTrial(trial_data);
|
||||
}
|
||||
|
||||
var after_response = function(info) {
|
||||
@ -170,4 +158,3 @@
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -8,37 +8,27 @@
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
jsPsych['survey-text'] = (function() {
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
|
||||
//params = jsPsych.pluginAPI.enforceArray(params, ['data']);
|
||||
|
||||
var trials = [];
|
||||
for (var i = 0; i < params.questions.length; i++) {
|
||||
var rows = [], cols = [];
|
||||
if(typeof params.rows == 'undefined' || typeof params.columns == 'undefined'){
|
||||
for(var j = 0; j < params.questions[i].length; j++){
|
||||
cols.push(40);
|
||||
rows.push(1);
|
||||
}
|
||||
}
|
||||
|
||||
trials.push({
|
||||
preamble: typeof params.preamble == 'undefined' ? "" : params.preamble[i],
|
||||
questions: params.questions[i],
|
||||
rows: typeof params.rows == 'undefined' ? rows : params.rows[i],
|
||||
columns: typeof params.columns == 'undefined' ? cols : params.columns[i]
|
||||
});
|
||||
}
|
||||
return trials;
|
||||
};
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble;
|
||||
if (typeof trial.rows == 'undefined') {
|
||||
trial.rows = [];
|
||||
for (var i = 0; i < trial.questions.length; i++) {
|
||||
trial.rows.push(1);
|
||||
}
|
||||
}
|
||||
if (typeof trial.columns == 'undefined') {
|
||||
trial.columns = [];
|
||||
for (var i = 0; i < trial.questions.length; i++) {
|
||||
trial.columns.push(40);
|
||||
}
|
||||
}
|
||||
|
||||
// if any trial variables are functions
|
||||
// this evaluates the function and replaces
|
||||
// it with the output of the function
|
||||
@ -89,15 +79,15 @@
|
||||
});
|
||||
|
||||
// save data
|
||||
jsPsych.data.write({
|
||||
var trialdata = {
|
||||
"rt": response_time,
|
||||
"responses": JSON.stringify(question_data)
|
||||
});
|
||||
};
|
||||
|
||||
display_element.html('');
|
||||
|
||||
// next trial
|
||||
jsPsych.finishTrial();
|
||||
jsPsych.finishTrial(trialdata);
|
||||
});
|
||||
|
||||
var startTime = (new Date()).getTime();
|
||||
@ -105,4 +95,3 @@
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -9,26 +9,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
jsPsych.text = (function() {
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
|
||||
params = jsPsych.pluginAPI.enforceArray(params, ['text','cont_key']);
|
||||
|
||||
var trials = new Array(params.text.length);
|
||||
for (var i = 0; i < trials.length; i++) {
|
||||
trials[i] = {};
|
||||
trials[i].text = params.text[i]; // text of all trials
|
||||
trials[i].cont_key = params.cont_key || []; // keycode to press to advance screen, default is all keys.
|
||||
}
|
||||
return trials;
|
||||
};
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
trial.cont_key = trial.cont_key || [];
|
||||
|
||||
// if any trial variables are functions
|
||||
// this evaluates the function and replaces
|
||||
// it with the output of the function
|
||||
@ -41,9 +29,12 @@
|
||||
|
||||
display_element.html(''); // clear the display
|
||||
|
||||
save_data(info.key, info.rt);
|
||||
var trialdata = {
|
||||
"rt": info.rt,
|
||||
"key_press": info.key
|
||||
}
|
||||
|
||||
jsPsych.finishTrial();
|
||||
jsPsych.finishTrial(trialdata);
|
||||
|
||||
};
|
||||
|
||||
@ -53,7 +44,10 @@
|
||||
|
||||
display_element.unbind('click', mouse_listener);
|
||||
|
||||
after_response({key: 'mouse', rt: rt});
|
||||
after_response({
|
||||
key: 'mouse',
|
||||
rt: rt
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
@ -71,14 +65,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function save_data(key, rt) {
|
||||
jsPsych.data.write({
|
||||
"rt": rt,
|
||||
"key_press": key
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
})(jQuery);
|
||||
|
@ -1,38 +1,15 @@
|
||||
/**
|
||||
* Josh de Leeuw
|
||||
* November 2013
|
||||
*
|
||||
* This is a basic template for a jsPsych plugin. Use it to start creating your
|
||||
* own plugin. There is more information about how to create a plugin on the
|
||||
* jsPsych wiki (https://github.com/jodeleeuw/jsPsych/wiki/Create-a-Plugin).
|
||||
*
|
||||
*
|
||||
/*
|
||||
* Example plugin template
|
||||
*/
|
||||
|
||||
(function( $ ) {
|
||||
jsPsych["PLUGIN-NAME"] = (function(){
|
||||
|
||||
var plugin = {};
|
||||
|
||||
plugin.create = function(params) {
|
||||
var trials = new Array(NUMBER_OF_TRIALS);
|
||||
for(var i = 0; i < NUMBER_OF_TRIALS; i++)
|
||||
{
|
||||
trials[i] = {};
|
||||
trials[i].type = "PLUGIN-NAME";
|
||||
// other information needed for the trial method can be added here
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
// supporting the generic data object with the following line
|
||||
// is always a good idea. it allows people to pass in the data
|
||||
// parameter, but if they don't it gracefully adds an empty object
|
||||
// in it's place.
|
||||
trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i];
|
||||
}
|
||||
return trials;
|
||||
};
|
||||
|
||||
plugin.trial = function(display_element, block, trial, part) {
|
||||
// code for running the trial goes here
|
||||
// set default values for parameters
|
||||
trial.parameter = trial.parameter || 'default value';
|
||||
|
||||
// allow variables as functions
|
||||
// this allows any trial variable to be specified as a function
|
||||
@ -43,23 +20,13 @@
|
||||
trial = jsPsych.evaluateFunctionParameters(trial);
|
||||
|
||||
// data saving
|
||||
// this is technically optional, but virtually every plugin will
|
||||
// need to do it. it is good practice to include the type and
|
||||
// trial_index fields for all plugins.
|
||||
var trial_data = {
|
||||
type: trial.type,
|
||||
trial_index: block.trial_idx,
|
||||
// other values to save go here
|
||||
parameter_name: 'parameter value'
|
||||
};
|
||||
|
||||
// this line merges together the trial_data object and the generic
|
||||
// data object (trial.data), and then stores them.
|
||||
block.writeData($.extend({}, trial_data, trial.data));
|
||||
|
||||
// this method must be called at the end of the trial
|
||||
block.next();
|
||||
// end trial
|
||||
jsPsych.finishTrial(trial_data);
|
||||
};
|
||||
|
||||
return plugin;
|
||||
})();
|
||||
}) (jQuery);
|
Loading…
Reference in New Issue
Block a user