From d1135ff55db85ef81bbe2bd8f283cdbbd5464298 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 13 Jul 2020 21:30:32 +0200 Subject: Show map and add marks with right click --- src/Lib/Dom/Element.ml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Lib/Dom/Element.ml (limited to 'src/Lib/Dom/Element.ml') diff --git a/src/Lib/Dom/Element.ml b/src/Lib/Dom/Element.ml new file mode 100644 index 0000000..3e3b78a --- /dev/null +++ b/src/Lib/Dom/Element.ml @@ -0,0 +1,42 @@ +external setValue : Dom.element -> string -> unit = "value" [@@bs.set] + +external setTextContent : Dom.element -> string -> unit = "textContent" + [@@bs.set] + +external setStyle : Dom.element -> string -> unit = "style" [@@bs.set] + +external setClassName : Dom.element -> string -> unit = "className" [@@bs.set] + +external setAttribute : Dom.element -> string -> string -> unit = "setAttribute" + [@@bs.send] + +external setAttributeNS : Dom.element -> string -> string -> string -> unit + = "setAttributeNS" + [@@bs.send] + +external addEventListener : Dom.element -> string -> (Dom.event -> unit) -> unit + = "addEventListener" + [@@bs.send] + +external appendChild : Dom.element -> Dom.element -> unit = "appendChild" + [@@bs.send] + +external firstChild : Dom.element -> Dom.element Js.Nullable.t = "firstChild" + [@@bs.get] + +external removeChild : Dom.element -> Dom.element -> unit = "removeChild" + [@@bs.send] + +let removeFirstChild element = + match Js.toOption (firstChild element) with + | Some child -> + let () = removeChild element child in + true + | _ -> false + +let rec removeChildren element = + if removeFirstChild element then removeChildren element else () + +let mountOn base element = + let () = removeChildren base in + appendChild base element -- cgit v1.2.3