mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
commit
d86c82f707
23
jspsych.js
23
jspsych.js
@ -227,6 +227,12 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// These are public functions, intended to be used for developing plugins.
|
||||||
|
// They aren't considered part of the normal API for the core library.
|
||||||
|
//
|
||||||
|
|
||||||
core.normalizeTrialVariables = function(trial, protect){
|
core.normalizeTrialVariables = function(trial, protect){
|
||||||
|
|
||||||
protect = (typeof protect === 'undefined') ? [] : protect;
|
protect = (typeof protect === 'undefined') ? [] : protect;
|
||||||
@ -256,6 +262,23 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if possible_array is not an array, then return a one-element array
|
||||||
|
// containing possible_array
|
||||||
|
core.enforceArray = function(params, possible_arrays) {
|
||||||
|
|
||||||
|
// function to check if something is an array, fallback
|
||||||
|
// to string method if browser doesn't support Array.isArray
|
||||||
|
var ckArray = Array.isArray || function(a) {
|
||||||
|
return toString.call(a) == '[object Array]';
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var i=0; i<possible_arrays.length; i++){
|
||||||
|
params[possible_arrays[i]] = ckArray(params[possible_arrays[i]]) ? params[possible_arrays[i]] : [params[possible_arrays[i]]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// private functions //
|
// private functions //
|
||||||
//
|
//
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
var plugin = {};
|
var plugin = {};
|
||||||
|
|
||||||
plugin.create = function(params) {
|
plugin.create = function(params) {
|
||||||
|
|
||||||
|
params = jsPsych.enforceArray(params, ['text','data']);
|
||||||
|
|
||||||
var trials = new Array(params.text.length);
|
var trials = new Array(params.text.length);
|
||||||
for (var i = 0; i < trials.length; i++) {
|
for (var i = 0; i < trials.length; i++) {
|
||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
|
Loading…
Reference in New Issue
Block a user