forked from norm2782/uhc-jscript
/
HTML5.hs
211 lines (150 loc) · 5.06 KB
/
HTML5.hs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
module Language.UHC.JScript.W3C.HTML5
( Document
, documentAnchors
, documentForms
, documentImages
, documentLinks
, document
, documentWriteln, documentWrite
, documentGetElementById, documentGetElementsByName, documentGetElementsByTagName
, documentCreateElement
, Anchor
, anchorCharset
, anchorHref
, anchorHreflang
, anchorName
, anchorRel
, anchorRev
, anchorTarget
, anchorType
, Form
, Image
, Link
, Element
, elementInnerHTML
, elementTagName
, elementClientWidth
, elementClientHeight
, elementAttributes
, elementSetAttribute
, elementAppendChild
, Attr
, attrValue
, NamedNodeMap
, namedNodeMapLength
, namedNodeMapItem
, namedNodeMapNamedItem
, namedNodeMapRemoveNamedItem
, namedNodeMapSetNamedItem
, Node
, nodeName
, nodeType
, NodeList
, nodeListItem
, nodeListLength
)
where
import Language.UHC.JScript.Types
import Language.UHC.JScript.Primitives
import Language.UHC.JScript.ECMA.Array
import Language.UHC.JScript.ECMA.String
data DocumentPtr
type Document = JSPtr DocumentPtr
foreign import jscript "document"
document :: IO Document
foreign import jscript "%1.anchors"
documentAnchors :: Document -> JSArray Anchor
foreign import jscript "%1.forms"
documentForms :: Document -> JSArray Form
foreign import jscript "%1.images"
documentImages :: Document -> JSArray Image
foreign import jscript "%1.links"
documentLinks :: Document -> JSArray Link
foreign import jscript "%1.write(%*)"
documentWrite :: Document -> JSString -> IO ()
foreign import jscript "%1.writeln(%*)"
documentWriteln :: Document -> JSString -> IO ()
foreign import jscript "%1.getElementById(%*)"
documentGetElementById :: Document -> JSString -> IO Node
foreign import jscript "%1.getElementsByName(%*)"
documentGetElementsByName :: Document -> JSString -> IO (NodeList Node)
documentGetElementsByTagName :: Document -> String -> IO (NodeList Node)
documentGetElementsByTagName d = _documentGetElementsByTagName d . stringToJSString
foreign import jscript "%1.getElementsByTagName(%*)"
_documentGetElementsByTagName :: Document -> JSString -> IO (NodeList Node)
documentCreateElement :: String -> IO Node
documentCreateElement elem = _documentCreateElement (stringToJSString elem :: JSString)
foreign import jscript "document.createElement(%*)"
_documentCreateElement :: JSString -> IO Node
data AnchorPtr
type Anchor = JSPtr AnchorPtr
foreign import jscript "%1.charset"
anchorCharset :: Anchor -> JSString
foreign import jscript "%1.href"
anchorHref :: Anchor -> JSString
foreign import jscript "%1.hreflang"
anchorHreflang :: Anchor -> JSString
foreign import jscript "%1.name"
anchorName :: Anchor -> JSString
foreign import jscript "%1.rel"
anchorRel :: Anchor -> JSString
foreign import jscript "%1.rev"
anchorRev :: Anchor -> JSString
foreign import jscript "%1.target"
anchorTarget :: Anchor -> JSString
foreign import jscript "%1.type"
anchorType :: Anchor -> JSString
data FormPtr
type Form = JSPtr FormPtr
foreign import jscript "%1.elements"
formElements :: Form -> JSArray Element
data ImagePtr
type Image = JSPtr ImagePtr
data LinkPtr
type Link = JSPtr LinkPtr
data ElementPtr
type Element = JSPtr ElementPtr
foreign import jscript "%1.innerHTML"
elementInnerHTML :: Node -> JSString
foreign import jscript "%1.tagName"
elementTagName :: Node -> JSString
foreign import jscript "%1.clientWidth"
elementClientWidth :: Node -> Int
foreign import jscript "%1.clientHeight"
elementClientHeight :: Node -> Int
foreign import jscript "%1.attributes"
elementAttributes :: Node -> NamedNodeMap Node
elementSetAttribute :: Node -> String -> String -> IO ()
elementSetAttribute n k v = _elementSetAttribute n (stringToJSString k :: JSString) (stringToJSString v :: JSString)
foreign import jscript "%1.setAttribute(%*)"
_elementSetAttribute :: Node -> JSString -> JSString -> IO ()
foreign import jscript "%1.appendChild(%2)"
elementAppendChild :: Node -> Node -> IO ()
data NodePtr
type Node = JSPtr NodePtr
foreign import jscript "%1.nodeName"
nodeName :: Node -> JSString
foreign import jscript "%1.nodeType"
nodeType :: Node -> Int
data NodeListPtr x
type NodeList x = JSPtr (NodeListPtr x)
foreign import jscript "%1.length"
nodeListLength :: NodeList Node -> Int
foreign import jscript "%1[%2]"
nodeListItem :: NodeList Node -> Int -> IO Node
data NamedNodeMapPtr x
type NamedNodeMap x = JSPtr (NamedNodeMapPtr x)
foreign import jscript "%1.length"
namedNodeMapLength :: NamedNodeMap Node -> Int
foreign import jscript "%1[%2]"
namedNodeMapItem :: NamedNodeMap Node -> Int -> IO Node
foreign import jscript "%1.getNamedItem(%*)"
namedNodeMapNamedItem :: NamedNodeMap Node -> JSString -> IO Node
foreign import jscript "%1.removeNamedItem(%*)"
namedNodeMapRemoveNamedItem :: NamedNodeMap Node -> JSString -> IO Node
foreign import jscript "%1.setNamedItem(%*)"
namedNodeMapSetNamedItem :: NamedNodeMap Node -> Node -> IO Node
data AttrPtr
type Attr = JSPtr AttrPtr
foreign import jscript "%1.value"
attrValue :: Attr -> JSString