Permalink
Browse files

* Work on AJAX stuff

  • Loading branch information...
1 parent 47d8a16 commit 0f75be7a16cda1dfd858efb87375b8bd6f49ec34 @spockz spockz committed Dec 14, 2011
View
49 uhc-jscript/src/Language/UHC/JScript/JQuery/Ajax.hs
@@ -0,0 +1,49 @@
+module Language.UHC.JScript.JQuery.Ajax (AjaxOptions(..), JSAjaxOptions(..), ajax, toJSOptions) where
+
+import Language.UHC.JScript.Types
+
+import Language.UHC.JScript.Primitives
+
+data AjaxOptions a = AjaxOptions {
+ ao_url :: String,
+ ao_requestType :: String,
+ ao_contentType :: String,
+ ao_dataType :: String,
+ ao_success :: JSFunPtr (a -> IO()),
+ ao_failure :: JSFunPtr (a -> IO())
+
+}
+
+data JSAjaxOptions a = JSAjaxOptions {
+ jsao_url :: JSString,
+ jsao_requestType :: JSString,
+ jsao_contentType :: JSString,
+ jsao_dataType :: JSString,
+ jsao_success :: JSFunPtr (a -> IO()),
+ jsao_failure :: JSFunPtr (a -> IO())
+
+}
+
+toJSOptions :: AjaxOptions a -> JSAjaxOptions a
+toJSOptions options = let url' = toJS (ao_url options)
+ requestType' = toJS (ao_requestType options)
+ contentType' = toJS (ao_contentType options)
+ dataType' = toJS (ao_dataType options)
+ in JSAjaxOptions { jsao_url = url'
+ , jsao_requestType = requestType'
+ , jsao_contentType = contentType'
+ , jsao_dataType = dataType'
+ , jsao_success = ao_success options
+ , jsao_failure = ao_failure options}
+
+
+ajax :: AjaxOptions a -> IO ()
+ajax options = do o <- mkObj (toJSOptions options)
+ _ajax o
+
+
+
+
+
+foreign import jscript "$.ajax(%1)"
+ _ajax :: JSPtr a -> IO ()
View
14 uhc-jscript/src/Language/UHC/JScript/JQuery/AjaxQueue.hs
@@ -0,0 +1,14 @@
+module Language.UHC.JScript.JQuery.AjaxQueue (ajaxQ) where
+
+import Language.UHC.JScript.Primitives
+import Language.UHC.JScript.Types
+
+import Language.UHC.JScript.ECMA.String
+import Language.UHC.JScript.JQuery.Ajax
+
+ajaxQ :: String -> AjaxOptions a -> IO ()
+ajaxQ queuename options = do o <- mkObj (toJSOptions options)
+ _ajaxQ (toJS queuename) o
+
+foreign import jscript "$.ajaxq(%*)"
+ _ajaxQ :: JSString -> JSPtr a -> IO ()
View
23 uhc-jscript/src/Language/UHC/JScript/W3C/HTML5.hs
@@ -32,7 +32,8 @@ module Language.UHC.JScript.W3C.HTML5
, elementClientHeight
, elementAttributes
, elementSetAttribute
-
+ , elementAppendChild
+
, Attr
, attrValue
@@ -53,7 +54,7 @@ module Language.UHC.JScript.W3C.HTML5
)
where
-import Language.UHC.JScript.Types (toJS)
+import Language.UHC.JScript.Types
import Language.UHC.JScript.Primitives
import Language.UHC.JScript.ECMA.Array
@@ -89,14 +90,17 @@ foreign import jscript "%1.getElementById(%*)"
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)
+ _documentGetElementsByTagName :: Document -> JSString -> IO (NodeList Node)
-documentCreateElement :: Document -> String -> IO Node
-documentCreateElement d elem = _documentCreateElement d (toJS elem)
+documentCreateElement :: String -> IO Node
+documentCreateElement elem = _documentCreateElement (stringToJSString elem :: JSString)
-foreign import jscript "%1.createElement(%*)"
- _documentCreateElement :: Document -> JSString -> IO Node
+foreign import jscript "document.createElement(%*)"
+ _documentCreateElement :: JSString -> IO Node
data AnchorPtr
type Anchor = JSPtr AnchorPtr
@@ -156,10 +160,13 @@ foreign import jscript "%1.attributes"
elementAttributes :: Node -> NamedNodeMap Node
elementSetAttribute :: Node -> String -> String -> IO ()
-elementSetAttribute n k v = _elementSetAttribute n (toJS k) (toJS v)
+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

0 comments on commit 0f75be7

Please sign in to comment.