(function( $ ) {
jsPsych.free_sort = (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] = {
"type": "free_sort",
"images": stims[i], // array of images to display
"stim_height": params.stim_height,
"stim_width": params.stim_width,
"timing": params.timing,
"prompt": params.prompt || undefined,
"prompt_location": params.prompt_location || "above",
"sort_area_width": params.sort_area_width || 800,
"sort_area_height": params.sort_area_height || 800
}
if(params.data) {
trials[i].data = params.data[i] || params.data;
}
}
return trials;
}
plugin.trial = function($this, block, trial, part)
{
switch(part){
case 1:
start_time = (new Date()).getTime();
// check if there is a prompt and if it is shown above
if(trial.prompt && trial.prompt_location == "above")
{
$this.append(trial.prompt);
}
$this.append($('
', {
"id": "sort_arena",
"class": "sort",
"css": {
"position": "relative",
"width": trial.sort_area_width,
"height": trial.sort_area_height
}
}));
// check if prompt exists and if it is shown below
if(trial.prompt && trial.prompt_location == "below")
{
$this.append(trial.prompt);
}
// store initial location data
var init_locations = [];
for(var i=0; i',
{
"src": trial.images[i],
"class": "draggable_stim sort",
"css": {
"position": "absolute",
"top": coords.y,
"left": coords.x
}
}));
init_locations.push({"src": trial.images[i], "x": coords.x, "y": coords.y});
}
var moves = [];
$('.draggable_stim').draggable({
containment: "#sort_arena",
scroll: false,
stack: ".draggable_stim",
stop: function(event, ui){
moves.push({"src": event.target.src.split("/").slice(-1)[0], "x":ui.position.left, "y": ui.position.top});
}
});
$this.append($('