Commit 2eba81a2 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Factorize common JS helpers

parent 95a0e178
......@@ -21,12 +21,7 @@
open Platform
open Serializable_j
let document = Dom_html.window##document
let alert s =
let open Js.Unsafe in
fun_call (variable "alert") [| s |> Js.string |> inject |]
open Tool_js_common
let install_handler (id, handler) =
let f _ =
......@@ -40,28 +35,6 @@ let install_handler (id, handler) =
(document##getElementById (Js.string id))
(fun e -> e##onclick <- Dom_html.handler f)
let get_textarea id =
let res = ref None in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
);
match !res with
| None -> raise Not_found
| Some x -> x
let set_textarea id z =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
)
module Tests = struct
let unit_tests () =
......
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2014 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program is distributed in the hope that it will be useful, but *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
let document = Dom_html.window##document
let alert s : unit =
let open Js.Unsafe in
fun_call (variable "alert") [| s |> Js.string |> inject |]
let get_textarea id =
let res = ref None in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
);
match !res with
| None -> raise Not_found
| Some x -> x
let set_textarea id z =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
)
......@@ -21,35 +21,7 @@
open Platform
open Serializable_j
let document = Dom_html.window##document
let alert s : unit =
let open Js.Unsafe in
fun_call (variable "alert") [| s |> Js.string |> inject |]
let get_textarea id =
let res = ref None in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
);
match !res with
| None -> raise Not_found
| Some x -> x
let set_textarea id z =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
)
open Tool_js_common
open Tool_credgen
let generate _ =
......
......@@ -21,35 +21,7 @@
open Platform
open Serializable_j
let document = Dom_html.window##document
let alert s : unit =
let open Js.Unsafe in
fun_call (variable "alert") [| s |> Js.string |> inject |]
let get_textarea id =
let res = ref None in
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> res := Some (Js.to_string (x##value)))
);
match !res with
| None -> raise Not_found
| Some x -> x
let set_textarea id z =
Js.Opt.iter
(document##getElementById (Js.string id))
(fun e ->
Js.Opt.iter
(Dom_html.CoerceTo.textarea e)
(fun x -> x##value <- Js.string z)
)
open Tool_js_common
open Tool_tkeygen
let tkeygen _ =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment