Skip to content

Commit

Permalink
Scroll positions are now floats
Browse files Browse the repository at this point in the history
Adapt to Dom_html API change
(ocsigen/js_of_ocaml#1747).
  • Loading branch information
vouillon committed Nov 27, 2024
1 parent da2540f commit a181f88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions eliom.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ depends: [
"ocamlfind"
"ppx_deriving"
"ppxlib" {>= "0.15.0"}
"js_of_ocaml-compiler" {>= "5.5.0"}
"js_of_ocaml" {>= "5.5.0"}
"js_of_ocaml-lwt" {>= "5.5.0"}
"js_of_ocaml-compiler" {>= "6.0.0"}
"js_of_ocaml" {>= "6.0.0"}
"js_of_ocaml-lwt" {>= "6.0.0"}
"js_of_ocaml-ocamlbuild" {build}
"js_of_ocaml-ppx" {>= "5.5.0"}
"js_of_ocaml-ppx_deriving_json" {>= "5.5.0"}
"js_of_ocaml-tyxml" {>= "5.5.0"}
"js_of_ocaml-ppx" {>= "6.0.0"}
"js_of_ocaml-ppx_deriving_json" {>= "6.0.0"}
"js_of_ocaml-tyxml" {>= "6.0.0"}
"lwt_log"
"lwt_ppx" {>= "1.2.3"}
"tyxml" {>= "4.6.0" & < "4.7.0"}
Expand Down
20 changes: 10 additions & 10 deletions src/lib/client/eliommod_dom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,18 @@ let preload_css (doc : Dom_html.element Js.t) =
[@@@warning "-39"]

type position =
{html_top : int; html_left : int; body_top : int; body_left : int}
{html_top : float; html_left : float; body_top : float; body_left : float}
[@@deriving json]

[@@@warning "+39"]

let top_position = {html_top = 0; html_left = 0; body_top = 0; body_left = 0}
let top_position = {html_top = 0.; html_left = 0.; body_top = 0.; body_left = 0.}

let createDocumentScroll () =
{ html_top = Dom_html.document##.documentElement##.scrollTop
; html_left = Dom_html.document##.documentElement##.scrollLeft
; body_top = Dom_html.document##.body##.scrollTop
; body_left = Dom_html.document##.body##.scrollLeft }
{ html_top = Js.to_float Dom_html.document##.documentElement##.scrollTop
; html_left = Js.to_float Dom_html.document##.documentElement##.scrollLeft
; body_top = Js.to_float Dom_html.document##.body##.scrollTop
; body_left = Js.to_float Dom_html.document##.body##.scrollLeft }

(* With firefox, the scroll position is restored before to fire the
popstate event. We maintain our own position. *)
Expand All @@ -718,10 +718,10 @@ let _ =
let getDocumentScroll () = !current_position

let setDocumentScroll pos =
Dom_html.document##.documentElement##.scrollTop := pos.html_top;
Dom_html.document##.documentElement##.scrollLeft := pos.html_left;
Dom_html.document##.body##.scrollTop := pos.body_top;
Dom_html.document##.body##.scrollLeft := pos.body_left;
Dom_html.document##.documentElement##.scrollTop := Js.float pos.html_top;
Dom_html.document##.documentElement##.scrollLeft := Js.float pos.html_left;
Dom_html.document##.body##.scrollTop := Js.float pos.body_top;
Dom_html.document##.body##.scrollLeft := Js.float pos.body_left;
current_position := pos

(* UGLY HACK for Opera bug: Opera seem does not always take into
Expand Down
2 changes: 1 addition & 1 deletion src/lib/client/eliommod_dom.mli
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ val iter_attrList :
(** Window scrolling. *)

type position =
{html_top : int; html_left : int; body_top : int; body_left : int}
{html_top : float; html_left : float; body_top : float; body_left : float}
[@@deriving json]

val top_position : position
Expand Down

0 comments on commit a181f88

Please sign in to comment.