Skip to content

Commit 5127728

Browse files
authored
Merge pull request #235 from ocsigen/mouse-events
Adapt to Dom_html changes
2 parents 98976e4 + 159a704 commit 5127728

16 files changed

+193
-180
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Build
33
on:
44
pull_request:
55
push:
6+
branches:
7+
- master
68
schedule:
79
# Prime the caches every Monday
810
- cron: 0 1 * * MON
@@ -42,6 +44,8 @@ jobs:
4244
if: runner.os == 'macOS'
4345
run: brew update && brew reinstall openssl@3
4446

47+
- run: opam pin add -n eliom https://github.com/ocsigen/eliom.git
48+
4549
- run: opam install . --deps-only
4650

4751
- run: opam exec -- make

opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ install: [ make "install" ]
1414
available: arch != "x86_32" & arch != "arm32"
1515
depends: [
1616
"ocaml" {>= "4.08.0"}
17-
"js_of_ocaml" {>= "5.5.0"}
17+
"js_of_ocaml" {>= "6.0.0"}
1818
"eliom" {>= "11.0.0"}
1919
"calendar" {>= "2.0.0"}
2020
]

src/widgets/ot_carousel.eliom

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ let average_time = 0.1
7676

7777
type status =
7878
| Stopped
79-
| Start of (int * int * float) (* Just started, x, y positions, timestamp *)
80-
| Ongoing of (int * int * int * float * int * float)
79+
| Start of (float * float * float)
80+
(* Just started, x, y positions, timestamp *)
81+
| Ongoing of (float * float * int * float * float * float)
8182

8283
(* Ongoing swipe, (x start position,
8384
y start position,
@@ -189,7 +190,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
189190
let maxi () = ~%maxi - React.S.value ~%nb_visible_elements + 1 in
190191
let pos_signal = ~%pos_signal in
191192
let pos_set = ~%pos_set in
192-
let action = ref (`Move (0, 0)) in
193+
let action = ref (`Move (0., 0)) in
193194
let animation_frame_requested = ref false in
194195
(**********************
195196
setting class active on visible pages (only)
@@ -349,17 +350,21 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
349350
React.S.value ~%pos_signal * width_element
350351
in
351352
let m = (-width_element * maxi ()) + global_delta in
352-
min global_delta (max delta m)
353+
min (float global_delta) (max delta (float m))
353354
in
354355
let pos = Eliom_shared.React.S.value pos_signal in
355-
~%swipe_pos_set (-.float delta /. float width_element);
356-
let s = ~%make_transform ~vertical ~delta pos in
356+
~%swipe_pos_set (-.delta /. float width_element);
357+
let s =
358+
~%make_transform ~vertical
359+
~delta:(int_of_float (delta +. 0.5))
360+
pos
361+
in
357362
(Js.Unsafe.coerce d2'##.style)##.transform := s;
358363
(Js.Unsafe.coerce d2'##.style)##.webkitTransform := s
359364
| `Goback position | `Change position ->
360365
Manip.Class.add ~%d2 ot_swiping;
361366
set_top_margin ();
362-
action := `Move (0, 0);
367+
action := `Move (0., 0);
363368
set_position ~transitionend:unset_top_margin position);
364369
Lwt.return_unit)
365370
else Lwt.return_unit)
@@ -373,7 +378,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
373378
if delta_t = 0.
374379
then prev_speed
375380
else
376-
let cur_speed = (float delta -. float prev_delta) /. delta_t in
381+
let cur_speed = (delta -. prev_delta) /. delta_t in
377382
if delta_t >= average_time
378383
then cur_speed
379384
else
@@ -386,14 +391,17 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
386391
let onpan ev _ =
387392
(match !status with
388393
| Start (startx, starty, prev_timestamp) ->
389-
let move = if vertical then clY ev - starty else clX ev - startx in
394+
let move =
395+
if vertical then clY ev -. starty else clX ev -. startx
396+
in
390397
status :=
391-
if abs (if vertical then clX ev - startx else clY ev - starty)
392-
>= abs move
398+
if abs_float
399+
(if vertical then clX ev -. startx else clY ev -. starty)
400+
>= abs_float move
393401
then
394402
Stopped
395403
(* swiping in wrong direction (vertical/horizontal) *)
396-
else if abs move > Ot_swipe.threshold
404+
else if abs_float move > Ot_swipe.threshold
397405
then (
398406
(* We decide to take the event *)
399407
(* We send a touchcancel to the parent
@@ -404,9 +412,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
404412
remove_transition d2';
405413
let timestamp = now () in
406414
let delta_t = timestamp -. prev_timestamp in
407-
let speed =
408-
if delta_t = 0. then 0. else float move /. delta_t
409-
in
415+
let speed = if delta_t = 0. then 0. else move /. delta_t in
410416
Ongoing
411417
(startx, starty, width_element (), speed, move, timestamp))
412418
else !status
@@ -424,7 +430,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
424430
(* in case there is a carousel
425431
in a carousel, e.g. *)
426432
let delta =
427-
if vertical then clY ev - starty else clX ev - startx
433+
if vertical then clY ev -. starty else clX ev -. startx
428434
in
429435
let timestamp, speed =
430436
compute_speed prev_speed prev_delta prev_timestamp delta
@@ -445,16 +451,18 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
445451
status := Stopped;
446452
let width, delta =
447453
if vertical
448-
then d2'##.offsetHeight, clY ev - starty
449-
else d2'##.offsetWidth, clX ev - startx
454+
then d2'##.offsetHeight, clY ev -. starty
455+
else d2'##.offsetWidth, clX ev -. startx
450456
in
451457
let timestamp, speed =
452458
compute_speed prev_speed prev_delta prev_timestamp delta
453459
in
454460
let pos = Eliom_shared.React.S.value pos_signal in
455461
let delta =
456-
delta
457-
+ (int_of_float (speed *. ~%transition_duration *. ~%inertia) / 2)
462+
int_of_float
463+
(delta
464+
+. (speed *. ~%transition_duration *. ~%inertia /. 2.)
465+
+. 0.5)
458466
in
459467
let rem = delta mod width in
460468
let nbpages =
@@ -475,7 +483,7 @@ let%shared make ?(a = []) ?(vertical = false) ?(position = 0)
475483
let touchend ev _ =
476484
match !status with
477485
| Start (startx, starty, timestamp) ->
478-
do_end ev startx starty 0. 0 timestamp
486+
do_end ev startx starty 0. 0. timestamp
479487
| Ongoing (startx, starty, _width, speed, delta, timestamp) ->
480488
do_end ev startx starty speed delta timestamp
481489
| _ -> Lwt.return_unit
@@ -549,7 +557,7 @@ let%shared default_fail_fun e =
549557
let e = Printexc.to_string e in
550558
ignore
551559
[%client
552-
(Firebug.console##error
560+
(Console.console##error
553561
(Js.string ("Ot_carousel content failed with " ^ ~%e))
554562
: unit)];
555563
em ~a:[a_class ["ot-icon-error"]] []

src/widgets/ot_drawer.eliom

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ type%client status = Stopped | Start | Aborted | In_progress
3030
let%client clX ev =
3131
Js.Optdef.case
3232
ev ##. changedTouches ## (item 0)
33-
(fun () -> 0)
34-
(fun a -> a##.clientX)
33+
(fun () -> 0.)
34+
(fun a -> Js.to_float a##.clientX)
3535

3636
let%client clY ev =
3737
Js.Optdef.case
3838
ev ##. changedTouches ## (item 0)
39-
(fun () -> 0)
40-
(fun a -> a##.clientY)
39+
(fun () -> 0.)
40+
(fun a -> Js.to_float a##.clientY)
4141

4242
let%client bind_click_outside bckgrnd elt close =
4343
Lwt.async (fun () ->
@@ -79,7 +79,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
7979
?(onopen : (unit -> unit) Eliom_client_value.t option)
8080
?(wrap_close = fun f -> f) ?(wrap_open = fun f -> f) content
8181
=
82-
let scroll_pos = ref 0 in
82+
let scroll_pos = ref 0. in
8383
let a = (a :> Html_types.div_attrib attrib list) in
8484
let toggle_button =
8585
D.Form.button_no_value ~button_type:`Button
@@ -112,7 +112,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
112112
[%client
113113
(fun () ->
114114
Dom_html.document##.body##.style##.top := Js.string "";
115-
Dom_html.window##scroll 0 !(~%scroll_pos)
115+
Dom_html.window##scrollTo (Js.float 0.) (Js.float !(~%scroll_pos))
116116
: unit -> unit)]
117117
in
118118
let stop_open_event =
@@ -141,11 +141,11 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
141141
let open_ =
142142
[%client
143143
(fun () ->
144-
~%scroll_pos := (Js.Unsafe.coerce Dom_html.window)##.pageYOffset;
144+
~%scroll_pos := Js.to_float Dom_html.window##.scrollY;
145145
add_class ~%bckgrnd "open";
146146
Eliom_lib.Option.iter (fun f -> f ()) ~%onopen;
147147
Dom_html.document##.body##.style##.top
148-
:= Js.string (Printf.sprintf "%dpx" (- !(~%scroll_pos)));
148+
:= Js.string (Printf.sprintf "%.2fpx" (-. !(~%scroll_pos)));
149149
add_class ~%bckgrnd "opening";
150150
Lwt.cancel !(~%touch_thread);
151151
Lwt.async (fun () ->
@@ -195,7 +195,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
195195
let bckgrnd' = To_dom.of_element ~%bckgrnd in
196196
let cl = ~%close in
197197
let animation_frame_requested = ref false in
198-
let action = ref (`Move 0) in
198+
let action = ref (`Move 0.) in
199199
let perform_animation a =
200200
if !action = `Close && a = `Open
201201
then
@@ -216,7 +216,7 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
216216
| `Right -> "translateX(calc(-100% + "
217217
| `Bottom -> "translateY(calc(-100% + "
218218
| `Left -> "translateX(calc(100% + ")
219-
|> (fun t -> Printf.sprintf "%s%dpx" t delta)
219+
|> (fun t -> Printf.sprintf "%s%.2fdpx" t delta)
220220
|> Js.string
221221
in
222222
(Js.Unsafe.coerce dr##.style)##.transform := s;
@@ -247,24 +247,24 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
247247
else Lwt.return_unit)
248248
in
249249
(* let hammer = Hammer.make_hammer bckgrnd in *)
250-
let startx = ref 0 (* position when touch starts *) in
251-
let starty = ref 0 (* position when touch starts *) in
250+
let startx = ref 0. (* position when touch starts *) in
251+
let starty = ref 0. (* position when touch starts *) in
252252
let status = ref Stopped in
253253
let onpan ev _ =
254-
let left = clX ev - !startx in
255-
let top = clY ev - !starty in
254+
let left = clX ev -. !startx in
255+
let top = clY ev -. !starty in
256256
if !status = Start
257257
then
258258
status :=
259259
if (~%position = `Top || ~%position = `Bottom)
260-
&& abs left > abs top
260+
&& abs_float left > abs_float top
261261
|| (~%position = `Left || ~%position = `Right)
262-
&& abs top > abs left
262+
&& abs_float top > abs_float left
263263
then Aborted (* Orthogonal scrolling *)
264264
else if (~%position = `Top || ~%position = `Bottom)
265-
&& abs top <= Ot_swipe.threshold
265+
&& abs_float top <= Ot_swipe.threshold
266266
|| (~%position = `Left || ~%position = `Right)
267-
&& abs left <= Ot_swipe.threshold
267+
&& abs_float left <= Ot_swipe.threshold
268268
then !status
269269
else (
270270
(* We decide to take the event *)
@@ -276,20 +276,20 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
276276
then (
277277
Dom.preventDefault ev;
278278
Dom_html.stopPropagation ev;
279-
let move = ref 0 in
280-
if ~%position = `Top && top <= 0
279+
let move = ref 0. in
280+
if ~%position = `Top && top <= 0.
281281
&&
282282
(move := top;
283283
true)
284-
|| ~%position = `Right && left >= 0
284+
|| ~%position = `Right && left >= 0.
285285
&&
286286
(move := left;
287287
true)
288-
|| ~%position = `Bottom && top >= 0
288+
|| ~%position = `Bottom && top >= 0.
289289
&&
290290
(move := top;
291291
true)
292-
|| ~%position = `Left && left <= 0
292+
|| ~%position = `Left && left <= 0.
293293
&&
294294
(move := left;
295295
true)
@@ -304,8 +304,8 @@ let%shared drawer ?(a = []) ?(position = `Left) ?(opened = false)
304304
(Js.Unsafe.coerce dr##.style)##.transition
305305
:= Js.string "-webkit-transform .35s, transform .35s";
306306
let width = dr##.offsetWidth in
307-
let deltaX = float_of_int (clX ev - !startx) in
308-
let deltaY = float_of_int (clY ev - !starty) in
307+
let deltaX = clX ev -. !startx in
308+
let deltaY = clY ev -. !starty in
309309
if (~%position = `Top && deltaY < -0.3 *. float width)
310310
|| (~%position = `Right && deltaX > 0.3 *. float width)
311311
|| (~%position = `Bottom && deltaY > 0.3 *. float width)

src/widgets/ot_nodeready.eliom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let log ~n:node s =
4040
if not debug
4141
then ()
4242
else (
43-
(* Firebug.console##log(node); *)
43+
(* Console.console##log(node); *)
4444
ignore node;
4545
print_endline
4646
@@ Printf.sprintf "Ot_nodeready: %s; watching %n elements" s

src/widgets/ot_nodeready.eliomi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ val nodeready : #Dom.node Js.t -> unit Lwt.t
2727
2828
{3 Example}
2929
30-
[let _ = nodeready node in Firebug.console##debug node]
30+
[let _ = nodeready node in Console.console##debug node]
3131
3232
{3 Known issues}
3333

src/widgets/ot_noderesize.eliom

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ let%client detach {watched; sensor; shrink_listener_id; grow_listener_id; _} =
7070
match shrink_listener_id with Some x -> Dom.removeEventListener x | _ -> ()
7171

7272
let%client reset {grow; grow_child; shrink; _} =
73-
shrink##.scrollLeft := shrink##.scrollWidth;
74-
shrink##.scrollTop := shrink##.scrollHeight;
73+
shrink##.scrollLeft := Js.float (float shrink##.scrollWidth);
74+
shrink##.scrollTop := Js.float (float shrink##.scrollHeight);
7575
grow_child##.style##.width
7676
:= Js.string (string_of_int (grow##.offsetWidth + 1) ^ "px");
7777
grow_child##.style##.height
7878
:= Js.string (string_of_int (grow##.offsetHeight + 1) ^ "px");
79-
grow##.scrollLeft := grow##.scrollWidth;
80-
grow##.scrollTop := grow##.scrollHeight
79+
grow##.scrollLeft := Js.float (float grow##.scrollWidth);
80+
grow##.scrollTop := Js.float (float grow##.scrollHeight)
8181

8282
let%client reset_opt {grow; grow_child; shrink; _} =
83-
shrink##.scrollLeft := 9999;
84-
shrink##.scrollTop := 9999;
85-
grow##.scrollLeft := 9999;
86-
grow##.scrollTop := 9999
83+
shrink##.scrollLeft := Js.float 9999.;
84+
shrink##.scrollTop := Js.float 9999.;
85+
grow##.scrollLeft := Js.float 9999.;
86+
grow##.scrollTop := Js.float 9999.
8787

8888
let%client noderesize_aux reset sensor f =
8989
let bind element =
@@ -95,15 +95,16 @@ let%client noderesize_aux reset sensor f =
9595
if not !throttle
9696
then (
9797
throttle := true;
98-
Dom_html._requestAnimationFrame
99-
( Js.wrap_callback @@ fun _ ->
100-
let w' = element##.offsetWidth in
101-
let h' = element##.offsetHeight in
102-
if w' <> !w || h' <> !h then f ();
103-
w := w';
104-
h := h';
105-
reset sensor;
106-
throttle := false ));
98+
ignore
99+
(Dom_html.window##requestAnimationFrame
100+
( Js.wrap_callback @@ fun _ ->
101+
let w' = element##.offsetWidth in
102+
let h' = element##.offsetHeight in
103+
if w' <> !w || h' <> !h then f ();
104+
w := w';
105+
h := h';
106+
reset sensor;
107+
throttle := false )));
107108
Js.bool true))
108109
(Js.bool false)
109110
in

src/widgets/ot_noderesize.eliomi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ open Js_of_ocaml
4949
let div' = (To_dom.of_element div) in
5050
let%lwt () = Ot_nodeready.nodeready div' in
5151
Ot_noderesize.noderesize (ot_noderesize.attach div) (fun () ->
52-
Firebug.console##log (Js.string "Resized") ) )]} *)
52+
Console.console##log (Js.string "Resized") ) )]} *)
5353

5454
type resize_sensor
5555

0 commit comments

Comments
 (0)