blob: 7213dafcba4043ab8fde718044a5ae4e98658d80 (
plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
(* Element creation *)
type attribute =
| TextAttr of string * string
| EventAttr of string * (Dom.event -> unit)
let h tag attributes children =
let element =
if tag == "svg" || tag == "path" then
Document.create_element_ns "http://www.w3.org/2000/svg" tag
else Document.create_element tag
in
let () =
Js.Array.forEach
(fun attr ->
match attr with
| TextAttr (name, value) ->
Element.set_attribute element name value
| EventAttr (name, eventListener) ->
Element.add_event_listener element name eventListener)
attributes
in
let () =
Js.Array.forEach
(fun child -> Element.append_child element child)
children
in
element
(* Node creation *)
let text = Document.create_text_node
let div = h "div"
let span = h "span"
let header = h "header"
let button = h "button"
let section = h "section"
let svg = h "svg"
let path = h "path"
let form = h "form"
let label = h "label"
let input = h "input"
let textarea = h "textarea"
let i = h "i"
let a = h "a"
let h1 = h "h1"
let h2 = h "h2"
let h3 = h "h3"
|