/** * 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, pretty_name: 'Stimuli', default: undefined, array: true, description: 'Images to be displayed.' }, stim_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus height', default: 100, description: 'Height of images in pixels.' }, stim_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Stimulus width', default: 100, description: 'Width of images in pixels' }, sort_area_height: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Sort area height', default: 800, description: 'The height of the container that subjects can move the stimuli in.' }, sort_area_width: { type: jsPsych.plugins.parameterType.INT, pretty_name: 'Sort area width', default: 800, description: 'The width of the container that subjects can move the stimuli in.' }, prompt: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Prompt', default: null, description: 'It can be used to provide a reminder about the action the subject is supposed to take.' }, prompt_location: { type: jsPsych.plugins.parameterType.SELECT, pretty_name: 'Prompt location', options: ['above','below'], default: 'above', description: 'Indicates whether to show prompt "above" or "below" the sorting area.' }, button_label: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button label', default: 'Continue', description: 'The text that appears on the button to continue to the next trial.' } } } plugin.trial = function(display_element, trial) { var start_time = (new Date()).getTime(); var html = ""; // check if there is a prompt and if it is shown above if (trial.prompt !== null && trial.prompt_location == "above") { html += trial.prompt; } html += '
'; // check if prompt exists and if it is shown below if (trial.prompt !== null && trial.prompt_location == "below") { html += trial.prompt; } display_element.innerHTML = html; // 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