4 | import Rhone.JS.ElemRef
19 | rawInnerHtmlAt : ElemRef t -> String -> JSIO ()
20 | rawInnerHtmlAt ref str = do
21 | elem <- castElementByRef {t2 = Element} ref
22 | innerHTML elem .= str
27 | innerHtml : ElemRef t -> MSF JSIO String ()
28 | innerHtml = arrM . rawInnerHtmlAt
34 | text : ElemRef t -> MSF JSIO String ()
35 | text ref = escape ^>> innerHtml ref
44 | attribute : (name : String) -> MSF JSIO (HList [ElemRef t, Maybe String]) ()
46 | arrM $
\[ref,m] => do
47 | el <- castElementByRef {t2 = Element} ref
49 | Just s => setAttribute el name s
50 | Nothing => removeAttribute el name
54 | attributeAt : (name : String) -> ElemRef t -> MSF JSIO (Maybe String) ()
55 | attributeAt = firstArg . attribute
59 | attribute_ : (name : String) -> MSF JSIO (HList [ElemRef t, String]) ()
60 | attribute_ name = (\[a,b] => [a,Just b]) ^>> attribute name
64 | attributeAt_ : (name : String) -> ElemRef t -> MSF JSIO String ()
65 | attributeAt_ = firstArg . attribute_
70 | boolAttribute : (name : String) -> MSF JSIO (HList [ElemRef t, Bool]) ()
71 | boolAttribute name = (\[a,b] => [a,toMaybe b ""]) ^>> attribute name
75 | disabled : MSF JSIO (HList [ElemRef t, Bool]) ()
76 | disabled = boolAttribute "disabled"
80 | disabledAt : ElemRef t -> MSF JSIO Bool ()
81 | disabledAt = firstArg disabled
85 | hidden : MSF JSIO (HList [ElemRef t, Bool]) ()
86 | hidden = boolAttribute "hidden"
90 | hiddenAt : ElemRef t -> MSF JSIO Bool ()
91 | hiddenAt = firstArg hidden
95 | class : MSF JSIO (HList [ElemRef t, String]) ()
96 | class = attribute_ "class"
100 | classAt : ElemRef t -> MSF JSIO String ()
101 | classAt = firstArg class
110 | interface SafeCast t => SetValidity t where
111 | setValidityMessage : t -> String -> JSIO ()
114 | SetValidity HTMLButtonElement where
115 | setValidityMessage = setCustomValidity
118 | SetValidity HTMLFieldSetElement where
119 | setValidityMessage = setCustomValidity
122 | SetValidity HTMLInputElement where
123 | setValidityMessage = setCustomValidity
126 | SetValidity HTMLObjectElement where
127 | setValidityMessage = setCustomValidity
130 | SetValidity HTMLOutputElement where
131 | setValidityMessage = setCustomValidity
134 | SetValidity HTMLSelectElement where
135 | setValidityMessage = setCustomValidity
138 | SetValidity HTMLTextAreaElement where
139 | setValidityMessage = setCustomValidity
142 | setValidityMessageAt : SetValidity t => ElemRef t -> String -> JSIO ()
143 | setValidityMessageAt ref s =
144 | getElementByRef ref >>= (`setValidityMessage` s)
148 | validityMessageAt : SetValidity t => ElemRef t -> MSF JSIO String ()
149 | validityMessageAt = arrM . setValidityMessageAt
158 | -> MSF JSIO (Either String x) ()
159 | leftInvalid ref = either id (const "") ^>> validityMessageAt ref
166 | interface SafeCast t => SetValue t where
167 | setValue' : String -> t -> JSIO ()
170 | SetValue HTMLButtonElement where
171 | setValue' = (value =.)
174 | SetValue HTMLDataElement where
175 | setValue' = (value =.)
178 | SetValue HTMLInputElement where
179 | setValue' = (value =.)
182 | SetValue HTMLOptionElement where
183 | setValue' = (value =.)
186 | SetValue HTMLOutputElement where
187 | setValue' = (value =.)
190 | SetValue HTMLParamElement where
191 | setValue' = (value =.)
194 | SetValue HTMLSelectElement where
195 | setValue' = (value =.)
198 | SetValue HTMLTextAreaElement where
199 | setValue' = (value =.)
202 | SetValue RadioNodeList where
203 | setValue' = (value =.)
206 | setValue : SetValue t => ElemRef t -> String -> JSIO ()
207 | setValue r s = getElementByRef r >>= setValue' s
210 | value : SetValue t => MSF JSIO (HList [ElemRef t,String]) ()
211 | value = arrM $
\[r,s] => setValue r s
214 | valueOf : SetValue t => ElemRef t -> MSF JSIO String ()
215 | valueOf = firstArg value
218 | setChecked : Bool -> HTMLInputElement -> JSIO ()
219 | setChecked b el = set (checked el) b
222 | checked : MSF JSIO (HList [ElemRef HTMLInputElement,Bool]) ()
223 | checked = arrM $
\[r,b] => getElementByRef r >>= setChecked b
226 | isChecked : ElemRef HTMLInputElement -> MSF JSIO Bool ()
227 | isChecked = firstArg checked
229 | namespace LocalStorage
231 | setItem : MSF JSIO (HList [String,String]) ()
232 | setItem = arrM $
\[k,v] =>
233 | window >>= localStorage >>= (\s => setItem s k v)
236 | setItemAt : (key : String) -> MSF JSIO String ()
237 | setItemAt = firstArg setItem
245 | {auto 0 _ : JSType t}
246 | -> {auto 0 _ : Elem HTMLOrSVGElement (Types t)}
247 | -> {auto sc : SafeCast t}
250 | setFocus v = HTMLOrSVGElement.focus v
254 | {auto 0 _ : JSType t}
255 | -> {auto 0 _ : Elem HTMLOrSVGElement (Types t)}
256 | -> {auto sc : SafeCast t}
257 | -> MSF JSIO (ElemRef t) ()
258 | focus = arrM $
\r => getElementByRef r >>= setFocus
262 | {auto 0 _ : JSType t}
263 | -> {auto 0 _ : Elem HTMLOrSVGElement (Types t)}
264 | -> {auto sc : SafeCast t}
267 | focusAt r = const r >>> focus