/**
* 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.
*
* parameters:
* stimuli: array of arrays. inner arrays are two stimuli. stimuli can be image paths or html strings. each inner array is one trial.
* labels: array of strings to label the slider with. labels will be evenly spaced along the slider.
* intervals: how many different response options are on the slider
* show_ticks: if true, then the slider will have small tick marks displayed to show where the response options are.
* show_response: determines when to show the response options: "FIRST_STIMULUS","SECOND_STIMULUS",or "POST_STIMULUS"
* timing_first_stim: how long to show the first stimulus.
* timing_second_stim: how long to show the second stimulus. can be -1 to show until a response is given.
* timing_image_gap: how long to show a blank screen between the two stimuli.
* timing_post_trial: how long to show a blank screen after the trial is over.
* is_html: must set to true when using HTML strings as the stimuli.
* prompt: optional HTML string to display with the stimulus.
* data: the optional data object
*
*/
(function($) {
jsPsych.similarity = (function() {
var plugin = {};
plugin.create = function(params) {
var trials = new Array(params.stimuli.length);
for (var i = 0; i < trials.length; i++) {
trials[i] = {};
trials[i].type = "similarity";
trials[i].a_path = params.stimuli[i][0];
trials[i].b_path = params.stimuli[i][1];
// TODO make all changes related to following 4 parameters.
trials[i].labels = (typeof params.labels === 'undefined') ? ["Not at all similar", "Identical"] : params.labels;
trials[i].intervals = params.intervals || 100;
trials[i].show_ticks = (typeof params.show_ticks === 'undefined') ? false : params.show_ticks;
trials[i].show_response = params.show_response || "SECOND_STIMULUS";
trials[i].timing_first_stim = params.timing_first_stim || 1000; // default 1000ms
trials[i].timing_second_stim = params.timing_second_stim || -1; // -1 = inf time; positive numbers = msec to display second image.
trials[i].timing_image_gap = params.timing_image_gap || 1000; // default 1000ms
trials[i].timing_post_trial = (typeof params.timing_post_trial === 'undefined') ? 1000 : params.timing_post_trial; // default 1000ms
trials[i].is_html = (typeof params.is_html === 'undefined') ? false : params.is_html;
trials[i].prompt = (typeof params.prompt === 'undefined') ? '' : params.prompt;
trials[i].data = (typeof params.data === 'undefined') ? {} : params.data[i];
}
return trials;
};
var sim_trial_complete = false;
plugin.trial = function(display_element, block, trial, part) {
switch (part) {
case 1:
sim_trial_complete = false;
// show the images
if (!trial.is_html) {
display_element.append($('', {
"src": trial.a_path,
"id": 'jspsych_sim_stim'
}));
}
else {
display_element.append($('