/**
* jspsych-similarity.js
* Josh de Leeuw
*
* This plugin create a trial where two images are shown sequentially, and the subject rates their similarity using a slider controlled with the mouse.
*
* documentation: docs.jspsych.org
*
*/
jsPsych.plugins.similarity = (function() {
var plugin = {};
jsPsych.pluginAPI.registerPreload('similarity', 'stimuli', 'image',function(t){ return !t.is_html || t.is_html == 'undefined'});
plugin.info = {
name: 'similarity',
description: '',
parameters: {
stimuli: {
type: [jsPsych.plugins.parameterType.STRING],
default: undefined,
array: true,
no_function: false,
description: ''
},
is_html: {
type: [jsPsych.plugins.parameterType.BOOL],
default: false,
no_function: false,
description: ''
},
labels: {
type: [jsPsych.plugins.parameterType.STRING],
array: true,
default: ['Not at all similar', 'Identical'],
no_function: false,
description: ''
},
intervals: {
type: [jsPsych.plugins.parameterType.INT],
default: 100,
no_function: false,
description: ''
},
show_ticks: {
type: [jsPsych.plugins.parameterType.BOOL],
default: false,
no_function: false,
description: ''
},
show_response: {
type: [jsPsych.plugins.parameterType.SELECT],
options: ['FIRST_STIMULUS', 'SECOND_STIMULUS','POST_STIMULUS'],
default: 'SECOND_STIMULUS',
no_function: false,
description: ''
},
timing_first_stim: {
type: [jsPsych.plugins.parameterType.INT],
default: 1000,
no_function: false,
description: ''
},
timing_image_gap: {
type: [jsPsych.plugins.parameterType.INT],
default: 1000,
no_function: false,
description: ''
},
timing_second_stim: {
type: [jsPsych.plugins.parameterType.INT],
default: -1,
no_function: false,
description: ''
},
prompt: {
type: [jsPsych.plugins.parameterType.STRING],
default: '',
no_function: false,
description: ''
}
}
}
plugin.trial = function(display_element, trial) {
// default parameters
trial.labels = (typeof trial.labels === 'undefined') ? ["Not at all similar", "Identical"] : trial.labels;
trial.intervals = trial.intervals || 100;
trial.show_ticks = (typeof trial.show_ticks === 'undefined') ? false : trial.show_ticks;
trial.show_response = trial.show_response || "SECOND_STIMULUS";
trial.timing_first_stim = trial.timing_first_stim || 1000; // default 1000ms
trial.timing_second_stim = trial.timing_second_stim || -1; // -1 = inf time; positive numbers = msec to display second image.
trial.timing_image_gap = trial.timing_image_gap || 1000; // default 1000ms
trial.is_html = (typeof trial.is_html === 'undefined') ? false : trial.is_html;
trial.prompt = (typeof trial.prompt === 'undefined') ? '' : trial.prompt;
// if any trial variables are functions
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
// show the images
if (!trial.is_html) {
display_element.innerHTML += '';
} else {
display_element.innerHTML += '