@@ -3,7 +3,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
33
44 const info = {
55 name : "html-vas-response" ,
6- version : "2.0 .0" ,
6+ version : "2.1 .0" ,
77 parameters : {
88 /** The string to be displayed. */
99 stimulus : {
@@ -187,7 +187,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
187187 trial ( display_element , trial ) {
188188 // constrain hline_pct to < 100
189189 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." ) ;
191191 trial . hline_pct = 100 ;
192192 }
193193 // half of the thumb width value from jspsych.css, used to adjust the label positions
@@ -213,17 +213,30 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
213213 // Draw horizontal line in VAS container
214214 html +=
215215 '<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">' ;
221228 // Draw vertical line, but hide it at first
222229 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; " +
227240 'width: 2px"></div>' ;
228241
229242 html += "<div>" ; // special alignment div
@@ -234,7 +247,9 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
234247 var offset = ( percent_dist_from_center * half_thumb_width ) / 100 ;
235248 html +=
236249 '<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; " +
238253 "left:calc(" +
239254 percent_of_range +
240255 "% - (" +
@@ -304,8 +319,7 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
304319 ppn_tick = Math . max ( Math . min ( ppn_tick , 1 ) , 0 ) ; // Constrain to 0 - 1
305320 // Round to nearest increment, if needed
306321 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 ) ;
309323 }
310324 var vline = document . getElementById ( "jspsych-html-vas-response-vline" ) ;
311325 vline . style . left = ppn_tick * hline_rect . width - 1 + "px" ;
@@ -319,25 +333,33 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
319333 if ( trial . resp_fcn ) {
320334 trial . resp_fcn ( ppn_tick ) ;
321335 }
322- } ;
336+ }
323337 // 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+ } ) ;
325341 // Make responsive to both clicks and touches
326342 vas . onclick = update_vas ;
327343 // Logic is more complex for dragging
328344 if ( trial . marker_draggable ) {
329345 // Track mouse state---whether to respond to mouse position depends on mouse position
330346 var mouse_state = "up" ; // or "down"
331- document . addEventListener ( "mousedown" , function ( ) { mouse_state = 'down' } ) ;
347+ document . addEventListener ( "mousedown" , function ( ) {
348+ mouse_state = "down" ;
349+ } ) ;
332350 // 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+ } ) ;
335357 function drag_update ( e , test_mouse_state ) {
336358 var do_update = true ;
337359 test_mouse_state = test_mouse_state ?? true ; // test by default
338360 if ( test_mouse_state ) {
339- if ( mouse_state == 'up' ) {
340- do_update = false
361+ if ( mouse_state == "up" ) {
362+ do_update = false ;
341363 }
342364 }
343365 if ( do_update ) {
@@ -346,9 +368,9 @@ var jsPsychHtmlVasResponse = (function (jspsych) {
346368 }
347369 vas . addEventListener ( "mousemove" , drag_update ) ;
348370 vas . addEventListener ( "drag" , drag_update ) ;
349- vas . addEventListener ( "touchmove" , function ( e ) {
371+ vas . addEventListener ( "touchmove" , function ( e ) {
350372 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
352374 } ) ;
353375 }
354376
0 commit comments