forked from cagdasbozman/ocp-jslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.ml
26 lines (22 loc) · 769 Bytes
/
button.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
open Utils
let registered_buttons = ref []
let button_type = _s "button"
let create txt action =
let b = Dom_html.createButton ~_type:button_type doc in
let id = "button" ^ txt in
b##innerHTML <- _s txt;
b##id <- _s id;
registered_buttons := (id, txt) :: !registered_buttons;
b##className <- _s "btn";
b##onclick <- Dom_html.handler (fun _ -> action (); Js._true);
b
let create_with_image src width txt action =
let b = Dom_html.createButton ~_type:button_type doc in
let id = "button" ^ txt in
b##innerHTML <-
Js.string (Printf.sprintf
"<img src=\"%s\" width=\"%d\" text=\"%s\"/>" src width txt);
b##id <- Js.string id;
b##className <- _s "btn";
b##onclick <- Dom_html.handler (fun _ -> action (); Js._true);
b