/*
* plugin for jsPsych based in Qisheng Li 11/2019. /// https://github.com/QishengLi/virtual_chinrest
Modified by Gustavo Juantorena 08/2020 // https://github.com/GEJ1
Contributions from Peter J. Kohler: https://github.com/pjkohler
*/
jsPsych.plugins['virtual-chinrest'] = (function() {
var plugin = {};
plugin.info = {
name: "virtual-chinrest",
parameters: {
resize_units: {
type: jsPsych.plugins.parameterType.STRING,
default: "none",
description: 'What units to resize to? ["none"/"cm"/"inch"/"deg"]. If "none", no resize will be done.'
},
pixels_per_unit: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Pixels per unit',
default: 100,
description: 'After the scaling factor is applied, this many pixels will equal one unit of measurement.'
},
blindspot_reps: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Blindspot measurement repetitions',
default: 5,
description: 'How many times to measure the blindspot location? If 0, blindspot will not detected and viewing distance not computed.'
},
prompt_card: {
type: jsPsych.plugins.parameterType.STRING,
default: ' Let’s find out how big your monitor is! '+
'
Please use any credit card that you have available. ' +
'It can also be a grocery store membership card, '+
'your drivers license or anything else of the same format. '+
'Place your card flat onto the screen, and adjust the slider below to match its size.
'+
'
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. '
},
prompt_blindspot: {
type: jsPsych.plugins.parameterType.STRING,
default: 'Now, let’s quickly test how far away you are sitting.'+
'
You might know that vision tests at a doctor’s practice often involve chinrests. '+
'The doctor basically asks you to sit away from a screen in a specific distance. '+
'We do this here with a “virtual chinrest”.
'+
'Instructions'+
'
'+
'
Put your finger on space bar on the keyboard.
'+
'
Close your right eye. (Tips: it might be easier to cover your right eye by hand!)
'+
'
Using your left eye, focus on the black square.
'+
'
Click the button below to start the animation of the red ball. The red ball '+
'will disappear as it moves from right to left. Press the “Space” key as soon as the ball disappears from your eye sight.
'+
'
'
},
card_path: {
type: jsPsych.plugins.parameterType.STRING,
default: "img/card.png"
}
}
}
// Get screen size
var w = window.innerWidth;
var h = window.innerHeight;
const screen_size_px = []
screen_size_px.push(w)
screen_size_px.push('x')
screen_size_px.push(h)
let trial_data = {
"card_width_mm": 85.60, //card dimension: 85.60 × 53.98 mm (3.370 × 2.125 in)
};
let config_data = {
"ball_pos": [],
"slider_clck": false
}
plugin.trial = function(display_element, trial) {
try {
if ( !( trial.blindspot_reps > 0 ) && ( (trial.resize_units == "deg" ) || (trial.resize_units == "degrees" ) ) ) {
throw Error("Blindspot repetitions set to 0, so resizing to degrees of visual angle is not possible!")
} else {
const start_time = performance.now();
if ( trial.blindspot_reps > 0 ) {
button_str = '