var jsPsychVirtualChinrest = (function (jspsych) {
'use strict';
const info = {
name: "virtual-chinrest",
parameters: {
/** What units to resize to? ["none"/"cm"/"inch"/"deg"]. If "none", no resizing will be done to the jsPsych content after this trial. */
resize_units: {
type: jspsych.ParameterType.SELECT,
pretty_name: "Resize units",
options: ["none", "cm", "inch", "deg"],
default: "none",
},
/** After the scaling factor is applied, this many pixels will equal one unit of measurement. */
pixels_per_unit: {
type: jspsych.ParameterType.INT,
pretty_name: "Pixels per unit",
default: 100,
},
// mouse_adjustment: {
// type: ParameterType.BOOL,
// pretty_name: "Adjust Using Mouse?",
// default: true,
// },
/** Any content here will be displayed above the card stimulus. */
adjustment_prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Adjustment prompt",
default: `
Click and drag the lower right corner of the image until it is the same size as a credit card held up to the screen.
You can use any card that is the same size as a credit card, like a membership card or driver's license.
If you do not have access to a real card you can use a ruler to measure the image width to 3.37 inches or 85.6 mm.
`,
},
/** Content of the button displayed below the card stimulus. */
adjustment_button_prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Adjustment button prompt",
default: "Click here when the image is the correct size",
},
/** Path to an image to be shown in the resizable item div. */
item_path: {
type: jspsych.ParameterType.IMAGE,
pretty_name: "Item path",
default: null,
preload: false,
},
/** The height of the item to be measured, in mm. */
item_height_mm: {
type: jspsych.ParameterType.FLOAT,
pretty_name: "Item height (mm)",
default: 53.98,
},
/** The width of the item to be measured, in mm. */
item_width_mm: {
type: jspsych.ParameterType.FLOAT,
pretty_name: "Item width (mm)",
default: 85.6,
},
/** The initial size of the card, in pixels, along the largest dimension. */
item_init_size: {
type: jspsych.ParameterType.INT,
pretty_name: "Initial Size",
default: 250,
},
/** How many times to measure the blindspot location? If 0, blindspot will not be detected, and viewing distance and degree data not computed. */
blindspot_reps: {
type: jspsych.ParameterType.INT,
pretty_name: "Blindspot measurement repetitions",
default: 5,
},
/** HTML-formatted prompt to be shown on the screen during blindspot estimates. */
blindspot_prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Blindspot prompt",
default: `
Now we will quickly measure how far away you are sitting.
Put your left hand on the space bar.
Cover your right eye with your right hand.
Using your left eye, focus on the black square. Keep your focus on the black square.
The red ball will disappear as it moves from right to left. Press the space bar as soon as the ball disappears.
Press the space bar when you are ready to begin.
`,
},
/** Content of the start button for the blindspot tasks. */
// blindspot_start_prompt: {
// type: ParameterType.HTML_STRING,
// pretty_name: "Blindspot start prompt",
// default: "Start"
// },
/** Text accompanying the remaining measurements counter. */
blindspot_measurements_prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Blindspot measurements prompt",
default: "Remaining measurements: ",
},
/** HTML-formatted string for reporting the distance estimate. It can contain a span with ID 'distance-estimate', which will be replaced with the distance estimate. If "none" is given, viewing distance will not be reported to the participant. */
viewing_distance_report: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Viewing distance report",
default: "
Based on your responses, you are sitting about from the screen.
Does that seem about right?
",
},
/** Label for the button that can be clicked on the viewing distance report screen to re-do the blindspot estimate(s). */
redo_measurement_button_label: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Re-do measurement button label",
default: "No, that is not close. Try again.",
},
/** Label for the button that can be clicked on the viewing distance report screen to accept the viewing distance estimate. */
blindspot_done_prompt: {
type: jspsych.ParameterType.HTML_STRING,
pretty_name: "Blindspot done prompt",
default: "Yes",
},
},
};
/**
* **virtual-chinrest**
*
* jsPsych plugin for estimating physical distance from monitor and optionally resizing experiment content, based on Qisheng Li 11/2019. /// https://github.com/QishengLi/virtual_chinrest
*
* @author Gustavo Juantorena
* 08/2020 // https://github.com/GEJ1
* Contributions from Peter J. Kohler: https://github.com/pjkohler
* @see {@link https://www.jspsych.org/plugins/jspsych-virtual-chinrest/ virtual-chinrest plugin documentation on jspsych.org}
*/
class VirtualChinrestPlugin {
constructor(jsPsych) {
this.jsPsych = jsPsych;
this.ball_size = 30;
this.ball = null;
this.container = null;
this.reps_remaining = 0;
this.ball_animation_frame_id = null;
}
trial(display_element, trial) {
/** check parameter compatibility */
if (!(trial.blindspot_reps > 0) &&
(trial.resize_units == "deg" || trial.resize_units == "degrees")) {
console.error("Blindspot repetitions set to 0, so resizing to degrees of visual angle is not possible!");
return;
}
this.reps_remaining = trial.blindspot_reps;
/** some additional parameter configuration */
let trial_data = {
item_width_mm: trial.item_width_mm,
item_height_mm: trial.item_height_mm, //card dimension: 85.60 × 53.98 mm (3.370 × 2.125 in)
};
let blindspot_config_data = {
ball_pos: [],
slider_clck: false,
};
let aspect_ratio = trial.item_width_mm / trial.item_height_mm;
const start_div_height = aspect_ratio < 1 ? trial.item_init_size : Math.round(trial.item_init_size / aspect_ratio);
const start_div_width = aspect_ratio < 1 ? Math.round(trial.item_init_size * aspect_ratio) : trial.item_init_size;
const adjust_size = Math.round(start_div_width * 0.1);
/** create content for first screen, resizing card */
let pagesize_content = `
${trial.adjustment_prompt}
`;
/** create content for second screen, blind spot */
let blindspot_content = `