@@ -63,14 +63,15 @@ struct ContinuousSlider{T} <: Bonito.AbstractSlider{T}
63
63
track_style:: Styles
64
64
thumb_style:: Styles
65
65
track_active_style:: Styles
66
+ arrowkeys:: Bool
66
67
end
67
68
68
- function ContinuousSlider (range, value:: Observable{T} ) where {T}
69
+ function ContinuousSlider (range, value:: Observable{T} ; kwargs ... ) where {T}
69
70
value_l = Observable {T} (zero (T)/ zero (T))
70
- ContinuousSlider (range, value_l, value)
71
+ ContinuousSlider (range, value_l, value; kwargs ... )
71
72
end
72
73
73
- function ContinuousSlider (range, value_l:: Observable{T} , value_r:: Observable{T} ) where {T}
74
+ function ContinuousSlider (range, value_l:: Observable{T} , value_r:: Observable{T} ; arrowkeys = false ) where {T}
74
75
style, track_style, track_active_style, thumb_style = get_slider_style ()
75
76
76
77
#=
@@ -98,6 +99,7 @@ function ContinuousSlider(range, value_l::Observable{T}, value_r::Observable{T})
98
99
track_style,
99
100
thumb_style,
100
101
track_active_style,
102
+ arrowkeys
101
103
)
102
104
return slider
103
105
end
@@ -253,28 +255,35 @@ function Bonito.jsrender(session::Session, slider::ContinuousSlider)
253
255
}, { signal: controller .signal });
254
256
set_thumb_val ($ (slider .value_l ).value , ' l' );
255
257
set_thumb_val ($ (slider .value_r ).value , ' r' );
258
+
259
+ function move_thumb_incremental (direction , shiftPressed ) {
260
+ const startval = $ (slider .range ).value [0 ];
261
+ const endval = $ (slider .range ).value [1 ];
262
+ let step = (endval - startval) / 100 ;
263
+ if (shiftPressed) {step *= 10 ;}
264
+
265
+ let newval;
266
+ if (direction === ' right' ) {
267
+ newval = Math .min (thumbval_r + step, endval);
268
+ } else if (direction === ' left' ) {
269
+ newval = Math .max (thumbval_r - step, startval);
270
+ }
271
+ $ (slider .value_r ).notify (newval);
272
+ }
273
+
274
+ if ($ (slider .arrowkeys )) {
275
+ document .addEventListener (' keydown' , function (e ) {
276
+ if (e .key === ' ArrowRight' ) {
277
+ move_thumb_incremental (' right' , e .shiftKey );
278
+ e .preventDefault ();
279
+ } else if (e .key === ' ArrowLeft' ) {
280
+ move_thumb_incremental (' left' , e .shiftKey );
281
+ e .preventDefault ();
282
+ }
283
+ }, { signal: controller .signal });
284
+ }
256
285
}
257
286
"""
258
- # function move_thumb_incremental(direction, shiftPressed) {
259
- # const startval = $(slider.values[][begin]);
260
- # const endval = $(slider.values[][end]);
261
- # let step = (endval - startval) / 100;
262
- # if (shiftPressed) {step *= 10;}
263
- # if (direction === 'right') {
264
- # set_thumb_val(Math.min(thumbval + step, endval));
265
- # } else if (direction === 'left') {
266
- # set_thumb_val(Math.max(thumbval - step, startval));
267
- # }
268
- # }
269
- # document.addEventListener('keydown', function (e) {
270
- # if (e.key === 'ArrowRight') {
271
- # move_thumb_incremental('right', e.shiftKey);
272
- # e.preventDefault();
273
- # } else if (e.key === 'ArrowLeft') {
274
- # move_thumb_incremental('left', e.shiftKey);
275
- # e.preventDefault();
276
- # }
277
- # }, { signal: controller.signal });
278
287
onload (session, container, jscode)
279
288
280
289
return jsrender (session, container)
0 commit comments