mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00

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.
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
(function( $ ) {
|
|
jsPsych.similarity = (function(){
|
|
|
|
var plugin = {};
|
|
|
|
plugin.create = function(params) {
|
|
sim_stims = params["stimuli"];
|
|
trials = new Array(sim_stims.length);
|
|
for(var i = 0; i < trials.length; i++)
|
|
{
|
|
trials[i] = {};
|
|
trials[i]["type"] = "similarity";
|
|
trials[i]["a_path"] = sim_stims[i][0];
|
|
trials[i]["b_path"] = sim_stims[i][1];
|
|
trials[i]["timing"] = params["timing"];
|
|
}
|
|
return trials;
|
|
}
|
|
|
|
plugin.trial = function($this, block, trial, part)
|
|
{
|
|
switch(part){
|
|
case 1:
|
|
// show the images
|
|
$this.append($('<img>', {
|
|
"src": trial.a_path,
|
|
"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>', {
|
|
"src": trial.b_path,
|
|
"class": 'sim'
|
|
}));
|
|
|
|
// create slider
|
|
$this.append($('<div>', { "id": 'slider', "class": 'sim' }));
|
|
$("#slider").slider(
|
|
{
|
|
value:50,
|
|
min:0,
|
|
max:100,
|
|
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
|
|
$this.append($('<button>', {'id':'next','class':'sim'}));
|
|
$("#next").html('Next');
|
|
$("#next").click(function(){
|
|
plugin.trial($this,block,trial,part+1);
|
|
});
|
|
break;
|
|
case 4:
|
|
// get data
|
|
var score = $("#slider").slider("value");
|
|
block.data[block.trial_idx] = {"score": score, "a_path": trial.a_path, "b_path": trial.b_path}
|
|
// goto next trial in block
|
|
$('.sim').remove();
|
|
setTimeout(function(){block.next();}, trial.timing[0]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return plugin;
|
|
})();
|
|
})(jQuery); |