/** * jspsych-free-sort * plugin for drag-and-drop sorting of a collection of images * Josh de Leeuw * * documentation: docs.jspsych.org */ jsPsych.plugins['free-sort'] = (function() { var plugin = {}; jsPsych.pluginAPI.registerPreload('free-sort', 'stimuli', 'image'); plugin.info = { name: 'free-sort', description: '', parameters: { stimuli: { type: [jsPsych.plugins.parameterType.STRING], default: undefined, array: true, no_function: false, description: '' }, stim_height: { type: [jsPsych.plugins.parameterType.INT], default: 100, no_function: false, description: '' }, stim_width: { type: [jsPsych.plugins.parameterType.INT], default: 100, no_function: false, description: '' }, sort_area_height: { type: [jsPsych.plugins.parameterType.INT], default: 800, no_function: false, description: '' }, sort_area_width: { type: [jsPsych.plugins.parameterType.INT], default: 800, no_function: false, description: '' }, prompt: { type: [jsPsych.plugins.parameterType.STRING], default: '', no_function: false, description: '' }, prompt_location: { type: [jsPsych.plugins.parameterType.SELECT], options: ['above','below'], default: 'above', no_function: false, description: '' } } } plugin.trial = function(display_element, trial) { // default values trial.stim_height = trial.stim_height || 100; trial.stim_width = trial.stim_width || 100; trial.prompt = (typeof trial.prompt === 'undefined') ? '' : trial.prompt; trial.prompt_location = trial.prompt_location || "above"; trial.sort_area_width = trial.sort_area_width || 800; trial.sort_area_height = trial.sort_area_height || 800; // if any trial variables are functions // this evaluates the function and replaces // it with the output of the function trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial); var start_time = (new Date()).getTime(); // check if there is a prompt and if it is shown above if (trial.prompt && trial.prompt_location == "above") { display_element.innerHTML += trial.prompt; } display_element.innerHTML += '
'; // check if prompt exists and if it is shown below if (trial.prompt && trial.prompt_location == "below") { display_element.innerHTML += trial.prompt; } // store initial location data var init_locations = []; for (var i = 0; i < trial.stimuli.length; i++) { var coords = random_coordinate(trial.sort_area_width - trial.stim_width, trial.sort_area_height - trial.stim_height); display_element.querySelector("#jspsych-free-sort-arena").innerHTML += ''+ ''; init_locations.push({ "src": trial.stimuli[i], "x": coords.x, "y": coords.y }); } display_element.innerHTML += ''; var maxz = 1; var moves = []; var draggables = display_element.querySelectorAll('.jspsych-free-sort-draggable'); for(var i=0;i