mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
breaking change
changes to the core jspsych.js file will break some backwards compatibility. script files are no longer loaded dynamically, due to issues with using $.getScript on local installations. this revision makes defining a list of plugins unnecessary; they are automatically recognized based on the experiment structure. changes to similarity plugin: display is now sequential. adding storybook plugin: this is an ipad plugin, which displays a single image and records the location of touch events.
This commit is contained in:
parent
de1087dc26
commit
338a21d199
@ -21,17 +21,25 @@
|
|||||||
{
|
{
|
||||||
switch(part){
|
switch(part){
|
||||||
case 1:
|
case 1:
|
||||||
images = [trial.a_path, trial.b_path];
|
|
||||||
if(Math.floor(Math.random()*2)==0){
|
|
||||||
images = [trial.b_path, trial.a_path];
|
|
||||||
}
|
|
||||||
// show the images
|
// show the images
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": images[0],
|
"src": trial.a_path,
|
||||||
"class": 'sim'
|
"class": 'sim'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
setTimeout(function(){plugin.trial($this, block, trial, part + 1)}, trial.timing[0]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
|
||||||
|
$('.sim').remove();
|
||||||
|
|
||||||
|
setTimeout(function(){plugin.trial($this, block, trial, part + 1)}, trial.timing[0]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
|
||||||
$this.append($('<img>', {
|
$this.append($('<img>', {
|
||||||
"src": images[1],
|
"src": trial.b_path,
|
||||||
"class": 'sim'
|
"class": 'sim'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -44,6 +52,13 @@
|
|||||||
max:100,
|
max:100,
|
||||||
step:1,
|
step:1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// create labels for slider
|
||||||
|
$this.append($('<div>', {"id": 'slider_labels', "class": 'sim'}));
|
||||||
|
|
||||||
|
$('#slider_labels').append($('<p class="slider_left sim">Not at all similar</p>'));
|
||||||
|
$('#slider_labels').append($('<p class="slider_right sim">Highly similar</p>'));
|
||||||
|
|
||||||
// create button
|
// create button
|
||||||
$this.append($('<button>', {'id':'next','class':'sim'}));
|
$this.append($('<button>', {'id':'next','class':'sim'}));
|
||||||
@ -52,7 +67,7 @@
|
|||||||
plugin.trial($this,block,trial,part+1);
|
plugin.trial($this,block,trial,part+1);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 4:
|
||||||
// get data
|
// get data
|
||||||
var score = $("#slider").slider("value");
|
var score = $("#slider").slider("value");
|
||||||
block.data[block.trial_idx] = {"score": score, "a_path": trial.a_path, "b_path": trial.b_path}
|
block.data[block.trial_idx] = {"score": score, "a_path": trial.a_path, "b_path": trial.b_path}
|
||||||
|
79
jspsych-storybook.js
Normal file
79
jspsych-storybook.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
(function( $ ) {
|
||||||
|
jsPsych.storybook = (function(){
|
||||||
|
|
||||||
|
var plugin = {};
|
||||||
|
|
||||||
|
plugin.create = function(params) {
|
||||||
|
stims = params["stimuli"];
|
||||||
|
trials = new Array(stims.length);
|
||||||
|
for(var i = 0; i < trials.length; i++)
|
||||||
|
{
|
||||||
|
trials[i] = {};
|
||||||
|
trials[i]["type"] = "storybook";
|
||||||
|
trials[i]["a_path"] = stims[i];
|
||||||
|
trials[i]["click_num"] = params["click_num"];
|
||||||
|
trials[i]["timing"] = params["timing"];
|
||||||
|
if(params["data"]!=undefined){
|
||||||
|
trials[i]["data"] = params["data"][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return trials;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.trial = function($this, block, trial, part)
|
||||||
|
{
|
||||||
|
switch(part){
|
||||||
|
case 1:
|
||||||
|
p1_time = (new Date()).getTime();
|
||||||
|
$this.append($('<img>', {
|
||||||
|
"src": trial.a_path,
|
||||||
|
"class": 'storybook'
|
||||||
|
}));
|
||||||
|
|
||||||
|
var click_count = 0;
|
||||||
|
var click_locations = [];
|
||||||
|
var click_times = [];
|
||||||
|
|
||||||
|
var touchfunction = function(e) {
|
||||||
|
|
||||||
|
var rt = (new Date()).getTime() - p1_time;
|
||||||
|
var x = e.originalEvent.touches[0].pageX;
|
||||||
|
var y = e.originalEvent.touches[0].pageY;
|
||||||
|
|
||||||
|
click_count = click_count + 1;
|
||||||
|
|
||||||
|
console.log("click event "+x+" "+y+". click count "+click_count+". click num "+trial.click_num);
|
||||||
|
|
||||||
|
//save location
|
||||||
|
click_locations.push([x,y]);
|
||||||
|
click_times.push(rt);
|
||||||
|
|
||||||
|
//save response time
|
||||||
|
if(click_count == trial.click_num)
|
||||||
|
{
|
||||||
|
var click_loc_data = {"click_locations": click_locations};
|
||||||
|
var click_time_data = {"click_times": click_times};
|
||||||
|
// save data
|
||||||
|
block.data[block.trial_idx] = $.extend({}, click_loc_data, click_time_data);
|
||||||
|
|
||||||
|
plugin.trial($this, block, trial, part + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$('.storybook').click(function(){ void(0); })
|
||||||
|
|
||||||
|
//$('.storybook').mousedown(function(e){ touchfunction(e);});
|
||||||
|
$('.storybook').bind("touchstart", function(e){touchfunction(e);});
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$('.storybook').remove();
|
||||||
|
|
||||||
|
setTimeout(function(){block.next();}, trial.timing[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
})();
|
||||||
|
})(jQuery);
|
285
jspsych.js
285
jspsych.js
@ -1,147 +1,138 @@
|
|||||||
// jspsych.js
|
// jspsych.js
|
||||||
//
|
//
|
||||||
// Josh de Leeuw and Drew Hendrickson
|
// Josh de Leeuw and Drew Hendrickson
|
||||||
// Percepts and Concepts Lab, Indiana University
|
// Percepts and Concepts Lab, Indiana University
|
||||||
//
|
//
|
||||||
(function( $ ) {
|
(function( $ ) {
|
||||||
jsPsych = (function() {
|
jsPsych = (function() {
|
||||||
|
|
||||||
//
|
//
|
||||||
// public object
|
// public object
|
||||||
//
|
//
|
||||||
var core = {};
|
var core = {};
|
||||||
|
|
||||||
//
|
//
|
||||||
// private class variables
|
// private class variables
|
||||||
//
|
//
|
||||||
|
|
||||||
// options
|
// options
|
||||||
var opts = {};
|
var opts = {};
|
||||||
// exp structure
|
// exp structure
|
||||||
var exp_blocks = [];
|
var exp_blocks = [];
|
||||||
// flow control
|
// flow control
|
||||||
var curr_block = 0;
|
var curr_block = 0;
|
||||||
// everything loaded?
|
// everything loaded?
|
||||||
var initialized = false;
|
var initialized = false;
|
||||||
// target DOM element
|
// target DOM element
|
||||||
var DOM_target;
|
var DOM_target;
|
||||||
|
|
||||||
//
|
//
|
||||||
// public methods
|
// public methods
|
||||||
//
|
//
|
||||||
|
|
||||||
core.init = function($this, options){
|
core.init = function($this, options){
|
||||||
// import options
|
// import options
|
||||||
opts = $.extend({}, jsPsych.defaults, options);
|
opts = $.extend({}, jsPsych.defaults, options);
|
||||||
// set target
|
// set target
|
||||||
DOM_target = $this;
|
DOM_target = $this;
|
||||||
|
|
||||||
// load plugin script files
|
run();
|
||||||
var scripts_loaded = 0;
|
/*
|
||||||
// load all of the plugins that are defined in the opts["plugins"]
|
* load scripts dynamically??
|
||||||
for(var j = 0; j < opts["plugins"].length; j++)
|
*
|
||||||
{
|
*
|
||||||
$.getScript(opts["plugins"][j]["src"], function(){
|
// load plugin script files
|
||||||
scripts_loaded++;
|
var scripts_loaded = 0;
|
||||||
if(scripts_loaded==opts["plugins"].length) {
|
// load all of the plugins that are defined in the opts["plugins"]
|
||||||
intialized = true;
|
for(var j = 0; j < opts["plugins"].length; j++)
|
||||||
run();
|
{
|
||||||
}
|
$.getScript(opts["plugins"][j]["src"], function(){
|
||||||
});
|
scripts_loaded++;
|
||||||
}
|
if(scripts_loaded==opts["plugins"].length) {
|
||||||
}
|
intialized = true;
|
||||||
|
run();
|
||||||
//
|
}
|
||||||
// private functions //
|
});
|
||||||
//
|
}*/
|
||||||
function run()
|
}
|
||||||
{
|
|
||||||
// take the experiment structure and dynamically create a set of blocks
|
//
|
||||||
exp_blocks = new Array(opts["experiment_structure"].length);
|
// private functions //
|
||||||
|
//
|
||||||
// iterate through block list to create trials
|
function run()
|
||||||
for(var i = exp_blocks.length-1; i>=0; i--)
|
{
|
||||||
{
|
// take the experiment structure and dynamically create a set of blocks
|
||||||
var trials = "undefined";
|
exp_blocks = new Array(opts["experiment_structure"].length);
|
||||||
|
|
||||||
for(var j = 0; j < opts["plugins"].length; j++)
|
// iterate through block list to create trials
|
||||||
{
|
for(var i = 0; i < exp_blocks.length; i++)
|
||||||
if(opts["experiment_structure"][i]["type"] == opts["plugins"][j]["type"])
|
{
|
||||||
{
|
var trials = jsPsych[opts["experiment_structure"][i]["type"]]["create"].call(null, opts["experiment_structure"][i]);
|
||||||
trials = jsPsych[opts["plugins"][j]["type"]]["create"].call(null, opts["experiment_structure"][i]);
|
|
||||||
}
|
exp_blocks[i] = createBlock(trials);
|
||||||
}
|
}
|
||||||
|
|
||||||
exp_blocks[i] = createBlock(trials);
|
// run the first block
|
||||||
}
|
exp_blocks[0].next();
|
||||||
|
}
|
||||||
// run the first block
|
|
||||||
exp_blocks[0].next();
|
function nextBlock()
|
||||||
}
|
{
|
||||||
|
curr_block += 1;
|
||||||
function nextBlock()
|
if(curr_block == exp_blocks.length)
|
||||||
{
|
{
|
||||||
curr_block += 1;
|
finishExperiment();
|
||||||
if(curr_block == exp_blocks.length)
|
} else {
|
||||||
{
|
exp_blocks[curr_block].next();
|
||||||
finishExperiment();
|
}
|
||||||
} else {
|
}
|
||||||
exp_blocks[curr_block].next();
|
|
||||||
}
|
function createBlock(trial_list)
|
||||||
}
|
{
|
||||||
|
var block = {
|
||||||
function createBlock(trial_list)
|
trial_idx: -1,
|
||||||
{
|
|
||||||
var block = {
|
trials: trial_list,
|
||||||
trial_idx: -1,
|
|
||||||
|
data: [],
|
||||||
trials: trial_list,
|
|
||||||
|
next: function() {
|
||||||
data: [],
|
this.trial_idx = this.trial_idx+1;
|
||||||
|
|
||||||
next: function() {
|
curr_trial = trial_list[this.trial_idx];
|
||||||
this.trial_idx = this.trial_idx+1;
|
|
||||||
|
if ( typeof curr_trial == "undefined"){
|
||||||
curr_trial = trial_list[this.trial_idx];
|
return this.done();
|
||||||
|
}
|
||||||
if ( typeof curr_trial == "undefined"){
|
|
||||||
return this.done();
|
do_trial(this, curr_trial);
|
||||||
}
|
},
|
||||||
|
|
||||||
do_trial(this, curr_trial);
|
done: nextBlock
|
||||||
},
|
}
|
||||||
|
|
||||||
done: nextBlock
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
return block;
|
function finishExperiment()
|
||||||
}
|
{
|
||||||
|
var all_data = [];
|
||||||
function finishExperiment()
|
for(var i=0;i<exp_blocks.length;i++)
|
||||||
{
|
{
|
||||||
var all_data = [];
|
all_data[i] = exp_blocks[i].data;
|
||||||
for(var i=0;i<exp_blocks.length;i++)
|
}
|
||||||
{
|
|
||||||
all_data[i] = exp_blocks[i].data;
|
opts["finish"].apply((new Object()), [all_data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
opts["finish"].apply((new Object()), [all_data]);
|
function do_trial(block, trial)
|
||||||
}
|
{
|
||||||
|
jsPsych[trial.type]["trial"].call(this, DOM_target, block, trial, 1);
|
||||||
function do_trial(block, trial)
|
}
|
||||||
{
|
|
||||||
for(var j = 0; j < opts["plugins"].length; j++)
|
return core;
|
||||||
{
|
})();
|
||||||
if(trial.type == opts["plugins"][j]["type"])
|
}) (jQuery);
|
||||||
{
|
|
||||||
jsPsych[opts["plugins"][j]["type"]]["trial"].call(this, DOM_target, block, trial, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return core;
|
|
||||||
})();
|
|
||||||
}) (jQuery);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user