@@ -25,10 +25,9 @@ open%client Eliom_content.Html.F
2525let % client display
2626 ?(container_a = [ a_class [" ot-tip-container" ] ])
2727 ?(filter_a = [ a_class [" ot-tip-filter" ] ])
28- ?(side : [ `Center | `Left | `Right ] option )
2928 ~(origin : Dom_html.element Js.t )
30- ?(onopen = fun _ _ _ () -> () )
31- ?(onclose = fun _ _ _ () -> () )
29+ ?(onopen = fun _ _ -> () )
30+ ?(onclose = fun _ _ -> () )
3231 ~(content : (unit -> unit ) ->
3332 [< Html_types. div_content_fun > `Div ] Eliom_content.Html. elt list ) () =
3433 let close = ref @@ fun () -> () in
@@ -50,40 +49,47 @@ let%client display
5049 - int_of_float bb##.right in
5150 let print_px x = Js. string (Printf. sprintf " %gpx" x) in
5251 m##.style##.minWidth := print_px w ;
53- if top < bottom
54- then ( let top = print_px bb##.bottom in
55- m##.style##.top := top
56- ; m##.classList##add (Js. string " ot-tip-top" ) )
57- else (let bottom =
58- print_px
59- (float_of_int Dom_html. document##.documentElement##.clientHeight
60- -. bb##.top) in
61- m##.style##.bottom := bottom
62- ; m##.classList##add (Js. string " ot-tip-bottom" ) ) ;
63- let side =
64- if side = Some `Center || (side = None && right = left)
65- then (Lwt. async (fun () ->
66- let % lwt () = Ot_nodeready. nodeready m in
67- let _ = Dom_html. window##getComputedStyle m in (* Force layout *)
68- m##.style##.left :=
69- print_px (((bb##.right +. bb##.left) /. 2. )
70- -. (float_of_int m##.offsetWidth) /. 2. )
71- ; Lwt. return_unit)
72- ; m##.classList##add (Js. string " ot-tip-center" )
73- ; `Center )
74- else if side = Some `Left || (side = None && right < left)
75- then (let right =
76- print_px
77- (float_of_int Dom_html. document##.documentElement##.clientWidth
78- -. bb##.right) in
79- m##.style##.right := right
80- ; m##.classList##add (Js. string " ot-tip-left" )
81- ; `Left )
82- else (* if side = Some `Right || (side = None && right > left) *)
83- ( m##.style##.left := print_px bb##.left
84- ; m##.classList##add (Js. string " ot-tip-right" )
85- ; `Right )
86- in
52+ if top < bottom then begin
53+ let top = print_px bb##.bottom in
54+ m##.style##.top := top;
55+ m##.classList##add (Js. string " ot-tip-top" )
56+ end else begin
57+ let bottom =
58+ print_px
59+ (float_of_int Dom_html. document##.documentElement##.clientHeight
60+ -. bb##.top)
61+ in
62+ m##.style##.bottom := bottom;
63+ m##.classList##add (Js. string " ot-tip-bottom" )
64+ end ;
65+ if right < left then begin
66+ let right =
67+ float_of_int Dom_html. document##.documentElement##.clientWidth
68+ -. (bb##.right +. bb##.left) /. 2.
69+ in
70+ m##.style##.right := print_px right;
71+ Lwt. async @@ fun () ->
72+ let % lwt () = Ot_nodeready. nodeready m in
73+ let off = float (m##.offsetWidth / 2 ) in
74+ if off < = right -. 1. then begin
75+ m##.style##.right := print_px (right -. off);
76+ Manip.Class. add container " ot-tip-center"
77+ end else
78+ Manip.Class. add container " ot-tip-left" ;
79+ Lwt. return_unit
80+ end else begin
81+ let left = (bb##.right +. bb##.left) /. 2. in
82+ m##.style##.left := print_px left;
83+ Lwt. async @@ fun () ->
84+ let % lwt () = Ot_nodeready. nodeready m in
85+ let off = float (m##.offsetWidth / 2 ) in
86+ if off < = left -. 1. then begin
87+ m##.style##.left := print_px (left -. off);
88+ Manip.Class. add container " ot-tip-center"
89+ end else
90+ Manip.Class. add container " ot-tip-right" ;
91+ Lwt. return_unit
92+ end;
8793 let filter =
8894 D. div ~a: (a_onclick (fun _ -> ! close () ) :: filter_a) [ container ]
8995 in
@@ -96,8 +102,8 @@ let%client display
96102 close := (fun () ->
97103 Dom. removeEventListener scroll_handler;
98104 Manip. removeSelf filter;
99- onclose filter container side () ;
105+ onclose filter container
100106 );
101107 Manip. appendToBody filter ;
102- onopen filter container side () ;
108+ onopen filter container;
103109 (filter, ! close)
0 commit comments