Commit af6fcd98 authored by lucas.coatanlem's avatar lucas.coatanlem
Browse files

Register_event in progress (starting).

parent 47ccfcf6
......@@ -67,6 +67,7 @@ let replace_outer id str =
None -> Value.failwith' ("No element with id : " ^ id)
| Some elem -> elem ## outerHTML <- (Js.string str)
let test_register3 id str1 str2 =
(* replace id by str1@str2 *)
let elem = Dom_html.document ## getElementById (Js.string id) in
......@@ -75,7 +76,48 @@ let test_register3 id str1 str2 =
None -> Value.failwith' ("No element with id : " ^ id)
| Some elem -> elem ## innerHTML <- (Js.string str)
let simple_js_to_cduce v =
(* Pour la valeur v, si elle est changeable (string), on le fait, sinon on renvoie None *)
match Js.to_string (Js.typeof v) with
"string" -> Some (Value.ocaml2cduce_string (Js.to_string v))
| _ -> None
let js_to_cduce e =
let js_get_properties = Js.Unsafe.get Dom_html.window (Js.string "js_get_properties") in
let _content = Js.Unsafe.fun_call js_get_properties [| (Js.Unsafe.inject e) |] in
assert false
(* initialiser une ref à [],
pour chaque ligne dans content (name : n, value : v),
match simple_js_to_cduce v with
None -> ()
| Some vcduce -> res := (Label.mk_ascii (Js.to_string n), vcduce) :: !res
et enfin Value.vrecord !res
Commencer à réfléchir à js_to_cduce qui appelle la fonction, et qui, si c'est un string, fait ce qu'il faut, si c'est un number, fait ce qu'il faut, et si c'est un object, il faut que cela se rappelle récursivement pour créer un record cduce à l'intérieur du record cduce.
*)
let register_event id event handler =
(* add an event with handler to id *)
let mlid = Value.cduce2ocaml_string id in
let mlevent = Value.cduce2ocaml_string event in
let elem = Dom_html.document ## getElementById (Js.string mlid) in
let event = Js.string ("on" ^ mlevent) in
match Js.Opt.to_option elem with
None -> Value.failwith' ("No element with id : " ^ mlid)
| Some elem ->
Js.Unsafe.set
elem
event
(Js.wrap_callback
(fun e -> ignore (Value.apply (Value.apply handler id) (js_to_cduce e)))
)
let define_prims () =
(* define js primitives one at the moment *)
Js.Unsafe.eval_string "
window.js_get_properties = function (o){
var res = [];
......@@ -84,8 +126,7 @@ let define_prims () =
'value': (o[n] + '') });
};
return res;
};
console.log('ok');"
};"
let use () =
......
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