@@ -3,7 +3,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
3
3
4
4
const info = {
5
5
name : "html-vas-response" ,
6
- version : "2.0 .0" ,
6
+ version : "2.1 .0" ,
7
7
parameters : {
8
8
/** The string to be displayed. */
9
9
stimulus : {
@@ -187,7 +187,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
187
187
trial ( display_element , trial ) {
188
188
// constrain hline_pct to < 100
189
189
if ( trial . hline_pct > 100 ) {
190
- console . log ( ' hline_pct is greater than 100! This makes no sense. Setting to 100.' ) ;
190
+ console . log ( " hline_pct is greater than 100! This makes no sense. Setting to 100." ) ;
191
191
trial . hline_pct = 100 ;
192
192
}
193
193
// half of the thumb width value from jspsych.css, used to adjust the label positions
@@ -213,17 +213,30 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
213
213
// Draw horizontal line in VAS container
214
214
html +=
215
215
'<div id="jspsych-html-vas-response-hline" style="position: relative; background: ' +
216
- trial . scale_colour + "; " +
217
- 'width: ' + trial . hline_pct + '%; ' +
218
- 'left: ' + ( 100 - trial . hline_pct ) / 2 + '%; ' + // Keep the horizontal line centred within clickable region
219
- 'height: 2px; ' +
220
- 'top: ' + ( trial . scale_height / 2 - 1 ) + 'px">' ;
216
+ trial . scale_colour +
217
+ "; " +
218
+ "width: " +
219
+ trial . hline_pct +
220
+ "%; " +
221
+ "left: " +
222
+ ( 100 - trial . hline_pct ) / 2 +
223
+ "%; " + // Keep the horizontal line centred within clickable region
224
+ "height: 2px; " +
225
+ "top: " +
226
+ ( trial . scale_height / 2 - 1 ) +
227
+ 'px">' ;
221
228
// Draw vertical line, but hide it at first
222
229
html +=
223
- '<div id="jspsych-html-vas-response-vline" style="visibility: hidden; position: absolute; left: 0px; ' +
224
- 'background-color: ' + trial . marker_colour + '; ' +
225
- 'height: ' + trial . scale_height + 'px; ' +
226
- 'top: ' + ( - trial . scale_height / 2 + 1 ) + 'px; ' +
230
+ '<div id="jspsych-html-vas-response-vline" style="visibility: hidden; position: absolute; left: 0px; ' +
231
+ "background-color: " +
232
+ trial . marker_colour +
233
+ "; " +
234
+ "height: " +
235
+ trial . scale_height +
236
+ "px; " +
237
+ "top: " +
238
+ ( - trial . scale_height / 2 + 1 ) +
239
+ "px; " +
227
240
'width: 2px"></div>' ;
228
241
229
242
html += "<div>" ; // special alignment div
@@ -234,7 +247,9 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
234
247
var offset = ( percent_dist_from_center * half_thumb_width ) / 100 ;
235
248
html +=
236
249
'<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
237
- 'top: ' + trial . scale_height / 2 + 'px; ' +
250
+ "top: " +
251
+ trial . scale_height / 2 +
252
+ "px; " +
238
253
"left:calc(" +
239
254
percent_of_range +
240
255
"% - (" +
@@ -304,8 +319,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
304
319
ppn_tick = Math . max ( Math . min ( ppn_tick , 1 ) , 0 ) ; // Constrain to 0 - 1
305
320
// Round to nearest increment, if needed
306
321
if ( trial . n_scale_points ) {
307
- ppn_tick =
308
- Math . round ( ppn_tick * ( trial . n_scale_points - 1 ) ) / ( trial . n_scale_points - 1 ) ;
322
+ ppn_tick = Math . round ( ppn_tick * ( trial . n_scale_points - 1 ) ) / ( trial . n_scale_points - 1 ) ;
309
323
}
310
324
var vline = document . getElementById ( "jspsych-html-vas-response-vline" ) ;
311
325
vline . style . left = ppn_tick * hline_rect . width - 1 + "px" ;
@@ -319,25 +333,33 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
319
333
if ( trial . resp_fcn ) {
320
334
trial . resp_fcn ( ppn_tick ) ;
321
335
}
322
- } ;
336
+ }
323
337
// Dragging makes an ugly "operation forbidden" cursor appear---easiest to just prevent any dragging
324
- document . addEventListener ( "dragstart" , function ( e ) { e . preventDefault ( ) } ) ;
338
+ document . addEventListener ( "dragstart" , function ( e ) {
339
+ e . preventDefault ( ) ;
340
+ } ) ;
325
341
// Make responsive to both clicks and touches
326
342
vas . onclick = update_vas ;
327
343
// Logic is more complex for dragging
328
344
if ( trial . marker_draggable ) {
329
345
// Track mouse state---whether to respond to mouse position depends on mouse position
330
346
var mouse_state = "up" ; // or "down"
331
- document . addEventListener ( "mousedown" , function ( ) { mouse_state = 'down' } ) ;
347
+ document . addEventListener ( "mousedown" , function ( ) {
348
+ mouse_state = "down" ;
349
+ } ) ;
332
350
// document.addEventListener("dblclick", function() {mouse_state = 'down'});
333
- document . addEventListener ( "mouseup" , function ( ) { mouse_state = 'up' } ) ;
334
- document . addEventListener ( "dragend" , function ( ) { mouse_state = 'up' } ) ;
351
+ document . addEventListener ( "mouseup" , function ( ) {
352
+ mouse_state = "up" ;
353
+ } ) ;
354
+ document . addEventListener ( "dragend" , function ( ) {
355
+ mouse_state = "up" ;
356
+ } ) ;
335
357
function drag_update ( e , test_mouse_state ) {
336
358
var do_update = true ;
337
359
test_mouse_state = test_mouse_state ?? true ; // test by default
338
360
if ( test_mouse_state ) {
339
- if ( mouse_state == 'up' ) {
340
- do_update = false
361
+ if ( mouse_state == "up" ) {
362
+ do_update = false ;
341
363
}
342
364
}
343
365
if ( do_update ) {
@@ -346,9 +368,9 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
346
368
}
347
369
vas . addEventListener ( "mousemove" , drag_update ) ;
348
370
vas . addEventListener ( "drag" , drag_update ) ;
349
- vas . addEventListener ( "touchmove" , function ( e ) {
371
+ vas . addEventListener ( "touchmove" , function ( e ) {
350
372
e . preventDefault ( ) ; // So that whole screen doesn't move in MS Edge
351
- drag_update ( e , false ) // Don't test whether mouse is down
373
+ drag_update ( e , false ) ; // Don't test whether mouse is down
352
374
} ) ;
353
375
}
354
376
0 commit comments