From d24dd97a0335b2fbd28d1b9bfed9c8f5d0d1f7af Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 14:57:35 +0100 Subject: Update common library --- lib/elements/popup.ml | 11 ++++++++++- lib/elements/transfert.ml | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'lib/elements') diff --git a/lib/elements/popup.ml b/lib/elements/popup.ml index bf97559..28c414e 100755 --- a/lib/elements/popup.ml +++ b/lib/elements/popup.ml @@ -37,7 +37,6 @@ let create: submit_btn end; - let container = match form with | None -> El.div | Some _ -> El.form @@ -73,6 +72,16 @@ let create: let () = El.append_children (Document.body G.document) [ el ] in + (* Add the focus to the first input element inside the form *) + let () = match form with + | Some (_, el) when El.is_el el -> + begin match (El.find_by_tag_name ~root:el (Jstr.v "input")) with + | [] -> () + | hd::_ -> El.set_has_focus true hd + end + | _ -> () + in + (* Event handler *) let close_event = Evr.on_el Ev.click diff --git a/lib/elements/transfert.ml b/lib/elements/transfert.ml index f324509..3001e32 100755 --- a/lib/elements/transfert.ml +++ b/lib/elements/transfert.ml @@ -1,5 +1,15 @@ open Brr +let send_raw + : filename:Jstr.t -> Jstr.t -> unit + = fun ~filename data -> + (* Create the link to download the the element, and simulate a click on it *) + let a = El.a + ~at:At.[ href Jv.Id.(of_jv @@ to_jv data) + ; v (Jstr.v "download") filename ] + [] in + El.click a + (** Send a file to the user. *) let send : mime_type:Jstr.t -> filename:Jstr.t -> Jstr.t -> unit @@ -16,9 +26,6 @@ let send ; base64data |] in - (* Create the link to download the the element, and simulate a click on it *) - let a = El.a - ~at:At.[ href Jv.Id.(of_jv @@ to_jv data) - ; v (Jstr.v "download") filename ] - [] in - El.click a + send_raw + ~filename + data -- cgit v1.2.3